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

via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 14 20:32:24 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");
----------------
yingopq wrote:

Now, MipsAsmParser.cpp use following code to parse .rdata,so the name, maybe I think, basically it won’t change.
```code
 if (IDVal == ".rdata") {
    parseRSectionDirective(".rodata");
    return false;
  }
```
And I have considered the situation you mentioned, the patch contains this situation, it use ```contains```to check if rdata section contains local symbol, instead of checking the next line.

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


More information about the llvm-commits mailing list