diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp index 3689651203f16fa..4aa9e11a9f021a6 100644 --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -2926,22 +2926,32 @@ void LinkerDriver::link(opt::InputArgList &args) { demoteSharedAndLazySymbols(); if (config->emachine == EM_BPF || config->emachine == EM_SBF) { + std::string StackError; + bool hasEntrypoint = false; for (const Symbol *sb : symtab.getSymbols()) { if (sb->getName().ends_with("::stack_overflow")) { const StringRef FuncName = sb->getName().substr(0, sb->getName().size() - 16); - report_fatal_error("Function " + FuncName + - " utilizes too much stack space and will cause " - "undefined behavior in the program. Refer to a" - "previously emitted warning for more information."); + StackError = "Function " + FuncName.str() + + " utilizes too much stack space and will cause " + "undefined behavior in the program. Refer to a" + "previously emitted warning for more information."; + break; } else if (sb->getName().ends_with("::call_overflow")) { const StringRef FuncName = sb->getName().substr(0, sb->getName().size() - 15); - report_fatal_error("A function call inside method " + FuncName + - "will overwrite data in the stack frame. Refer to a " - "previously emitted warning for more information."); + StackError = "A function call inside method " + FuncName.str() + + "will overwrite data in the stack frame. Refer to a " + "previously emitted warning for more information."; + break; + } else if (!hasEntrypoint && sb->getName() == "entrypoint") { + hasEntrypoint = true; } } + + if (!StackError.empty() && hasEntrypoint) { + report_fatal_error(StringRef(StackError)); + } } // Make copies of any input sections that need to be copied into each