@@ -177,6 +177,8 @@ class AsmParser : public MCAsmParser {
177
177
178
178
// / Are we parsing ms-style inline assembly?
179
179
bool ParsingMSInlineAsm = false ;
180
+ bool NeedParseFromRdata = false ;
181
+ int ParseRdataCnt = 0 ;
180
182
181
183
// / Did we already inform the user about inconsistent MD5 usage?
182
184
bool ReportedInconsistentMD5 = false ;
@@ -996,11 +998,65 @@ bool AsmParser::Run(bool NoInitialTextSection, bool NoFinalize) {
996
998
997
999
getTargetParser ().onBeginOfFile ();
998
1000
1001
+ // Save begin location, check if have .rdata section, confirm where to begin
1002
+ // parse. If have it and .rdata after .text, begin parse from .rdata, when go
1003
+ // to Eof, jump to begin location and then continue parse.
1004
+ SMLoc IDLoc_start = getTok ().getLoc ();
1005
+ SMLoc IDLoc_rdata = getTok ().getLoc ();
1006
+ StringRef IDVal;
1007
+ bool HasParseText = false ;
1008
+ bool HasParseRdata = false ;
1009
+ while (Lexer.isNot (AsmToken::Eof)) {
1010
+ while (Lexer.is (AsmToken::Space)) {
1011
+ IDLoc_rdata = getTok ().getLoc ();
1012
+ Lex ();
1013
+ }
1014
+ if (Lexer.is (AsmToken::EndOfStatement) || Lexer.is (AsmToken::Integer) ||
1015
+ Lexer.is (AsmToken::Dot) || Lexer.is (AsmToken::LCurly) ||
1016
+ Lexer.is (AsmToken::RCurly) ||
1017
+ (Lexer.is (AsmToken::Star) &&
1018
+ getTargetParser ().starIsStartOfStatement ())) {
1019
+ IDLoc_rdata = getTok ().getLoc ();
1020
+ Lex ();
1021
+ } else if (!parseIdentifier (IDVal)) {
1022
+ if (IDVal == " .rdata" )
1023
+ HasParseRdata = true ;
1024
+ if (IDVal == " .text" )
1025
+ HasParseText = true ;
1026
+ // .text section before .rdata section.
1027
+ if (IDVal == " .rdata" && HasParseText == true ) {
1028
+ NeedParseFromRdata = true ;
1029
+ jumpToLoc (IDLoc_rdata);
1030
+ Lex ();
1031
+ break ;
1032
+ }
1033
+ if (IDVal == " .text" && HasParseRdata == true ) {
1034
+ break ;
1035
+ }
1036
+ IDLoc_rdata = getTok ().getLoc ();
1037
+ Lex ();
1038
+ } else {
1039
+ IDLoc_rdata = getTok ().getLoc ();
1040
+ Lex ();
1041
+ }
1042
+ }
1043
+
1044
+ // If did not have .rdata section or .rdata before .text, jump to begin
1045
+ // location and then parse.
1046
+ if (NeedParseFromRdata == false ) {
1047
+ jumpToLoc (IDLoc_start);
1048
+ Lex ();
1049
+ }
1050
+
1051
+ BeginParse:
999
1052
// While we have input, parse each statement.
1000
1053
while (Lexer.isNot (AsmToken::Eof)) {
1001
1054
ParseStatementInfo Info (&AsmStrRewrites);
1002
1055
bool Parsed = parseStatement (Info, nullptr );
1003
1056
1057
+ if (!Parsed && (ParseRdataCnt == 2 )) {
1058
+ break ;
1059
+ }
1004
1060
// If we have a Lexer Error we are on an Error Token. Load in Lexer Error
1005
1061
// for printing ErrMsg via Lex() only if no (presumably better) parser error
1006
1062
// exists.
@@ -1016,6 +1072,15 @@ bool AsmParser::Run(bool NoInitialTextSection, bool NoFinalize) {
1016
1072
eatToEndOfStatement ();
1017
1073
}
1018
1074
1075
+ // Because when we parse from .rdata, what before .rdata would be skipped and
1076
+ // not be parsed, so need to go to begin location until once again parse
1077
+ // .rdata section.
1078
+ if (NeedParseFromRdata == true ) {
1079
+ jumpToLoc (IDLoc_start);
1080
+ Lex ();
1081
+ goto BeginParse;
1082
+ }
1083
+
1019
1084
getTargetParser ().onEndOfFile ();
1020
1085
printPendingErrors ();
1021
1086
@@ -2003,6 +2068,15 @@ bool AsmParser::parseStatement(ParseStatementInfo &Info,
2003
2068
// manner, or at least have a default behavior that's shared between
2004
2069
// all targets and platforms.
2005
2070
2071
+ // Prevent parsing .rdata section twice.
2072
+ if (IDVal == " .rdata" ) {
2073
+ ParseRdataCnt++;
2074
+ }
2075
+ if (NeedParseFromRdata == true && ParseRdataCnt == 2 ) {
2076
+ NeedParseFromRdata = false ;
2077
+ return false ;
2078
+ }
2079
+
2006
2080
getTargetParser ().flushPendingInstructions (getStreamer ());
2007
2081
2008
2082
ParseStatus TPDirectiveReturn = getTargetParser ().parseDirective (ID);
0 commit comments