Skip to content

Commit ad50149

Browse files
Merge pull request #11005 from swiftlang/jepa-stable
[stable/20250601] Various JIT failure workarounds
2 parents 556ab11 + 1234d78 commit ad50149

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

llvm/lib/ExecutionEngine/JITLink/ELFLinkGraphBuilder.h

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

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

387380
Block *B = nullptr;
388381
if (Sec.sh_type != ELF::SHT_NOBITS) {
@@ -513,7 +506,14 @@ template <typename ELFT> Error ELFLinkGraphBuilder<ELFT>::graphifySymbols() {
513506
TargetFlagsType Flags = makeTargetFlags(Sym);
514507
orc::ExecutorAddrDiff Offset = getRawOffset(Sym, Flags);
515508

516-
if (Offset + Sym.st_size > B->getSize()) {
509+
// Truncate symbol if it would overflow -- ELF size fields can't be
510+
// trusted.
511+
// FIXME: this makes the following error check unreachable, but it's
512+
// left here to reduce merge conflicts.
513+
uint64_t Size =
514+
std::min(static_cast<uint64_t>(Sym.st_size), B->getSize() - Offset);
515+
516+
if (Offset + Size > B->getSize()) {
517517
std::string ErrMsg;
518518
raw_string_ostream ErrStream(ErrMsg);
519519
ErrStream << "In " << G->getName() << ", symbol ";
@@ -536,11 +536,9 @@ template <typename ELFT> Error ELFLinkGraphBuilder<ELFT>::graphifySymbols() {
536536
// anonymous symbol.
537537
auto &GSym =
538538
Name->empty()
539-
? G->addAnonymousSymbol(*B, Offset, Sym.st_size,
540-
false, false)
541-
: G->addDefinedSymbol(*B, Offset, *Name, Sym.st_size, L,
542-
S, Sym.getType() == ELF::STT_FUNC,
543-
false);
539+
? G->addAnonymousSymbol(*B, Offset, Size, false, false)
540+
: G->addDefinedSymbol(*B, Offset, *Name, Size, L, S,
541+
Sym.getType() == ELF::STT_FUNC, false);
544542

545543
GSym.setTargetFlags(Flags);
546544
setGraphSymbol(SymIndex, GSym);

0 commit comments

Comments
 (0)