[llvm] 63adf07 - ELFObjectWriter: Move Thumb-specific condition to ARMELFObjectWriter

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Sat May 24 22:31:44 PDT 2025


Author: Fangrui Song
Date: 2025-05-24T22:31:39-07:00
New Revision: 63adf075551221901cee551af101a484234fd1f2

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

LOG: ELFObjectWriter: Move Thumb-specific condition to ARMELFObjectWriter

Added: 
    

Modified: 
    llvm/lib/MC/ELFObjectWriter.cpp
    llvm/lib/Target/ARM/MCTargetDesc/ARMELFObjectWriter.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/MC/ELFObjectWriter.cpp b/llvm/lib/MC/ELFObjectWriter.cpp
index 7df9e90ebad12..ed3663056f0e0 100644
--- a/llvm/lib/MC/ELFObjectWriter.cpp
+++ b/llvm/lib/MC/ELFObjectWriter.cpp
@@ -1298,13 +1298,6 @@ bool ELFObjectWriter::useSectionSymbol(const MCValue &Val,
       return false;
   }
 
-  // If the symbol is a thumb function the final relocation must set the lowest
-  // bit. With a symbol that is done by just having the symbol have that bit
-  // set, so we would lose the bit if we relocated with the section.
-  // FIXME: We could use the section but add the bit to the relocation value.
-  if (EMachine == ELF::EM_ARM && Asm->isThumbFunc(Sym))
-    return false;
-
   return !TargetObjectWriter->needsRelocateWithSymbol(Val, *Sym, Type);
 }
 

diff  --git a/llvm/lib/Target/ARM/MCTargetDesc/ARMELFObjectWriter.cpp b/llvm/lib/Target/ARM/MCTargetDesc/ARMELFObjectWriter.cpp
index 3754f1c29c364..dcf98659fe8a8 100644
--- a/llvm/lib/Target/ARM/MCTargetDesc/ARMELFObjectWriter.cpp
+++ b/llvm/lib/Target/ARM/MCTargetDesc/ARMELFObjectWriter.cpp
@@ -10,6 +10,7 @@
 #include "MCTargetDesc/ARMMCExpr.h"
 #include "MCTargetDesc/ARMMCTargetDesc.h"
 #include "llvm/BinaryFormat/ELF.h"
+#include "llvm/MC/MCAssembler.h"
 #include "llvm/MC/MCContext.h"
 #include "llvm/MC/MCELFObjectWriter.h"
 #include "llvm/MC/MCExpr.h"
@@ -47,9 +48,16 @@ ARMELFObjectWriter::ARMELFObjectWriter(uint8_t OSABI)
                             ELF::EM_ARM,
                             /*HasRelocationAddend*/ false) {}
 
-bool ARMELFObjectWriter::needsRelocateWithSymbol(const MCValue &,
-                                                 const MCSymbol &,
+bool ARMELFObjectWriter::needsRelocateWithSymbol(const MCValue &Val,
+                                                 const MCSymbol &Sym,
                                                  unsigned Type) const {
+  // If the symbol is a thumb function the final relocation must set the lowest
+  // bit. With a symbol that is done by just having the symbol have that bit
+  // set, so we would lose the bit if we relocated with the section.
+  // We could use the section but add the bit to the relocation value.
+  if (Asm->isThumbFunc(Val.getAddSym()))
+    return true;
+
   // FIXME: This is extremely conservative. This really needs to use an
   // explicit list with a clear explanation for why each realocation needs to
   // point to the symbol, not to the section.


        


More information about the llvm-commits mailing list