@@ -374,14 +374,7 @@ template <typename ELFT> Error ELFLinkGraphBuilder<ELFT>::graphifySections() {
374
374
}
375
375
}
376
376
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);
385
378
386
379
Block *B = nullptr ;
387
380
if (Sec.sh_type != ELF::SHT_NOBITS) {
@@ -528,18 +521,21 @@ template <typename ELFT> Error ELFLinkGraphBuilder<ELFT>::graphifySymbols() {
528
521
return make_error<JITLinkError>(std::move (ErrMsg));
529
522
}
530
523
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
+
531
529
// In RISCV, temporary symbols (Used to generate dwarf, eh_frame
532
530
// sections...) will appear in object code's symbol table, and LLVM does
533
531
// not use names on these temporary symbols (RISCV gnu toolchain uses
534
532
// names on these temporary symbols). If the symbol is unnamed, add an
535
533
// anonymous symbol.
536
534
auto &GSym =
537
535
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 );
543
539
544
540
GSym.setTargetFlags (Flags);
545
541
setGraphSymbol (SymIndex, GSym);
0 commit comments