Skip to content

Commit ce487d4

Browse files
authored
Merge pull request #9135 from bnbarham/jit-failures
[rebranch] Various JIT failure workarounds
2 parents 0b4e2f5 + a655fbe commit ce487d4

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

llvm/lib/ExecutionEngine/JITLink/ELFLinkGraphBuilder.h

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -374,14 +374,7 @@ template <typename ELFT> Error ELFLinkGraphBuilder<ELFT>::graphifySections() {
374374
}
375375
}
376376

377-
if (GraphSec->getMemProt() != Prot) {
378-
std::string ErrMsg;
379-
raw_string_ostream(ErrMsg)
380-
<< "In " << G->getName() << ", section " << *Name
381-
<< " is present more than once with different permissions: "
382-
<< GraphSec->getMemProt() << " vs " << Prot;
383-
return make_error<JITLinkError>(std::move(ErrMsg));
384-
}
377+
GraphSec->setMemProt(GraphSec->getMemProt() | Prot);
385378

386379
Block *B = nullptr;
387380
if (Sec.sh_type != ELF::SHT_NOBITS) {
@@ -528,18 +521,21 @@ template <typename ELFT> Error ELFLinkGraphBuilder<ELFT>::graphifySymbols() {
528521
return make_error<JITLinkError>(std::move(ErrMsg));
529522
}
530523

524+
// Truncate symbol if it would overflow -- ELF size fields can't be
525+
// trusted.
526+
uint64_t Size =
527+
std::min(static_cast<uint64_t>(Sym.st_size), B->getSize() - Offset);
528+
531529
// In RISCV, temporary symbols (Used to generate dwarf, eh_frame
532530
// sections...) will appear in object code's symbol table, and LLVM does
533531
// not use names on these temporary symbols (RISCV gnu toolchain uses
534532
// names on these temporary symbols). If the symbol is unnamed, add an
535533
// anonymous symbol.
536534
auto &GSym =
537535
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);
536+
? G->addAnonymousSymbol(*B, Offset, Size, false, false)
537+
: G->addDefinedSymbol(*B, Offset, *Name, Size, L, S,
538+
Sym.getType() == ELF::STT_FUNC, false);
543539

544540
GSym.setTargetFlags(Flags);
545541
setGraphSymbol(SymIndex, GSym);

0 commit comments

Comments
 (0)