[lld] [lld][ELF] Warn instead of error when linker script fails to find section (PR #68058)

via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 2 17:23:11 PDT 2023


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-lld

<details>
<summary>Changes</summary>

It can be hard to predict whether a section exist when using the `INSERT AFTER/BEFORE <section>` directive, this makes it difficult to apply a global linker script that's applicable to the entire build system. We should warn instead of hard error in such cases.

---
Full diff: https://github.com/llvm/llvm-project/pull/68058.diff


2 Files Affected:

- (modified) lld/ELF/LinkerScript.cpp (+1-1) 
- (modified) lld/test/ELF/linkerscript/insert-not-exist.test (+3-3) 


``````````diff
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp
index df091613dc0a144..84658751b30487d 100644
--- a/lld/ELF/LinkerScript.cpp
+++ b/lld/ELF/LinkerScript.cpp
@@ -327,7 +327,7 @@ void LinkerScript::processInsertCommands() {
           return to != nullptr && to->osec.name == cmd.where;
         });
     if (insertPos == sectionCommands.end()) {
-      error("unable to insert " + cmd.names[0] +
+      warn("unable to insert " + cmd.names[0] +
             (cmd.isAfter ? " after " : " before ") + cmd.where);
     } else {
       if (cmd.isAfter)
diff --git a/lld/test/ELF/linkerscript/insert-not-exist.test b/lld/test/ELF/linkerscript/insert-not-exist.test
index 8bb8a7d0ce8dc8f..4f68ad378678edd 100644
--- a/lld/test/ELF/linkerscript/insert-not-exist.test
+++ b/lld/test/ELF/linkerscript/insert-not-exist.test
@@ -1,9 +1,9 @@
 # REQUIRES: x86
 # RUN: llvm-mc -filetype=obj -triple=x86_64 %p/Inputs/insert-after.s -o %t.o
-# RUN: not ld.lld -T %s %t.o -o /dev/null 2>&1 | FileCheck %s
+# RUN: ld.lld -T %s %t.o -o /dev/null 2>&1 | FileCheck %s
 
-# CHECK: error: unable to insert .foo.data after .not_exist
-# CHECK: error: unable to insert .foo.text before .not_exist
+# CHECK: warning: unable to insert .foo.data after .not_exist
+# CHECK: warning: unable to insert .foo.text before .not_exist
 
 SECTIONS { .foo.data : {} } INSERT AFTER .not_exist;
 SECTIONS { .foo.text : {} } INSERT BEFORE .not_exist;

``````````

</details>


https://github.com/llvm/llvm-project/pull/68058


More information about the llvm-commits mailing list