Skip to content

Commit 2f53a4c

Browse files
lhamesbnbarham
authored andcommitted
[JITLink] Truncate ELF symbol sizes to fit containing block.
LLVM currently emits dubious symbol sizes for aliases. E.g. assembling the following with LLVM top-of-tree... ``` $ cat foo.s <snip> .data .globl base base: .dword 42 .size base, 8 .set alias, base+4 ``` results in both base and alias having symbol size 8, even alias starts at base + 4. This also means that alias extends past the end of the .data section in this example. We should probably teach LLVM not to do this in the future, but as a short-term fix this patch teaches JITLink to simply truncate symbols that would extend past the end of their containing block. rdar://114207607 (cherry picked from commit 6267697) Conflicts: llvm/lib/ExecutionEngine/JITLink/ELFLinkGraphBuilder.h
1 parent 8f9b972 commit 2f53a4c

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

llvm/lib/ExecutionEngine/JITLink/ELFLinkGraphBuilder.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -528,18 +528,21 @@ template <typename ELFT> Error ELFLinkGraphBuilder<ELFT>::graphifySymbols() {
528528
return make_error<JITLinkError>(std::move(ErrMsg));
529529
}
530530

531+
// Truncate symbol if it would overflow -- ELF size fields can't be
532+
// trusted.
533+
uint64_t Size =
534+
std::min(static_cast<uint64_t>(Sym.st_size), B->getSize() - Offset);
535+
531536
// In RISCV, temporary symbols (Used to generate dwarf, eh_frame
532537
// sections...) will appear in object code's symbol table, and LLVM does
533538
// not use names on these temporary symbols (RISCV gnu toolchain uses
534539
// names on these temporary symbols). If the symbol is unnamed, add an
535540
// anonymous symbol.
536541
auto &GSym =
537542
Name->empty()
538-
? G->addAnonymousSymbol(*B, Offset, Sym.st_size,
539-
false, false)
540-
: G->addDefinedSymbol(*B, Offset, *Name, Sym.st_size, L,
541-
S, Sym.getType() == ELF::STT_FUNC,
542-
false);
543+
? G->addAnonymousSymbol(*B, Offset, Size, false, false)
544+
: G->addDefinedSymbol(*B, Offset, *Name, Size, L, S,
545+
Sym.getType() == ELF::STT_FUNC, false);
543546

544547
GSym.setTargetFlags(Flags);
545548
setGraphSymbol(SymIndex, GSym);

0 commit comments

Comments
 (0)