diff --git a/llvm/lib/ExecutionEngine/JITLink/ELFLinkGraphBuilder.h b/llvm/lib/ExecutionEngine/JITLink/ELFLinkGraphBuilder.h index 550a55705943b..60f4e8d35129d 100644 --- a/llvm/lib/ExecutionEngine/JITLink/ELFLinkGraphBuilder.h +++ b/llvm/lib/ExecutionEngine/JITLink/ELFLinkGraphBuilder.h @@ -505,7 +505,14 @@ template Error ELFLinkGraphBuilder::graphifySymbols() { TargetFlagsType Flags = makeTargetFlags(Sym); orc::ExecutorAddrDiff Offset = getRawOffset(Sym, Flags); - if (Offset + Sym.st_size > B->getSize()) { + // Truncate symbol if it would overflow -- ELF size fields can't be + // trusted. + // FIXME: this makes the following error check unreachable, but it's + // left here to reduce merge conflicts. + uint64_t Size = + std::min(static_cast(Sym.st_size), B->getSize() - Offset); + + if (Offset + Size > B->getSize()) { std::string ErrMsg; raw_string_ostream ErrStream(ErrMsg); ErrStream << "In " << G->getName() << ", symbol "; @@ -521,11 +528,6 @@ template Error ELFLinkGraphBuilder::graphifySymbols() { return make_error(std::move(ErrMsg)); } - // Truncate symbol if it would overflow -- ELF size fields can't be - // trusted. - uint64_t Size = - std::min(static_cast(Sym.st_size), B->getSize() - Offset); - // In RISCV, temporary symbols (Used to generate dwarf, eh_frame // sections...) will appear in object code's symbol table, and LLVM does // not use names on these temporary symbols (RISCV gnu toolchain uses