[PATCH] D17755: [ELF] - More direct implementation of edata/etext

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 1 00:15:25 PST 2016


grimar created this revision.
grimar added reviewers: ruiu, rafael.
grimar added subscribers: llvm-commits, grimar.

As was suggested in mails, this patch implements edata/etext
symbols in a more direct way.
It iterates through PT_LOADs.

Result seems to be the same and equal to gold output.

http://reviews.llvm.org/D17755

Files:
  ELF/Writer.cpp

Index: ELF/Writer.cpp
===================================================================
--- ELF/Writer.cpp
+++ ELF/Writer.cpp
@@ -1457,15 +1457,16 @@
   if (Config->EMachine == EM_MIPS)
     ElfSym<ELFT>::MipsGp.st_value = getMipsGpAddr<ELFT>();
 
-  // _etext points to location after the last read-only loadable segment.
-  // _edata points to the end of the last non SHT_NOBITS section.
-  for (OutputSectionBase<ELFT> *Sec : OutputSections) {
-    if (!(Sec->getFlags() & SHF_ALLOC))
+  // _etext is the first location after the last read-only loadable segment.
+  // _edata is the first location after the last read-write loadable segment.
+  for (Phdr &PHdr : Phdrs) {
+    if (PHdr.H.p_type != PT_LOAD)
       continue;
-    if (!(Sec->getFlags() & SHF_WRITE))
-      ElfSym<ELFT>::Etext.st_value = Sec->getVA() + Sec->getSize();
-    if (Sec->getType() != SHT_NOBITS)
-      ElfSym<ELFT>::Edata.st_value = Sec->getVA() + Sec->getSize();
+    uintX_t Val = PHdr.H.p_vaddr + PHdr.H.p_filesz;
+    if (PHdr.H.p_flags & PF_W)
+      ElfSym<ELFT>::Edata.st_value = Val;
+    else
+      ElfSym<ELFT>::Etext.st_value = Val;
   }
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D17755.49460.patch
Type: text/x-patch
Size: 1138 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160301/e8cdf5b7/attachment.bin>


More information about the llvm-commits mailing list