Skip to content

Commit

Permalink
[ELF] - More direct implementation of edata/etext
Browse files Browse the repository at this point in the history
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.

Differential revision: http://reviews.llvm.org/D17755

llvm-svn: 262369
  • Loading branch information
George Rimar committed Mar 1, 2016
1 parent ebd9193 commit 2abc587
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions lld/ELF/Writer.cpp
Expand Up @@ -1467,15 +1467,16 @@ template <class ELFT> void Writer<ELFT>::fixAbsoluteSymbols() {
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;
}
}

Expand Down

0 comments on commit 2abc587

Please sign in to comment.