@@ -149,6 +149,7 @@ class MipsAsmParser : public MCTargetAsmParser {
149
149
// directive.
150
150
bool IsLittleEndian;
151
151
bool IsPicEnabled;
152
+ bool HasParseRdata;
152
153
bool IsCpRestoreSet;
153
154
int CpRestoreOffset;
154
155
unsigned GPReg;
@@ -555,6 +556,7 @@ class MipsAsmParser : public MCTargetAsmParser {
555
556
IsPicEnabled = getContext ().getObjectFileInfo ()->isPositionIndependent ();
556
557
557
558
IsCpRestoreSet = false ;
559
+ HasParseRdata = false ;
558
560
CpRestoreOffset = -1 ;
559
561
GPReg = ABI.GetGlobalPtr ();
560
562
@@ -2920,11 +2922,45 @@ bool MipsAsmParser::loadAndAddSymbolAddress(const MCExpr *SymExpr,
2920
2922
(Res.getSymA ()->getSymbol ().isELF () &&
2921
2923
cast<MCSymbolELF>(Res.getSymA ()->getSymbol ()).getBinding () ==
2922
2924
ELF::STB_LOCAL);
2925
+
2923
2926
// For O32, "$"-prefixed symbols are recognized as temporary while
2924
2927
// .L-prefixed symbols are not (PrivateGlobalPrefix is "$"). Recognize ".L"
2925
2928
// manually.
2926
2929
if (ABI.IsO32 () && Res.getSymA ()->getSymbol ().getName ().starts_with (" .L" ))
2927
2930
IsLocalSym = true ;
2931
+ else {
2932
+ if (HasParseRdata == false ) {
2933
+ StringRef CurrentASMContent = StringRef (IDLoc.getPointer ());
2934
+
2935
+ // Get local symbol name LocalSymbol from "la $number, localsymbolname\n
2936
+ // ... "
2937
+ size_t NewlineIndex = CurrentASMContent.find_first_of (' \n ' );
2938
+ size_t CommaIndex = CurrentASMContent.find_first_of (' ,' );
2939
+ size_t SymbolLength = NewlineIndex - CommaIndex - 2 ;
2940
+ StringRef LocalSymbol =
2941
+ CurrentASMContent.take_front (NewlineIndex).take_back (SymbolLength);
2942
+
2943
+ // Get and check if ".rdata" section exist.
2944
+ size_t RdataIndex = CurrentASMContent.find (" .rdata" );
2945
+ if (RdataIndex != StringRef::npos) {
2946
+ StringRef Rdata = CurrentASMContent.substr (RdataIndex);
2947
+
2948
+ // Check if rdata section contain local symbol.
2949
+ if (1 == Rdata.contains (LocalSymbol)) {
2950
+ // Check if "LocalSymbol:" exist.
2951
+ size_t A = Rdata.find (LocalSymbol);
2952
+ size_t B = Rdata.find (' :' , A);
2953
+ if (B - A == LocalSymbol.size ()) {
2954
+ IsLocalSym = true ;
2955
+ LLVM_DEBUG (dbgs ()
2956
+ << DEBUG_TYPE << " : Has definition of local symbol "
2957
+ << LocalSymbol << " after 'la' instruction"
2958
+ << " \n " );
2959
+ }
2960
+ }
2961
+ }
2962
+ }
2963
+ }
2928
2964
bool UseXGOT = STI->hasFeature (Mips::FeatureXGOT) && !IsLocalSym;
2929
2965
2930
2966
// The case where the result register is $25 is somewhat special. If the
@@ -8073,6 +8109,7 @@ bool MipsAsmParser::parseDirectiveTpRelWord() {
8073
8109
if (getLexer ().isNot (AsmToken::EndOfStatement))
8074
8110
return Error (getLexer ().getLoc (),
8075
8111
" unexpected token, expected end of statement" );
8112
+ HasParseRdata = true ;
8076
8113
Parser.Lex (); // Eat EndOfStatement token.
8077
8114
return false ;
8078
8115
}
0 commit comments