Don't give an address to sections that are not allocated.

llvm-svn: 244900
This commit is contained in:
Rafael Espindola 2015-08-13 15:31:17 +00:00
parent 221104bec6
commit ef1ac01c2e
2 changed files with 6 additions and 2 deletions

View File

@ -174,9 +174,11 @@ template <class ELFT> void Writer<ELFT>::assignAddresses() {
std::stable_sort(OutputSections.begin(), OutputSections.end(), compSec<ELFT>);
for (OutputSection<ELFT> *Sec : OutputSections) {
Sec->setVA(VA);
if (Sec->getFlags() & SHF_ALLOC) {
Sec->setVA(VA);
VA += RoundUpToAlignment(Sec->getSize(), PageSize);
}
Sec->setFileOffset(FileOff);
VA += RoundUpToAlignment(Sec->getSize(), PageSize);
FileOff += RoundUpToAlignment(Sec->getSize(), 8);
StrTabBuilder.add(Sec->getName());
}

View File

@ -15,11 +15,13 @@ _start:
// CHECK-NEXT: Flags [
// CHECK-NEXT: SHF_ALLOC
// CHECK-NEXT: ]
// CHECK-NEXT: Address: 0x1000
// CHECK: Name: foobar
// CHECK-NEXT: Type: SHT_PROGBITS
// CHECK-NEXT: Flags [
// CHECK-NEXT: ]
// CHECK-NEXT: Address: 0x0
// Test that the sting "bar" is merged into "foobar"