[lld] [lld][ELF] Skip finalizeAddressDependentContent if assignAddresses produces errors. (PR #75581)

via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 15 01:42:40 PST 2023


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-lld

@llvm/pr-subscribers-lld-elf

Author: Bevin Hansson (bevin-hansson)

<details>
<summary>Changes</summary>

There's no point in running the rest of finalizeAddressDependentContent
if the initial assignAddresses gives an error. Since we will also end
up running it again at least once, we might emit duplicate errors for
no reason.

Remember how many errors we had before we run assignAddresses the
first time, and if it changes, simply return.


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


2 Files Affected:

- (modified) lld/ELF/Writer.cpp (+4) 
- (modified) lld/test/ELF/linkerscript/symbolreferenced.s (+1-1) 


``````````diff
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index a84e4864ab0e5a..9a538e0ce54253 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -1679,7 +1679,11 @@ template <class ELFT> void Writer<ELFT>::finalizeAddressDependentContent() {
   ThunkCreator tc;
   AArch64Err843419Patcher a64p;
   ARMErr657417Patcher a32p;
+  unsigned errors = errorHandler().errorCount;
   script->assignAddresses();
+  // Exit out early if the first assignAddresses produced errors.
+  if (errors != errorHandler().errorCount)
+    return;
   // .ARM.exidx and SHF_LINK_ORDER do not require precise addresses, but they
   // do require the relative addresses of OutputSections because linker scripts
   // can assign Virtual Addresses to OutputSections that are not monotonically
diff --git a/lld/test/ELF/linkerscript/symbolreferenced.s b/lld/test/ELF/linkerscript/symbolreferenced.s
index ba7a7721ea9697..d8ea9be80aa5d5 100644
--- a/lld/test/ELF/linkerscript/symbolreferenced.s
+++ b/lld/test/ELF/linkerscript/symbolreferenced.s
@@ -28,7 +28,7 @@
 # CHECK-NEXT: 0000000000001000 A newsym
 
 # RUN: not ld.lld -T chain2.t a.o 2>&1 | FileCheck %s --check-prefix=ERR --implicit-check-not=error:
-# ERR-COUNT-3: error: chain2.t:1: symbol not found: undef
+# ERR-COUNT-2: error: chain2.t:1: symbol not found: undef
 
 #--- a.s
 .global _start

``````````

</details>


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


More information about the llvm-commits mailing list