[lld] [LLD] [COFF] Ubuntu24 build failure due to LLD's COFF regression (PR #98447)

Vikash Gupta via llvm-commits llvm-commits at lists.llvm.org
Sun Jul 21 23:32:35 PDT 2024


https://github.com/vg0204 updated https://github.com/llvm/llvm-project/pull/98447

>From 5366a612f500eb46f249230c74458dfb29d5061d Mon Sep 17 00:00:00 2001
From: vg0204 <Vikash.Gupta at amd.com>
Date: Thu, 11 Jul 2024 14:05:34 +0530
Subject: [PATCH 1/2] [LLD] [Build Issue] Ubuntu24 build failure  due to LLD's
 COFF regression

It happened due to lld's COFF linker multiple regression tests
failure. The bug found can be identified as a Heisenbug, which
appears only in Release mode, not in Debug mode. It also vanishes
when BUG is being tried to be outputed out or isolated. This
behaviour cannot be seen at all in OS below Ubuntu24.

Eventually, the bug was about not handling exported symbols properly,
when dealing with defining undefined symbols for COFF linker. Its
specifically about improper forwarding of isUsedinRegObject boolean
while invoking replaceSymbol() API, so hence explicitly doing it
resolved issue.
---
 lld/COFF/Symbols.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/lld/COFF/Symbols.h b/lld/COFF/Symbols.h
index 5ef46f5af6a6c..d33989841c501 100644
--- a/lld/COFF/Symbols.h
+++ b/lld/COFF/Symbols.h
@@ -499,8 +499,10 @@ void replaceSymbol(Symbol *s, ArgT &&... arg) {
   assert(static_cast<Symbol *>(static_cast<T *>(nullptr)) == nullptr &&
          "Not a Symbol");
   bool canInline = s->canInline;
+  bool isUsedInRegularObj = s->isUsedInRegularObj;
   new (s) T(std::forward<ArgT>(arg)...);
   s->canInline = canInline;
+  s->isUsedInRegularObj = isUsedInRegularObj;
 }
 } // namespace coff
 

>From 0a3e465cf3bf472e2c8bd2e83cc98c0ecc8f773e Mon Sep 17 00:00:00 2001
From: vg0204 <Vikash.Gupta at amd.com>
Date: Mon, 22 Jul 2024 12:04:13 +0530
Subject: [PATCH 2/2] Added missing zero-initialization of isUsedInRegularObj
 in COFF's symbol, exposing the BUG.

---
 lld/COFF/Symbols.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/lld/COFF/Symbols.h b/lld/COFF/Symbols.h
index d33989841c501..56b137d56873a 100644
--- a/lld/COFF/Symbols.h
+++ b/lld/COFF/Symbols.h
@@ -98,10 +98,10 @@ class Symbol {
   friend SymbolTable;
   explicit Symbol(Kind k, StringRef n = "")
       : symbolKind(k), isExternal(true), isCOMDAT(false),
-        writtenToSymtab(false), pendingArchiveLoad(false), isGCRoot(false),
-        isRuntimePseudoReloc(false), deferUndefined(false), canInline(true),
-        isWeak(false), nameSize(n.size()),
-        nameData(n.empty() ? nullptr : n.data()) {
+        writtenToSymtab(false), isUsedInRegularObj(false),
+        pendingArchiveLoad(false), isGCRoot(false), isRuntimePseudoReloc(false),
+        deferUndefined(false), canInline(true), isWeak(false),
+        nameSize(n.size()), nameData(n.empty() ? nullptr : n.data()) {
     assert((!n.empty() || k <= LastDefinedCOFFKind) &&
            "If the name is empty, the Symbol must be a DefinedCOFF.");
   }



More information about the llvm-commits mailing list