[lld] r282173 - Avoid duplicated code.
Rafael Espindola via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 22 09:47:21 PDT 2016
Author: rafael
Date: Thu Sep 22 11:47:21 2016
New Revision: 282173
URL: http://llvm.org/viewvc/llvm-project?rev=282173&view=rev
Log:
Avoid duplicated code.
This also fixes the linker script accounting for the ELF header in
some places but not in others.
Modified:
lld/trunk/ELF/LinkerScript.cpp
lld/trunk/ELF/OutputSections.h
lld/trunk/ELF/Writer.cpp
lld/trunk/test/ELF/oformat-binary.s
Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=282173&r1=282172&r2=282173&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Thu Sep 22 11:47:21 2016
@@ -587,8 +587,7 @@ template <class ELFT> void LinkerScript<
Sec->setVA(0);
}
- uintX_t HeaderSize =
- Out<ELFT>::ElfHeader->getSize() + Out<ELFT>::ProgramHeaders->getSize();
+ uintX_t HeaderSize = getHeaderSize();
if (HeaderSize > MinVA)
fatal("Not enough space for ELF and program headers");
@@ -723,7 +722,7 @@ uint64_t LinkerScript<ELFT>::getOutputSe
}
template <class ELFT> uint64_t LinkerScript<ELFT>::getHeaderSize() {
- return Out<ELFT>::ElfHeader->getSize() + Out<ELFT>::ProgramHeaders->getSize();
+ return elf::getHeaderSize<ELFT>();
}
template <class ELFT> uint64_t LinkerScript<ELFT>::getSymbolValue(StringRef S) {
Modified: lld/trunk/ELF/OutputSections.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.h?rev=282173&r1=282172&r2=282173&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.h (original)
+++ lld/trunk/ELF/OutputSections.h Thu Sep 22 11:47:21 2016
@@ -812,6 +812,12 @@ private:
llvm::SmallDenseMap<Key, OutputSectionBase<ELFT> *> Map;
};
+template <class ELFT> uint64_t getHeaderSize() {
+ if (Config->OFormatBinary)
+ return 0;
+ return Out<ELFT>::ElfHeader->getSize() + Out<ELFT>::ProgramHeaders->getSize();
+}
+
template <class ELFT> BuildIdSection<ELFT> *Out<ELFT>::BuildId;
template <class ELFT> DynamicSection<ELFT> *Out<ELFT>::Dynamic;
template <class ELFT> EhFrameHeader<ELFT> *Out<ELFT>::EhFrameHdr;
Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=282173&r1=282172&r2=282173&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Thu Sep 22 11:47:21 2016
@@ -1148,11 +1148,7 @@ template <class ELFT> void Writer<ELFT>:
// Assign VAs (addresses at run-time) to output sections.
template <class ELFT> void Writer<ELFT>::assignAddresses() {
- uintX_t VA = Config->ImageBase;
- if (!Config->OFormatBinary)
- VA +=
- Out<ELFT>::ElfHeader->getSize() + Out<ELFT>::ProgramHeaders->getSize();
-
+ uintX_t VA = Config->ImageBase + getHeaderSize<ELFT>();
uintX_t ThreadBssOffset = 0;
for (OutputSectionBase<ELFT> *Sec : OutputSections) {
uintX_t Alignment = Sec->getAlignment();
Modified: lld/trunk/test/ELF/oformat-binary.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/oformat-binary.s?rev=282173&r1=282172&r2=282173&view=diff
==============================================================================
--- lld/trunk/test/ELF/oformat-binary.s (original)
+++ lld/trunk/test/ELF/oformat-binary.s Thu Sep 22 11:47:21 2016
@@ -11,6 +11,10 @@
# RUN: ld.lld -o %t2.out --script %t.script %t --oformat binary
# RUN: od -t x1 -v %t2.out | FileCheck %s
+# RUN: echo "SECTIONS { }" > %t.script
+# RUN: ld.lld -o %t2.out --script %t.script %t --oformat binary
+# RUN: od -t x1 -v %t2.out | FileCheck %s
+
# RUN: not ld.lld -o %t3.out %t --oformat foo 2>&1 \
# RUN: | FileCheck %s --check-prefix ERR
# ERR: unknown --oformat value: foo
More information about the llvm-commits
mailing list