[llvm] aa96e20 - MCSymbol: Remove AMDGPU-specific Kind::TargetCommon

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Sat Aug 16 15:39:38 PDT 2025


Author: Fangrui Song
Date: 2025-08-16T15:39:33-07:00
New Revision: aa96e20dcefa7d73229c98a7d2727696ff949459

URL: https://github.com/llvm/llvm-project/commit/aa96e20dcefa7d73229c98a7d2727696ff949459
DIFF: https://github.com/llvm/llvm-project/commit/aa96e20dcefa7d73229c98a7d2727696ff949459.diff

LOG: MCSymbol: Remove AMDGPU-specific Kind::TargetCommon

The SymContentsTargetCommon kind introduced by
https://reviews.llvm.org/D61493 lackes significant and should be treated
as a regular common symbol with a different section index.

Update ELFObjectWriter to respect the specified section index.
The new representation also works with Hexagon's SHN_HEXAGON_SCOMMON.

Added: 
    

Modified: 
    llvm/include/llvm/MC/MCSymbol.h
    llvm/lib/MC/ELFObjectWriter.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/MC/MCSymbol.h b/llvm/include/llvm/MC/MCSymbol.h
index 740fae22d1b91..88e2230a0c340 100644
--- a/llvm/include/llvm/MC/MCSymbol.h
+++ b/llvm/include/llvm/MC/MCSymbol.h
@@ -46,7 +46,6 @@ class MCSymbol {
     Regular,
     Equated,
     Common,
-    TargetCommon, // Index stores the section index
   };
 
   // Special sentinel value for the absolute pseudo fragment.
@@ -315,7 +314,7 @@ class MCSymbol {
   void setCommon(uint64_t Size, Align Alignment, bool Target = false) {
     assert(getOffset() == 0);
     CommonSize = Size;
-    kind = Target ? Kind::TargetCommon : Kind::Common;
+    kind = Kind::Common;
 
     unsigned Log2Align = encode(Alignment);
     assert(Log2Align < (1U << NumCommonAlignmentBits) &&
@@ -338,8 +337,7 @@ class MCSymbol {
   bool declareCommon(uint64_t Size, Align Alignment, bool Target = false) {
     assert(isCommon() || getOffset() == 0);
     if(isCommon()) {
-      if (CommonSize != Size || getCommonAlignment() != Alignment ||
-          isTargetCommon() != Target)
+      if (CommonSize != Size || getCommonAlignment() != Alignment)
         return true;
     } else
       setCommon(Size, Alignment, Target);
@@ -347,13 +345,7 @@ class MCSymbol {
   }
 
   /// Is this a 'common' symbol.
-  bool isCommon() const {
-    return kind == Kind::Common || kind == Kind::TargetCommon;
-  }
-
-  /// Used by AMDGPU to indicate a common-like symbol of section index
-  /// SHN_AMDGPU_LDS.
-  bool isTargetCommon() const { return kind == Kind::TargetCommon; }
+  bool isCommon() const { return kind == Kind::Common; }
 
   MCFragment *getFragment() const {
     if (Fragment || !isVariable() || isWeakExternal())

diff  --git a/llvm/lib/MC/ELFObjectWriter.cpp b/llvm/lib/MC/ELFObjectWriter.cpp
index 8f3814a1dd62e..759d3e0e14291 100644
--- a/llvm/lib/MC/ELFObjectWriter.cpp
+++ b/llvm/lib/MC/ELFObjectWriter.cpp
@@ -541,12 +541,12 @@ void ELFWriter::computeSymbolTable(const RevGroupMapTy &RevGroupMap) {
     if (Symbol.isAbsolute()) {
       MSD.SectionIndex = ELF::SHN_ABS;
     } else if (Symbol.isCommon()) {
-      if (Symbol.isTargetCommon()) {
-        MSD.SectionIndex = Symbol.getIndex();
-      } else {
+      auto Shndx = Symbol.getIndex();
+      if (!Shndx) {
         assert(!Local);
-        MSD.SectionIndex = ELF::SHN_COMMON;
+        Shndx = ELF::SHN_COMMON;
       }
+      MSD.SectionIndex = Shndx;
     } else if (Symbol.isUndefined()) {
       if (Symbol.isSignature() && !Symbol.isUsedInReloc()) {
         MSD.SectionIndex = RevGroupMap.lookup(&Symbol);


        


More information about the llvm-commits mailing list