From 2abc587c1ef126850cd230e44deca6e93fab0b9b Mon Sep 17 00:00:00 2001 From: George Rimar Date: Tue, 1 Mar 2016 19:18:07 +0000 Subject: [PATCH] [ELF] - More direct implementation of edata/etext 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 --- lld/ELF/Writer.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index cfb4920..8b1486c 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -1467,15 +1467,16 @@ template void Writer::fixAbsoluteSymbols() { if (Config->EMachine == EM_MIPS) ElfSym::MipsGp.st_value = getMipsGpAddr(); - // _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 *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::Etext.st_value = Sec->getVA() + Sec->getSize(); - if (Sec->getType() != SHT_NOBITS) - ElfSym::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::Edata.st_value = Val; + else + ElfSym::Etext.st_value = Val; } } -- 2.7.4