[ELF] - Implemented basic location counter support.
This patch implements location counter support.
It also separates assign addresses for sections to assignAddressesScript() if it scipt exists.
Main testcase is test/ELF/linkerscript-locationcounter.s, It contains some work with location counter. It is basic now.
Implemented location counter assignment and '+' operations.
Patch by myself with LOTS of comments and design suggestions from Rui Ueyama.
Differential revision: http://reviews.llvm.org/D18499
llvm-svn: 266457
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index ee1d32b..48eee43 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -220,8 +220,12 @@
} else {
createPhdrs();
fixHeaders();
- fixSectionAlignments();
- assignAddresses();
+ if (Script->Exists) {
+ Script->assignAddresses(OutputSections);
+ } else {
+ fixSectionAlignments();
+ assignAddresses();
+ }
assignFileOffsets();
setPhdrs();
fixAbsoluteSymbols();
@@ -1541,10 +1545,11 @@
// sections. These are special, we do not include them into output sections
// list, but have them to simplify the code.
template <class ELFT> void Writer<ELFT>::fixHeaders() {
- Out<ELFT>::ElfHeader->setVA(Target->getVAStart());
+ uintX_t BaseVA = Script->Exists ? 0 : Target->getVAStart();
+ Out<ELFT>::ElfHeader->setVA(BaseVA);
Out<ELFT>::ElfHeader->setFileOffset(0);
uintX_t Off = Out<ELFT>::ElfHeader->getSize();
- Out<ELFT>::ProgramHeaders->setVA(Off + Target->getVAStart());
+ Out<ELFT>::ProgramHeaders->setVA(Off + BaseVA);
Out<ELFT>::ProgramHeaders->setFileOffset(Off);
}