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

YunQiang Su via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 12 16:53:20 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);
+
+        // Get and check if ".rdata" section exist.
+        size_t RdataIndex = CurrentASMContent.find(".rdata");
----------------
wzssyqa wrote:

And I think that we need a more generic solution.
The naive scan string may have lots of bug.
maybe something like, in the next lines, we may have:

```
do_read_rdata:
      lw ...
      lw ...
```

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


More information about the llvm-commits mailing list