diff options
| author | George Rimar <grimar@accesssoftek.com> | 2017-04-14 09:23:26 +0000 |
|---|---|---|
| committer | George Rimar <grimar@accesssoftek.com> | 2017-04-14 09:23:26 +0000 |
| commit | 01aa795f82d8c587b47ed85c2c94b895ce1990f8 (patch) | |
| tree | 5550a93051494e2b197238fd1b5fea41fec3679f /lld/ELF/LinkerScript.cpp | |
| parent | 4e7bcd5216afb5e380fe21bfa7401253d9046138 (diff) | |
| download | bcm5719-llvm-01aa795f82d8c587b47ed85c2c94b895ce1990f8.tar.gz bcm5719-llvm-01aa795f82d8c587b47ed85c2c94b895ce1990f8.zip | |
[ELF] LinkerScript: Don't assign zero to all regular symbols
This fixes an assertion `Align != 0u && "Align can't be 0."'
in llvm::alignTo() when a linker script references a globally
defined variable in an ALIGN() context.
Patch by Alexander Richardson !
Differential revision: https://reviews.llvm.org/D31984
llvm-svn: 300315
Diffstat (limited to 'lld/ELF/LinkerScript.cpp')
| -rw-r--r-- | lld/ELF/LinkerScript.cpp | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp index fdd6220c015..5a9e4652b22 100644 --- a/lld/ELF/LinkerScript.cpp +++ b/lld/ELF/LinkerScript.cpp @@ -68,8 +68,13 @@ template <class ELFT> static SymbolBody *addRegular(SymbolAssignment *Cmd) { Sym->Binding = STB_GLOBAL; ExprValue Value = Cmd->Expression(); SectionBase *Sec = Value.isAbsolute() ? nullptr : Value.Sec; + + // We want to set symbol values early if we can. This allows us to use symbols + // as variables in linker scripts. Doing so allows us to write expressions + // like this: `alignment = 16; . = ALIGN(., alignment)` + uint64_t SymValue = Value.isAbsolute() ? Value.getValue() : 0; replaceBody<DefinedRegular>(Sym, Cmd->Name, /*IsLocal=*/false, Visibility, - STT_NOTYPE, 0, 0, Sec, nullptr); + STT_NOTYPE, SymValue, 0, Sec, nullptr); return Sym->body(); } |

