diff options
| author | Rafael Espindola <rafael.espindola@gmail.com> | 2017-06-13 20:57:43 +0000 |
|---|---|---|
| committer | Rafael Espindola <rafael.espindola@gmail.com> | 2017-06-13 20:57:43 +0000 |
| commit | dece28087ea83030c1bb3c2c7c2ec6c8bdd85624 (patch) | |
| tree | 176f1f7662e6e36b03ab96464703259e29344f09 | |
| parent | 1f76ca5a2d1ddebdd81690a2891c11359e805ea9 (diff) | |
| download | bcm5719-llvm-dece28087ea83030c1bb3c2c7c2ec6c8bdd85624.tar.gz bcm5719-llvm-dece28087ea83030c1bb3c2c7c2ec6c8bdd85624.zip | |
Set non alloc section address to 0 earlier.
Currently we do layout as if non alloc sections had an actual address
and then set it to zero. This produces a few odd results where a
symbol has an address that is inconsistent with the section address.
The simplest way to fix it is probably to just set the address earlier.
The behavior of bfd seems to be similar, but it only sets the non
alloc section address is missing from the linker script or if the
script has an explicit " : 0" setting the address of the output
section (which the default script does).
llvm-svn: 305323
| -rw-r--r-- | lld/ELF/LinkerScript.cpp | 11 | ||||
| -rw-r--r-- | lld/test/ELF/linkerscript/locationcountererr2.s | 2 | ||||
| -rw-r--r-- | lld/test/ELF/linkerscript/symbols-non-alloc.s | 2 |
3 files changed, 6 insertions, 9 deletions
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp index 235fa254bec..8624c5d3d56 100644 --- a/lld/ELF/LinkerScript.cpp +++ b/lld/ELF/LinkerScript.cpp @@ -142,10 +142,7 @@ void LinkerScript::assignSymbol(SymbolAssignment *Cmd, bool InSec) { Sym->Value = V.getValue(); } else { Sym->Section = V.Sec; - if (Sym->Section->Flags & SHF_ALLOC) - Sym->Value = alignTo(V.Val, V.Alignment); - else - Sym->Value = V.getValue(); + Sym->Value = alignTo(V.Val, V.Alignment); } } @@ -649,7 +646,9 @@ void LinkerScript::assignOffsets(OutputSectionCommand *Cmd) { if (!Sec) return; - if (Cmd->AddrExpr && (Sec->Flags & SHF_ALLOC)) + if (!(Sec->Flags & SHF_ALLOC)) + Dot = 0; + else if (Cmd->AddrExpr) setDot(Cmd->AddrExpr, Cmd->Location, false); if (Cmd->LMAExpr) { @@ -950,8 +949,6 @@ void LinkerScript::assignAddresses( OutputSection *Sec = Cmd->Sec; if (Sec->Flags & SHF_ALLOC) MinVA = std::min<uint64_t>(MinVA, Sec->Addr); - else - Sec->Addr = 0; } allocateHeaders(Phdrs, OutputSectionCommands, MinVA); diff --git a/lld/test/ELF/linkerscript/locationcountererr2.s b/lld/test/ELF/linkerscript/locationcountererr2.s index e711f77a3f7..54ee4a34da2 100644 --- a/lld/test/ELF/linkerscript/locationcountererr2.s +++ b/lld/test/ELF/linkerscript/locationcountererr2.s @@ -1,7 +1,7 @@ # REQUIRES: x86 # RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o # RUN: echo "SECTIONS {" > %t.script -# RUN: echo ". = 0x20; . = 0x10; }" >> %t.script +# RUN: echo ". = 0x20; . = 0x10; .text : {} }" >> %t.script # RUN: not ld.lld %t.o --script %t.script -o %t -shared 2>&1 | FileCheck %s # CHECK: {{.*}}.script:2: unable to move location counter backward diff --git a/lld/test/ELF/linkerscript/symbols-non-alloc.s b/lld/test/ELF/linkerscript/symbols-non-alloc.s index 7a656cb938c..e51a39ee5d2 100644 --- a/lld/test/ELF/linkerscript/symbols-non-alloc.s +++ b/lld/test/ELF/linkerscript/symbols-non-alloc.s @@ -13,7 +13,7 @@ # CHECK: .nonalloc 00000008 0000000000000000 # CHECK: SYMBOL TABLE: -# CHECK: 00000000000000f0 .nonalloc 00000000 Sym +# CHECK: 0000000000000008 .nonalloc 00000000 Sym .section .nonalloc,"" .quad 0 |

