[llvm] [Mips] Fix clang integrated assembler generates incorrect relocations… (PR #83115)

YunQiang Su via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 15 00:05:59 PDT 2024


================
@@ -2920,11 +2922,45 @@ bool MipsAsmParser::loadAndAddSymbolAddress(const MCExpr *SymExpr,
         (Res.getSymA()->getSymbol().isELF() &&
          cast<MCSymbolELF>(Res.getSymA()->getSymbol()).getBinding() ==
              ELF::STB_LOCAL);
+
     // For O32, "$"-prefixed symbols are recognized as temporary while
     // .L-prefixed symbols are not (PrivateGlobalPrefix is "$"). Recognize ".L"
     // manually.
     if (ABI.IsO32() && Res.getSymA()->getSymbol().getName().starts_with(".L"))
       IsLocalSym = true;
+    else {
+      if (HasParseRdata == false) {
+        StringRef CurrentASMContent = StringRef(IDLoc.getPointer());
+
+        // Get local symbol name LocalSymbol from "la $number, localsymbolname\n
+        // ... "
+        size_t NewlineIndex = CurrentASMContent.find_first_of('\n');
+        size_t CommaIndex = CurrentASMContent.find_first_of(',');
+        size_t SymbolLength = NewlineIndex - CommaIndex - 2;
+        StringRef LocalSymbol =
+            CurrentASMContent.take_front(NewlineIndex).take_back(SymbolLength);
----------------
wzssyqa wrote:

if the asm code is like 
```
# more spaces and windows style newline
LA   $a0,                          localsymbolname         \r\n
```
It won't work.

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


More information about the llvm-commits mailing list