llvm.org GIT mirror llvm / a034c96
Fix parsing of .symver directive on ARM ARM assembly syntax uses @ for a comment, execpt for the second parameter of the .symver directive which requires @ as part of the symbol name. This commit fixes the parsing of this directive by adding a special case for ARM for this one argumnet. To make the change we had to move the AllowAtInIdentifier variable to the MCAsmLexer interface (from AsmLexer) and expose a setter for the value. The ELFAsmParser then toggles this value when parsing the second argument to the .symver directive for a target that uses @ as a comment symbol git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@199339 91177308-0d34-0410-b5e6-96231b3b80d8 David Peixotto 6 years ago
5 changed file(s) with 187 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
2929 const char *CurPtr;
3030 const MemoryBuffer *CurBuf;
3131 bool isAtStartOfLine;
32 bool AllowAtInIdentifier; // Cached here to avoid repeated MAI query.
3332
3433 void operator=(const AsmLexer&) LLVM_DELETED_FUNCTION;
3534 AsmLexer(const AsmLexer&) LLVM_DELETED_FUNCTION;
117117 protected: // Can only create subclasses.
118118 const char *TokStart;
119119 bool SkipSpace;
120 bool AllowAtInIdentifier;
120121
121122 MCAsmLexer();
122123
169170
170171 /// setSkipSpace - Set whether spaces should be ignored by the lexer
171172 void setSkipSpace(bool val) { SkipSpace = val; }
173
174 bool getAllowAtInIdentifier() { return AllowAtInIdentifier; }
175 void setAllowAtInIdentifier(bool v) { AllowAtInIdentifier = v; }
172176 };
173177
174178 } // End llvm namespace
589589 if (getLexer().isNot(AsmToken::Comma))
590590 return TokError("expected a comma");
591591
592 Lex();
592 // ARM assembly uses @ for a comment...
593 // except when parsing the second parameter of the .symver directive.
594 // Force the next symbol to allow @ in the identifier, which is
595 // required for this directive and then reset it to its initial state.
596 const bool AllowAtInIdentifier = getLexer().getAllowAtInIdentifier();
597 getLexer().setAllowAtInIdentifier(true);
598 Lex();
599 getLexer().setAllowAtInIdentifier(AllowAtInIdentifier);
593600
594601 StringRef AliasName;
595602 if (getParser().parseIdentifier(AliasName))
0 @ RUN: llvm-mc -filetype=obj -triple arm-none-linux-gnueabi %s -o - | llvm-readobj -r -t | FileCheck %s
1 @ RUN: llvm-mc -filetype=obj -triple thumb-none-linux-gnueabi %s -o - | llvm-readobj -r -t | FileCheck %s
2
3 defined1:
4 defined2:
5 defined3:
6 .symver defined1, bar1@zed
7 .symver undefined1, bar2@zed
8
9 .symver defined2, bar3@@zed
10
11 .symver defined3, bar5@@@zed
12 .symver undefined3, bar6@@@zed
13
14 .long defined1
15 .long undefined1
16 .long defined2
17 .long defined3
18 .long undefined3
19
20 .global global1
21 .symver global1, g1@@zed
22 global1:
23
24 @ CHECK: Relocations [
25 @ CHECK-NEXT: Section (2) .rel.text {
26 @ CHECK-NEXT: 0x0 R_ARM_ABS32 defined1 0x0
27 @ CHECK-NEXT: 0x4 R_ARM_ABS32 bar2@zed 0x0
28 @ CHECK-NEXT: 0x8 R_ARM_ABS32 defined2 0x0
29 @ CHECK-NEXT: 0xC R_ARM_ABS32 defined3 0x0
30 @ CHECK-NEXT: 0x10 R_ARM_ABS32 bar6@zed 0x0
31 @ CHECK-NEXT: }
32 @ CHECK-NEXT: ]
33
34 @ CHECK: Symbol {
35 @ CHECK: Name: bar1@zed (28)
36 @ CHECK-NEXT: Value: 0x0
37 @ CHECK-NEXT: Size: 0
38 @ CHECK-NEXT: Binding: Local (0x0)
39 @ CHECK-NEXT: Type: None (0x0)
40 @ CHECK-NEXT: Other: 0
41 @ CHECK-NEXT: Section: .text (0x1)
42 @ CHECK-NEXT: }
43 @ CHECK-NEXT: Symbol {
44 @ CHECK-NEXT: Name: bar3@@zed (46)
45 @ CHECK-NEXT: Value: 0x0
46 @ CHECK-NEXT: Size: 0
47 @ CHECK-NEXT: Binding: Local (0x0)
48 @ CHECK-NEXT: Type: None (0x0)
49 @ CHECK-NEXT: Other: 0
50 @ CHECK-NEXT: Section: .text (0x1)
51 @ CHECK-NEXT: }
52 @ CHECK-NEXT: Symbol {
53 @ CHECK-NEXT: Name: bar5@@zed (56)
54 @ CHECK-NEXT: Value: 0x0
55 @ CHECK-NEXT: Size: 0
56 @ CHECK-NEXT: Binding: Local (0x0)
57 @ CHECK-NEXT: Type: None (0x0)
58 @ CHECK-NEXT: Other: 0
59 @ CHECK-NEXT: Section: .text (0x1)
60 @ CHECK-NEXT: }
61 @ CHECK-NEXT: Symbol {
62 @ CHECK-NEXT: Name: defined1 (1)
63 @ CHECK-NEXT: Value: 0x0
64 @ CHECK-NEXT: Size: 0
65 @ CHECK-NEXT: Binding: Local (0x0)
66 @ CHECK-NEXT: Type: None (0x0)
67 @ CHECK-NEXT: Other: 0
68 @ CHECK-NEXT: Section: .text (0x1)
69 @ CHECK-NEXT: }
70 @ CHECK-NEXT: Symbol {
71 @ CHECK-NEXT: Name: defined2 (10)
72 @ CHECK-NEXT: Value: 0x0
73 @ CHECK-NEXT: Size: 0
74 @ CHECK-NEXT: Binding: Local (0x0)
75 @ CHECK-NEXT: Type: None (0x0)
76 @ CHECK-NEXT: Other: 0
77 @ CHECK-NEXT: Section: .text (0x1)
78 @ CHECK-NEXT: }
79 @ CHECK-NEXT: Symbol {
80 @ CHECK-NEXT: Name: defined3 (19)
81 @ CHECK-NEXT: Value: 0x0
82 @ CHECK-NEXT: Size: 0
83 @ CHECK-NEXT: Binding: Local (0x0)
84 @ CHECK-NEXT: Type: None (0x0)
85 @ CHECK-NEXT: Other: 0
86 @ CHECK-NEXT: Section: .text (0x1)
87 @ CHECK-NEXT: }
88 @ CHECK-NEXT: Symbol {
89 @ CHECK-NEXT: Name: .text (0)
90 @ CHECK-NEXT: Value: 0x0
91 @ CHECK-NEXT: Size: 0
92 @ CHECK-NEXT: Binding: Local (0x0)
93 @ CHECK-NEXT: Type: Section (0x3)
94 @ CHECK-NEXT: Other: 0
95 @ CHECK-NEXT: Section: .text (0x1)
96 @ CHECK-NEXT: }
97 @ CHECK-NEXT: Symbol {
98 @ CHECK-NEXT: Name: .data (0)
99 @ CHECK-NEXT: Value: 0x0
100 @ CHECK-NEXT: Size: 0
101 @ CHECK-NEXT: Binding: Local (0x0)
102 @ CHECK-NEXT: Type: Section (0x3)
103 @ CHECK-NEXT: Other: 0
104 @ CHECK-NEXT: Section: .data (0x3)
105 @ CHECK-NEXT: }
106 @ CHECK-NEXT: Symbol {
107 @ CHECK-NEXT: Name: .bss (0)
108 @ CHECK-NEXT: Value: 0x0
109 @ CHECK-NEXT: Size: 0
110 @ CHECK-NEXT: Binding: Local (0x0)
111 @ CHECK-NEXT: Type: Section (0x3)
112 @ CHECK-NEXT: Other: 0
113 @ CHECK-NEXT: Section: .bss (0x4)
114 @ CHECK-NEXT: }
115 @ CHECK-NEXT: Symbol {
116 @ CHECK-NEXT: Name: g1@@zed (88)
117 @ CHECK-NEXT: Value: 0x14
118 @ CHECK-NEXT: Size: 0
119 @ CHECK-NEXT: Binding: Global (0x1)
120 @ CHECK-NEXT: Type: None (0x0)
121 @ CHECK-NEXT: Other: 0
122 @ CHECK-NEXT: Section: .text (0x1)
123 @ CHECK-NEXT: }
124 @ CHECK-NEXT: Symbol {
125 @ CHECK-NEXT: Name: global1 (80)
126 @ CHECK-NEXT: Value: 0x14
127 @ CHECK-NEXT: Size: 0
128 @ CHECK-NEXT: Binding: Global (0x1)
129 @ CHECK-NEXT: Type: None (0x0)
130 @ CHECK-NEXT: Other: 0
131 @ CHECK-NEXT: Section: .text (0x1)
132 @ CHECK-NEXT: }
133 @ CHECK-NEXT: Symbol {
134 @ CHECK-NEXT: Name: bar2@zed (37)
135 @ CHECK-NEXT: Value: 0x0
136 @ CHECK-NEXT: Size: 0
137 @ CHECK-NEXT: Binding: Global (0x1)
138 @ CHECK-NEXT: Type: None (0x0)
139 @ CHECK-NEXT: Other: 0
140 @ CHECK-NEXT: Section: (0x0)
141 @ CHECK-NEXT: }
142 @ CHECK-NEXT: Symbol {
143 @ CHECK-NEXT: Name: bar6@zed (66)
144 @ CHECK-NEXT: Value: 0x0
145 @ CHECK-NEXT: Size: 0
146 @ CHECK-NEXT: Binding: Global (0x1)
147 @ CHECK-NEXT: Type: None (0x0)
148 @ CHECK-NEXT: Other: 0
149 @ CHECK-NEXT: Section: (0x0)
150 @ CHECK-NEXT: }
151 @ CHECK-NEXT: ]
77 .long bar@got to parse this as a comment
88 .long baz@got
99 add r0, r0@ignore this extra junk
10
11 @ the symver directive should allow @ in the second symbol name
12 defined1:
13 defined2:
14 defined3:
15 bar:
16 .symver defined1, bar1@zed
17 .symver defined2, bar3@@zed
18 .symver defined3, bar5@@@zed
19
20 far:
21 .long baz@got
1022
1123 @CHECK-LABEL: foo:
1224 @CHECK: bl boo
2032 @CHECK: add r0, r0
2133 @CHECK-NOT: @
2234
35 @CHECK-LABEL: bar:
36 @CHECK: bar1@zed = defined1
37 @CHECK: bar3@@zed = defined2
38 @CHECK: bar5@@@zed = defined3
39
40 @ Make sure we did not mess up the parser state and it still lexes
41 @ comments correctly by excluding the @ in normal symbols
42 @CHECK-LABEL: far:
43 @CHECK: .long baz
44 @CHECK-NOT: @
45
2346 @ERROR-NOT: error: