llvm.org GIT mirror llvm / c24a374
Implement AsmParser for ARM unwind directives. This commit implements the AsmParser for fnstart, fnend, cantunwind, personality, handlerdata, pad, setfp, save, and vsave directives. This commit fixes some minor issue in the ARMELFStreamer: * The switch back to corresponding section after the .fnend directive. * Emit the unwind opcode while processing .fnend directive if there is no .handlerdata directive. * Emit the unwind opcode to .ARM.extab while processing .handlerdata even if .personality directive does not exist. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@181603 91177308-0d34-0410-b5e6-96231b3b80d8 Logan Chien 7 years ago
24 changed file(s) with 2588 addition(s) and 28 deletion(s). Raw diff Collapse all Expand all
4848 MCAsmParser &Parser;
4949 const MCRegisterInfo *MRI;
5050
51 // Unwind directives state
52 SMLoc FnStartLoc;
53 SMLoc CantUnwindLoc;
54 SMLoc PersonalityLoc;
55 SMLoc HandlerDataLoc;
56 int FPReg;
57 void resetUnwindDirectiveParserState() {
58 FnStartLoc = SMLoc();
59 CantUnwindLoc = SMLoc();
60 PersonalityLoc = SMLoc();
61 HandlerDataLoc = SMLoc();
62 FPReg = -1;
63 }
64
5165 // Map of register aliases registers via the .req directive.
5266 StringMap RegisterReqs;
5367
112126 bool parseDirectiveUnreq(SMLoc L);
113127 bool parseDirectiveArch(SMLoc L);
114128 bool parseDirectiveEabiAttr(SMLoc L);
129 bool parseDirectiveFnStart(SMLoc L);
130 bool parseDirectiveFnEnd(SMLoc L);
131 bool parseDirectiveCantUnwind(SMLoc L);
132 bool parseDirectivePersonality(SMLoc L);
133 bool parseDirectiveHandlerData(SMLoc L);
134 bool parseDirectiveSetFP(SMLoc L);
135 bool parseDirectivePad(SMLoc L);
136 bool parseDirectiveRegSave(SMLoc L, bool IsVector);
115137
116138 StringRef splitMnemonic(StringRef Mnemonic, unsigned &PredicationCode,
117139 bool &CarrySetting, unsigned &ProcessorIMod,
241263 };
242264
243265 ARMAsmParser(MCSubtargetInfo &_STI, MCAsmParser &_Parser)
244 : MCTargetAsmParser(), STI(_STI), Parser(_Parser) {
266 : MCTargetAsmParser(), STI(_STI), Parser(_Parser), FPReg(-1) {
245267 MCAsmParserExtension::Initialize(_Parser);
246268
247269 // Cache the MCRegisterInfo.
76577679 return parseDirectiveArch(DirectiveID.getLoc());
76587680 else if (IDVal == ".eabi_attribute")
76597681 return parseDirectiveEabiAttr(DirectiveID.getLoc());
7682 else if (IDVal == ".fnstart")
7683 return parseDirectiveFnStart(DirectiveID.getLoc());
7684 else if (IDVal == ".fnend")
7685 return parseDirectiveFnEnd(DirectiveID.getLoc());
7686 else if (IDVal == ".cantunwind")
7687 return parseDirectiveCantUnwind(DirectiveID.getLoc());
7688 else if (IDVal == ".personality")
7689 return parseDirectivePersonality(DirectiveID.getLoc());
7690 else if (IDVal == ".handlerdata")
7691 return parseDirectiveHandlerData(DirectiveID.getLoc());
7692 else if (IDVal == ".setfp")
7693 return parseDirectiveSetFP(DirectiveID.getLoc());
7694 else if (IDVal == ".pad")
7695 return parseDirectivePad(DirectiveID.getLoc());
7696 else if (IDVal == ".save")
7697 return parseDirectiveRegSave(DirectiveID.getLoc(), false);
7698 else if (IDVal == ".vsave")
7699 return parseDirectiveRegSave(DirectiveID.getLoc(), true);
76607700 return true;
76617701 }
76627702
78557895 /// ::= .eabi_attribute int, int
78567896 bool ARMAsmParser::parseDirectiveEabiAttr(SMLoc L) {
78577897 return true;
7898 }
7899
7900 /// parseDirectiveFnStart
7901 /// ::= .fnstart
7902 bool ARMAsmParser::parseDirectiveFnStart(SMLoc L) {
7903 if (FnStartLoc.isValid()) {
7904 Error(L, ".fnstart starts before the end of previous one");
7905 Error(FnStartLoc, "previous .fnstart starts here");
7906 return true;
7907 }
7908
7909 FnStartLoc = L;
7910 getParser().getStreamer().EmitFnStart();
7911 return false;
7912 }
7913
7914 /// parseDirectiveFnEnd
7915 /// ::= .fnend
7916 bool ARMAsmParser::parseDirectiveFnEnd(SMLoc L) {
7917 // Check the ordering of unwind directives
7918 if (!FnStartLoc.isValid())
7919 return Error(L, ".fnstart must precede .fnend directive");
7920
7921 // Reset the unwind directives parser state
7922 resetUnwindDirectiveParserState();
7923
7924 getParser().getStreamer().EmitFnEnd();
7925 return false;
7926 }
7927
7928 /// parseDirectiveCantUnwind
7929 /// ::= .cantunwind
7930 bool ARMAsmParser::parseDirectiveCantUnwind(SMLoc L) {
7931 // Check the ordering of unwind directives
7932 CantUnwindLoc = L;
7933 if (!FnStartLoc.isValid())
7934 return Error(L, ".fnstart must precede .cantunwind directive");
7935 if (HandlerDataLoc.isValid()) {
7936 Error(L, ".cantunwind can't be used with .handlerdata directive");
7937 Error(HandlerDataLoc, ".handlerdata was specified here");
7938 return true;
7939 }
7940 if (PersonalityLoc.isValid()) {
7941 Error(L, ".cantunwind can't be used with .personality directive");
7942 Error(PersonalityLoc, ".personality was specified here");
7943 return true;
7944 }
7945
7946 getParser().getStreamer().EmitCantUnwind();
7947 return false;
7948 }
7949
7950 /// parseDirectivePersonality
7951 /// ::= .personality name
7952 bool ARMAsmParser::parseDirectivePersonality(SMLoc L) {
7953 // Check the ordering of unwind directives
7954 PersonalityLoc = L;
7955 if (!FnStartLoc.isValid())
7956 return Error(L, ".fnstart must precede .personality directive");
7957 if (CantUnwindLoc.isValid()) {
7958 Error(L, ".personality can't be used with .cantunwind directive");
7959 Error(CantUnwindLoc, ".cantunwind was specified here");
7960 return true;
7961 }
7962 if (HandlerDataLoc.isValid()) {
7963 Error(L, ".personality must precede .handlerdata directive");
7964 Error(HandlerDataLoc, ".handlerdata was specified here");
7965 return true;
7966 }
7967
7968 // Parse the name of the personality routine
7969 if (Parser.getTok().isNot(AsmToken::Identifier)) {
7970 Parser.eatToEndOfStatement();
7971 return Error(L, "unexpected input in .personality directive.");
7972 }
7973 StringRef Name(Parser.getTok().getIdentifier());
7974 Parser.Lex();
7975
7976 MCSymbol *PR = getParser().getContext().GetOrCreateSymbol(Name);
7977 getParser().getStreamer().EmitPersonality(PR);
7978 return false;
7979 }
7980
7981 /// parseDirectiveHandlerData
7982 /// ::= .handlerdata
7983 bool ARMAsmParser::parseDirectiveHandlerData(SMLoc L) {
7984 // Check the ordering of unwind directives
7985 HandlerDataLoc = L;
7986 if (!FnStartLoc.isValid())
7987 return Error(L, ".fnstart must precede .personality directive");
7988 if (CantUnwindLoc.isValid()) {
7989 Error(L, ".handlerdata can't be used with .cantunwind directive");
7990 Error(CantUnwindLoc, ".cantunwind was specified here");
7991 return true;
7992 }
7993
7994 getParser().getStreamer().EmitHandlerData();
7995 return false;
7996 }
7997
7998 /// parseDirectiveSetFP
7999 /// ::= .setfp fpreg, spreg [, offset]
8000 bool ARMAsmParser::parseDirectiveSetFP(SMLoc L) {
8001 // Check the ordering of unwind directives
8002 if (!FnStartLoc.isValid())
8003 return Error(L, ".fnstart must precede .setfp directive");
8004 if (HandlerDataLoc.isValid())
8005 return Error(L, ".setfp must precede .handlerdata directive");
8006
8007 // Parse fpreg
8008 SMLoc NewFPRegLoc = Parser.getTok().getLoc();
8009 int NewFPReg = tryParseRegister();
8010 if (NewFPReg == -1)
8011 return Error(NewFPRegLoc, "frame pointer register expected");
8012
8013 // Consume comma
8014 if (!Parser.getTok().is(AsmToken::Comma))
8015 return Error(Parser.getTok().getLoc(), "comma expected");
8016 Parser.Lex(); // skip comma
8017
8018 // Parse spreg
8019 SMLoc NewSPRegLoc = Parser.getTok().getLoc();
8020 int NewSPReg = tryParseRegister();
8021 if (NewSPReg == -1)
8022 return Error(NewSPRegLoc, "stack pointer register expected");
8023
8024 if (NewSPReg != ARM::SP && NewSPReg != FPReg)
8025 return Error(NewSPRegLoc,
8026 "register should be either $sp or the latest fp register");
8027
8028 // Update the frame pointer register
8029 FPReg = NewFPReg;
8030
8031 // Parse offset
8032 int64_t Offset = 0;
8033 if (Parser.getTok().is(AsmToken::Comma)) {
8034 Parser.Lex(); // skip comma
8035
8036 if (Parser.getTok().isNot(AsmToken::Hash) &&
8037 Parser.getTok().isNot(AsmToken::Dollar)) {
8038 return Error(Parser.getTok().getLoc(), "'#' expected");
8039 }
8040 Parser.Lex(); // skip hash token.
8041
8042 const MCExpr *OffsetExpr;
8043 SMLoc ExLoc = Parser.getTok().getLoc();
8044 SMLoc EndLoc;
8045 if (getParser().parseExpression(OffsetExpr, EndLoc))
8046 return Error(ExLoc, "malformed setfp offset");
8047 const MCConstantExpr *CE = dyn_cast(OffsetExpr);
8048 if (!CE)
8049 return Error(ExLoc, "setfp offset must be an immediate");
8050
8051 Offset = CE->getValue();
8052 }
8053
8054 getParser().getStreamer().EmitSetFP(static_cast(NewFPReg),
8055 static_cast(NewSPReg),
8056 Offset);
8057 return false;
8058 }
8059
8060 /// parseDirective
8061 /// ::= .pad offset
8062 bool ARMAsmParser::parseDirectivePad(SMLoc L) {
8063 // Check the ordering of unwind directives
8064 if (!FnStartLoc.isValid())
8065 return Error(L, ".fnstart must precede .pad directive");
8066 if (HandlerDataLoc.isValid())
8067 return Error(L, ".pad must precede .handlerdata directive");
8068
8069 // Parse the offset
8070 if (Parser.getTok().isNot(AsmToken::Hash) &&
8071 Parser.getTok().isNot(AsmToken::Dollar)) {
8072 return Error(Parser.getTok().getLoc(), "'#' expected");
8073 }
8074 Parser.Lex(); // skip hash token.
8075
8076 const MCExpr *OffsetExpr;
8077 SMLoc ExLoc = Parser.getTok().getLoc();
8078 SMLoc EndLoc;
8079 if (getParser().parseExpression(OffsetExpr, EndLoc))
8080 return Error(ExLoc, "malformed pad offset");
8081 const MCConstantExpr *CE = dyn_cast(OffsetExpr);
8082 if (!CE)
8083 return Error(ExLoc, "pad offset must be an immediate");
8084
8085 getParser().getStreamer().EmitPad(CE->getValue());
8086 return false;
8087 }
8088
8089 /// parseDirectiveRegSave
8090 /// ::= .save { registers }
8091 /// ::= .vsave { registers }
8092 bool ARMAsmParser::parseDirectiveRegSave(SMLoc L, bool IsVector) {
8093 // Check the ordering of unwind directives
8094 if (!FnStartLoc.isValid())
8095 return Error(L, ".fnstart must precede .save or .vsave directives");
8096 if (HandlerDataLoc.isValid())
8097 return Error(L, ".save or .vsave must precede .handlerdata directive");
8098
8099 // Parse the register list
8100 SmallVector Operands;
8101 if (parseRegisterList(Operands))
8102 return true;
8103 ARMOperand *Op = (ARMOperand*)Operands[0];
8104 if (!IsVector && !Op->isRegList())
8105 return Error(L, ".save expects GPR registers");
8106 if (IsVector && !Op->isDPRRegList())
8107 return Error(L, ".vsave expects DPR registers");
8108
8109 getParser().getStreamer().EmitRegSave(Op->getRegList(), IsVector);
8110 return false;
78588111 }
78598112
78608113 /// Force static initialization.
203203
204204 void EmitPersonalityFixup(StringRef Name);
205205 void CollectUnwindOpcodes();
206 void FlushUnwindOpcodes(bool AllowCompactModel0);
206207
207208 void SwitchToEHSection(const char *Prefix, unsigned Type, unsigned Flags,
208209 SectionKind Kind, const MCSymbol &Fn);
332333 assert(FnStart && ".fnstart must preceeds .fnend");
333334
334335 // Emit unwind opcodes if there is no .handlerdata directive
335 if (!ExTab && !CantUnwind) {
336 CollectUnwindOpcodes();
337
338 unsigned PersonalityIndex = UnwindOpAsm.getPersonalityIndex();
339 if (PersonalityIndex == AEABI_UNWIND_CPP_PR1 ||
340 PersonalityIndex == AEABI_UNWIND_CPP_PR2) {
341 // For the __aeabi_unwind_cpp_pr1 and __aeabi_unwind_cpp_pr2, we have to
342 // emit the unwind opcodes in the corresponding ".ARM.extab" section, and
343 // then emit a reference to these unwind opcodes in the second word of
344 // the exception index table entry.
345 SwitchToExTabSection(*FnStart);
346 ExTab = getContext().CreateTempSymbol();
347 EmitLabel(ExTab);
348 EmitBytes(UnwindOpAsm.data(), 0);
349 }
350 }
336 if (!ExTab && !CantUnwind)
337 FlushUnwindOpcodes(true);
351338
352339 // Emit the exception index table entry
353340 SwitchToExIdxSection(*FnStart);
383370 EmitBytes(UnwindOpAsm.data(), 0);
384371 }
385372
373 // Switch to the section containing FnStart
374 SwitchSection(&FnStart->getSection());
375
386376 // Clean exception handling frame information
387377 Reset();
388378 }
391381 CantUnwind = true;
392382 }
393383
394 void ARMELFStreamer::EmitHandlerData() {
384 void ARMELFStreamer::FlushUnwindOpcodes(bool AllowCompactModel0) {
385 // Collect and finalize the unwind opcodes
386 CollectUnwindOpcodes();
387
388 // For compact model 0, we have to emit the unwind opcodes in the .ARM.exidx
389 // section. Thus, we don't have to create an entry in the .ARM.extab
390 // section.
391 if (AllowCompactModel0 &&
392 UnwindOpAsm.getPersonalityIndex() == AEABI_UNWIND_CPP_PR0)
393 return;
394
395 // Switch to .ARM.extab section.
395396 SwitchToExTabSection(*FnStart);
396397
397398 // Create .ARM.extab label for offset in .ARM.exidx
399400 ExTab = getContext().CreateTempSymbol();
400401 EmitLabel(ExTab);
401402
402 // Emit Personality
403 assert(Personality && ".personality directive must preceed .handlerdata");
404
405 const MCSymbolRefExpr *PersonalityRef =
406 MCSymbolRefExpr::Create(Personality,
407 MCSymbolRefExpr::VK_ARM_PREL31,
408 getContext());
409
410 EmitValue(PersonalityRef, 4, 0);
403 // Emit personality
404 if (Personality) {
405 const MCSymbolRefExpr *PersonalityRef =
406 MCSymbolRefExpr::Create(Personality,
407 MCSymbolRefExpr::VK_ARM_PREL31,
408 getContext());
409
410 EmitValue(PersonalityRef, 4, 0);
411 }
411412
412413 // Emit unwind opcodes
413 CollectUnwindOpcodes();
414414 EmitBytes(UnwindOpAsm.data(), 0);
415 }
416
417 void ARMELFStreamer::EmitHandlerData() {
418 FlushUnwindOpcodes(false);
415419 }
416420
417421 void ARMELFStreamer::EmitPersonality(const MCSymbol *Per) {
0 @ RUN: llvm-mc %s -triple=armv7-unknown-linux-gnueabi -filetype=obj -o - \
1 @ RUN: | llvm-readobj -s -sd -sr | FileCheck %s
2
3 @ Check the compact pr0 model
4
5 .syntax unified
6
7 .section .TEST1
8 .globl func1
9 .align 2
10 .type func1,%function
11 func1:
12 .fnstart
13 .save {r11, lr}
14 push {r11, lr}
15 .setfp r11, sp
16 mov r11, sp
17 pop {r11, lr}
18 mov pc, lr
19 .fnend
20
21 .section .TEST2
22 .globl func2
23 .align 2
24 .type func2,%function
25 func2:
26 .fnstart
27 .save {r11, lr}
28 push {r11, lr}
29 pop {r11, pc}
30 .fnend
31
32
33
34 @-------------------------------------------------------------------------------
35 @ Check .TEST1 section
36 @-------------------------------------------------------------------------------
37 @ CHECK: Sections [
38 @ CHECK: Section {
39 @ CHECK: Name: .TEST1
40 @ CHECK: SectionData (
41 @ CHECK: 0000: 00482DE9 0DB0A0E1 0048BDE8 0EF0A0E1 |.H-......H......|
42 @ CHECK: )
43 @ CHECK: }
44
45
46 @-------------------------------------------------------------------------------
47 @ Check .ARM.exidx.TEST1 section
48 @-------------------------------------------------------------------------------
49 @ CHECK: Section {
50 @ CHECK: Name: .ARM.exidx.TEST1
51 @-------------------------------------------------------------------------------
52 @ The first word should be relocated to .TEST1 section. Besides, there is
53 @ another relocation entry for __aeabi_unwind_cpp_pr0, so that the linker
54 @ will keep __aeabi_unwind_cpp_pr0.
55 @-------------------------------------------------------------------------------
56 @ CHECK: Relocations [
57 @ CHECK: 0x0 R_ARM_PREL31 .TEST1 0x0
58 @ CHECK: 0x0 R_ARM_NONE __aeabi_unwind_cpp_pr0 0x0
59 @ CHECK: ]
60 @-------------------------------------------------------------------------------
61 @ 0x80 = Compact model 0, personality routine: __aeabi_unwind_cpp_pr0
62 @ 0x9B = $sp can be found in $r11
63 @ 0x8480 = pop {r11, r14}
64 @-------------------------------------------------------------------------------
65 @ CHECK: SectionData (
66 @ CHECK: 0000: 00000000 80849B80 |........|
67 @ CHECK: )
68 @ CHECK: }
69
70
71 @-------------------------------------------------------------------------------
72 @ Check .TEST2 section
73 @-------------------------------------------------------------------------------
74 @ CHECK: Section {
75 @ CHECK: Name: .TEST2
76 @ CHECK: SectionData (
77 @ CHECK: 0000: 00482DE9 0088BDE8 |.H-.....|
78 @ CHECK: )
79 @ CHECK: }
80 @-------------------------------------------------------------------------------
81 @ Check .ARM.exidx.TEST1 section
82 @-------------------------------------------------------------------------------
83 @ CHECK: Section {
84 @ CHECK: Name: .ARM.exidx.TEST2
85 @-------------------------------------------------------------------------------
86 @ The first word should be relocated to .TEST2 section. Besides, there is
87 @ another relocation entry for __aeabi_unwind_cpp_pr0, so that the linker
88 @ will keep __aeabi_unwind_cpp_pr0.
89 @-------------------------------------------------------------------------------
90 @ CHECK: Relocations [
91 @ CHECK: 0x0 R_ARM_PREL31 .TEST2 0x0
92 @ CHECK: 0x0 R_ARM_NONE __aeabi_unwind_cpp_pr0 0x0
93 @ CHECK: ]
94 @-------------------------------------------------------------------------------
95 @ 0x80 = Compact model 0, personality routine: __aeabi_unwind_cpp_pr0
96 @ 0x8480 = pop {r11, r14}
97 @ 0xB0 = finish
98 @-------------------------------------------------------------------------------
99 @ CHECK: SectionData (
100 @ CHECK: 0000: 00000000 B0808480 |........|
101 @ CHECK: )
102 @ CHECK: }
103 @ CHECK: ]
0 @ RUN: llvm-mc %s -triple=armv7-unknown-linux-gnueabi -filetype=obj -o - \
1 @ RUN: | llvm-readobj -s -sd -sr | FileCheck %s
2
3 @ Check the compact pr1 model
4
5 .syntax unified
6
7 .section .TEST1
8 .globl func1
9 .align 2
10 .type func1,%function
11 func1:
12 .fnstart
13 .save {r4, r5, r11, lr}
14 push {r4, r5, r11, lr}
15 add r0, r1, r0
16 .setfp r11, sp, #8
17 add r11, sp, #8
18 pop {r4, r5, r11, pc}
19 .fnend
20
21
22
23 @-------------------------------------------------------------------------------
24 @ Check .TEST1 section
25 @-------------------------------------------------------------------------------
26 @ CHECK: Sections [
27 @ CHECK: Section {
28 @ CHECK: Name: .TEST1
29 @ CHECK: SectionData (
30 @ CHECK: 0000: 30482DE9 000081E0 08B08DE2 3088BDE8 |0H-.........0...|
31 @ CHECK: )
32 @ CHECK: }
33
34
35 @-------------------------------------------------------------------------------
36 @ Check .ARM.extab.TEST1 section
37 @-------------------------------------------------------------------------------
38 @ CHECK: Section {
39 @ CHECK: Name: .ARM.extab.TEST1
40 @-------------------------------------------------------------------------------
41 @ 0x81 = Compact model 1, personality routine: __aeabi_unwind_cpp_pr1
42 @ 0x9B = $sp can be found in $r11
43 @ 0x41 = $sp = $sp - 8
44 @ 0x8483 = pop {r4, r5, r11, r14}
45 @ 0xB0 = finish
46 @-------------------------------------------------------------------------------
47 @ CHECK: SectionData (
48 @ CHECK: 0000: 419B0181 B0B08384 |A.......|
49 @ CHECK: )
50 @ CHECK: }
51
52
53 @-------------------------------------------------------------------------------
54 @ Check .ARM.exidx.TEST1 section
55 @-------------------------------------------------------------------------------
56 @ CHECK: Section {
57 @ CHECK: Name: .ARM.exidx.TEST1
58 @-------------------------------------------------------------------------------
59 @ The first word should be relocated to .TEST1 section, and the second word
60 @ should be relocated to .ARM.extab.TEST1 section. Besides, there is
61 @ another relocation entry for __aeabi_unwind_cpp_pr1, so that the linker
62 @ will keep __aeabi_unwind_cpp_pr1.
63 @-------------------------------------------------------------------------------
64 @ CHECK: Relocations [
65 @ CHECK: 0x0 R_ARM_PREL31 .TEST1 0x0
66 @ CHECK: 0x0 R_ARM_NONE __aeabi_unwind_cpp_pr1 0x0
67 @ CHECK: 0x4 R_ARM_PREL31 .ARM.extab.TEST1 0x0
68 @ CHECK: ]
69 @ CHECK: SectionData (
70 @ CHECK: 0000: 00000000 00000000 |........|
71 @ CHECK: )
72 @ CHECK: }
73 @ CHECK: ]
0 @ RUN: not llvm-mc -triple=armv7-unknown-linux-gnueabi < %s 2> %t
1 @ RUN: FileCheck < %t %s
2
3 @ Check the diagnostics for .cantunwind, .handlerdata, and .personality
4
5 @ .cantunwind directive can't be used with .handlerdata directive nor
6 @ .personality directive. This test case check for the diagnostics for
7 @ the conflicts.
8
9
10 .syntax unified
11 .text
12
13 @-------------------------------------------------------------------------------
14 @ TEST1: cantunwind + personality
15 @-------------------------------------------------------------------------------
16 .globl func1
17 .align 2
18 .type func1,%function
19 .fnstart
20 func1:
21 .cantunwind
22 .personality __gxx_personality_v0
23 @ CHECK: error: .personality can't be used with .cantunwind directive
24 @ CEHCK: .personality __gxx_personality_v0
25 @ CHECK: ^
26 @ CHECK: error: .cantunwind was specified here
27 @ CHECK: .cantunwind
28 @ CHECK: ^
29 .fnend
30
31
32
33 @-------------------------------------------------------------------------------
34 @ TEST2: cantunwind + handlerdata
35 @-------------------------------------------------------------------------------
36 .globl func2
37 .align 2
38 .type func2,%function
39 .fnstart
40 func2:
41 .cantunwind
42 .handlerdata
43 @ CHECK: error: .handlerdata can't be used with .cantunwind directive
44 @ CEHCK: .handlerdata
45 @ CHECK: ^
46 @ CHECK: error: .cantunwind was specified here
47 @ CHECK: .cantunwind
48 @ CHECK: ^
49 .fnend
50
51
52
53 @-------------------------------------------------------------------------------
54 @ TEST3: personality + cantunwind
55 @-------------------------------------------------------------------------------
56 .globl func3
57 .align 2
58 .type func3,%function
59 .fnstart
60 func3:
61 .personality __gxx_personality_v0
62 .cantunwind
63 @ CHECK: error: .cantunwind can't be used with .personality directive
64 @ CEHCK: .cantunwind
65 @ CHECK: ^
66 @ CHECK: error: .personality was specified here
67 @ CHECK: .personality __gxx_personality_v0
68 @ CHECK: ^
69 .fnend
70
71
72
73 @-------------------------------------------------------------------------------
74 @ TEST4: handlerdata + cantunwind
75 @-------------------------------------------------------------------------------
76 .globl func4
77 .align 2
78 .type func4,%function
79 .fnstart
80 func4:
81 .handlerdata
82 .cantunwind
83 @ CHECK: error: .cantunwind can't be used with .handlerdata directive
84 @ CEHCK: .cantunwind
85 @ CHECK: ^
86 @ CHECK: error: .handlerdata was specified here
87 @ CHECK: .handlerdata
88 @ CHECK: ^
89 .fnend
90
91
92
93 @-------------------------------------------------------------------------------
94 @ TEST5: cantunwind + fnstart
95 @-------------------------------------------------------------------------------
96 .globl func5
97 .align 2
98 .type func5,%function
99 .cantunwind
100 @ CHECK: error: .fnstart must precede .cantunwind directive
101 @ CHECK: .cantunwind
102 @ CHECK: ^
103 .fnstart
104 func5:
105 .fnend
0 @ RUN: llvm-mc %s -triple=armv7-unknown-linux-gnueabi -filetype=obj -o - \
1 @ RUN: | llvm-readobj -s -sd -sr | FileCheck %s
2
3 @ Check the .cantunwind directive
4
5 @ When a function contains a .cantunwind directive, we should create an entry
6 @ in corresponding .ARM.exidx, and its second word should be EXIDX_CANTUNWIND.
7
8 .syntax unified
9
10 .text
11 .globl func1
12 .align 2
13 .type func1,%function
14 .fnstart
15 func1:
16 bx lr
17 .cantunwind
18 .fnend
19
20
21
22 @-------------------------------------------------------------------------------
23 @ Check .text section
24 @-------------------------------------------------------------------------------
25 @ CHECK: Sections [
26 @ CHECK: Section {
27 @ CHECK: Name: .text
28 @ CHECK: SectionData (
29 @ CHECK: 0000: 1EFF2FE1 |../.|
30 @ CHECK: )
31 @ CHECK: }
32
33
34 @-------------------------------------------------------------------------------
35 @ Check .ARM.exidx section
36 @-------------------------------------------------------------------------------
37 @ CHECK: Section {
38 @ CHECK: Name: .ARM.exidx
39 @ CHECK: Relocations [
40 @ CHECK: 0x0 R_ARM_PREL31 .text 0x0
41 @ CHECK: ]
42 @-------------------------------------------------------------------------------
43 @ The first word should be the offset to .text.
44 @ The second word should be EXIDX_CANTUNWIND (01000000).
45 @-------------------------------------------------------------------------------
46 @ CHECK: SectionData (
47 @ CHECK: 0000: 00000000 01000000 |........|
48 @ CHECK: )
49 @ CHECK: }
50 @ CHECK: ]
0 @ RUN: llvm-mc %s -triple=armv7-unknown-linux-gnueabi \
1 @ RUN: -filetype=obj -o /dev/null 2>&1 | FileCheck %s
2
3 @ Check the diagnostics for mismatched .fnend directive
4
5
6 .syntax unified
7 .text
8
9 .globl func1
10 .align 2
11 .type func1,%function
12 func1:
13 .fnend
14 @ CHECK: error: .fnstart must precede .fnend directive
15 @ CHECK: .fnend
16 @ CHECK: ^
0 @ RUN: llvm-mc %s -triple=armv7-unknown-linux-gnueabi \
1 @ RUN: -filetype=obj -o /dev/null 2>&1 | FileCheck %s
2
3 @ Check the diagnostics for the mismatched .fnstart directives.
4
5 @ There should be some diagnostics when the previous .fnstart is not closed
6 @ by the .fnend directive.
7
8
9 .syntax unified
10 .text
11
12 .globl func1
13 .align 2
14 .type func1,%function
15 .fnstart
16 func1:
17 @ Intentionally miss the .fnend directive
18
19 .globl func2
20 .align 2
21 .type func2,%function
22 .fnstart
23 @ CHECK: error: .fnstart starts before the end of previous one
24 @ CHECK: .fnstart
25 @ CHECK: ^
26 @ CHECK: error: previous .fnstart starts here
27 @ CHECK: .fnstart
28 @ CHECK: ^
29 func2:
30 .fnend
0 @ RUN: llvm-mc %s -triple=armv7-unknown-linux-gnueabi -filetype=obj -o - \
1 @ RUN: | llvm-readobj -s -sd -sr | FileCheck %s
2
3 @ Check the .handlerdata directive (without .personality directive)
4
5 .syntax unified
6
7 @-------------------------------------------------------------------------------
8 @ TEST1
9 @-------------------------------------------------------------------------------
10 .section .TEST1
11 .globl func1
12 .align 2
13 .type func1,%function
14 .fnstart
15 func1:
16 bx lr
17 .handlerdata
18 .fnend
19
20
21 @ CHECK:Section {
22 @ CHECK: Name: .TEST1
23 @ CHECK: SectionData (
24 @ CHECK: 0000: 1EFF2FE1 |../.|
25 @ CHECK: )
26 @ CHECK:}
27
28 @ CHECK:Section {
29 @ CHECK: Name: .ARM.extab.TEST1
30 @ CHECK: SectionData (
31 @ CHECK: 0000: B0B0B080 |....|
32 @ CHECK: )
33 @ CHECK:}
34
35 @ CHECK:Section {
36 @ CHECK: Name: .ARM.exidx.TEST1
37 @-------------------------------------------------------------------------------
38 @ We should see a relocation entry to __aeabi_unwind_cpp_pr0, so that the
39 @ linker can keep __aeabi_unwind_cpp_pr0.
40 @-------------------------------------------------------------------------------
41 @ CHECK: Relocations [
42 @ CHECK: 0x0 R_ARM_PREL31 .TEST1 0x0
43 @ CHECK: 0x0 R_ARM_NONE __aeabi_unwind_cpp_pr0 0x0
44 @ CHECK: 0x4 R_ARM_PREL31 .ARM.extab.TEST1 0x0
45 @ CHECK: ]
46 @ CHECK: SectionData (
47 @ CHECK: 0000: 00000000 00000000 |........|
48 @ CHECK: )
49 @ CHECK:}
50
51
52
53
54 @-------------------------------------------------------------------------------
55 @ TEST2
56 @-------------------------------------------------------------------------------
57 .section .TEST2
58 .globl func2
59 .align 2
60 .type func2,%function
61 .fnstart
62 func2:
63 @-------------------------------------------------------------------------------
64 @ Use a lot of unwind opcdes to get __aeabi_unwind_cpp_pr1.
65 @-------------------------------------------------------------------------------
66 .save {r4, r5, r6, r7, r8, r9, r10, r11, r12}
67 push {r4, r5, r6, r7, r8, r9, r10, r11, r12}
68 pop {r4, r5, r6, r7, r8, r9, r10, r11, r12}
69 .pad #0x240
70 sub sp, sp, #0x240
71 add sp, sp, #0x240
72 bx lr
73 .handlerdata
74 .fnend
75
76
77
78 @ CHECK:Section {
79 @ CHECK: Name: .TEST2
80 @ CHECK: SectionData (
81 @ CHECK: 0000: F01F2DE9 F01FBDE8 09DD4DE2 09DD8DE2 |..-.......M.....|
82 @ CHECK: 0010: 1EFF2FE1 |../.|
83 @ CHECK: )
84 @ CHECK:}
85
86 @ CHECK:Section {
87 @ CHECK: Name: .ARM.extab.TEST2
88 @ CHECK: SectionData (
89 @ CHECK: 0000: 0FB20181 B0B0FF81 |........|
90 @ CHECK: )
91 @ CHECK:}
92
93 @ CHECK:Section {
94 @ CHECK: Name: .ARM.exidx.TEST2
95 @-------------------------------------------------------------------------------
96 @ We should see a relocation entry to __aeabi_unwind_cpp_pr0, so that the
97 @ linker can keep __aeabi_unwind_cpp_pr0.
98 @-------------------------------------------------------------------------------
99 @ CHECK: Relocations [
100 @ CHECK: 0x0 R_ARM_PREL31 .TEST2 0x0
101 @ CHECK: 0x0 R_ARM_NONE __aeabi_unwind_cpp_pr1 0x0
102 @ CHECK: 0x4 R_ARM_PREL31 .ARM.extab.TEST2 0x0
103 @ CHECK: ]
104 @ CHECK: SectionData (
105 @ CHECK: 0000: 00000000 00000000 |........|
106 @ CHECK: )
107 @ CHECK:}
0 @ RUN: not llvm-mc -triple=armv7-unknown-linux-gnueabi < %s 2> %t
1 @ RUN: FileCheck --check-prefix=CHECK < %t %s
2
3 @ Check the diagnostics for .pad directive.
4
5
6 .syntax unified
7 .text
8
9 @-------------------------------------------------------------------------------
10 @ TEST1: .pad before .fnstart
11 @-------------------------------------------------------------------------------
12 .globl func1
13 .align 2
14 .type func1,%function
15 .pad #0
16 @ CHECK: error: .fnstart must precede .pad directive
17 @ CHECK: .pad #0
18 @ CHECK: ^
19 .fnstart
20 func1:
21 .fnend
22
23
24
25 @-------------------------------------------------------------------------------
26 @ TEST2: .pad after .handlerdata
27 @-------------------------------------------------------------------------------
28 .globl func2
29 .align 2
30 .type func2,%function
31 .fnstart
32 func2:
33 .handlerdata
34 .pad #0
35 @ CHECK: error: .pad must precede .handlerdata directive
36 @ CHECK: .pad #0
37 @ CHECK: ^
38 .fnend
0 @ RUN: llvm-mc %s -triple=armv7-unknown-linux-gnueabi -filetype=obj -o - \
1 @ RUN: | llvm-readobj -s -sd | FileCheck %s
2
3 @ Check for different stack pointer offsets.
4
5 @ The .pad directive will track the stack pointer offsets. There are several
6 @ ways to encode the stack offsets. We have to test:
7 @
8 @ offset < 0x00
9 @ offset == 0x00
10 @ 0x04 <= offset <= 0x100
11 @ 0x104 <= offset <= 0x200
12 @ 0x204 <= offset
13
14
15 .syntax unified
16
17 @-------------------------------------------------------------------------------
18 @ TEST1
19 @-------------------------------------------------------------------------------
20 .section .TEST1
21 .globl func1
22 .align 2
23 .type func1,%function
24 .fnstart
25 func1:
26 .pad #0
27 sub sp, sp, #0
28 add sp, sp, #0
29 bx lr
30 .personality __gxx_personality_v0
31 .handlerdata
32 .fnend
33
34 @-------------------------------------------------------------------------------
35 @ The assembler should emit nothing (will be filled up with finish opcode).
36 @-------------------------------------------------------------------------------
37 @ CHECK: Section {
38 @ CHECK: Name: .ARM.extab.TEST1
39 @ CHECK: SectionData (
40 @ CHECK: 0000: 00000000 B0B0B000 |........|
41 @ CHECK: )
42 @ CHECK: }
43
44
45
46 @-------------------------------------------------------------------------------
47 @ TEST2
48 @-------------------------------------------------------------------------------
49 .section .TEST2
50 .globl func2a
51 .align 2
52 .type func2a,%function
53 .fnstart
54 func2a:
55 .pad #0x4
56 sub sp, sp, #0x4
57 add sp, sp, #0x4
58 bx lr
59 .personality __gxx_personality_v0
60 .handlerdata
61 .fnend
62
63 .globl func2b
64 .align 2
65 .type func2b,%function
66 .fnstart
67 func2b:
68 .pad #0x100
69 sub sp, sp, #0x100
70 add sp, sp, #0x100
71 bx lr
72 .personality __gxx_personality_v0
73 .handlerdata
74 .fnend
75
76 @-------------------------------------------------------------------------------
77 @ The assembler should emit ((offset - 4) >> 2).
78 @-------------------------------------------------------------------------------
79 @ CHECK: Section {
80 @ CHECK: Name: .ARM.extab.TEST2
81 @ CHECK: SectionData (
82 @ CHECK: 0000: 00000000 B0B00000 00000000 B0B03F00 |..............?.|
83 @ CHECK: )
84 @ CHECK: }
85
86
87 @-------------------------------------------------------------------------------
88 @ TEST3
89 @-------------------------------------------------------------------------------
90 .section .TEST3
91 .globl func3a
92 .align 2
93 .type func3a,%function
94 .fnstart
95 func3a:
96 .pad #0x104
97 sub sp, sp, #0x104
98 add sp, sp, #0x104
99 bx lr
100 .personality __gxx_personality_v0
101 .handlerdata
102 .fnend
103
104 .globl func3b
105 .align 2
106 .type func3b,%function
107 .fnstart
108 func3b:
109 .pad #0x200
110 sub sp, sp, #0x200
111 add sp, sp, #0x200
112 bx lr
113 .personality __gxx_personality_v0
114 .handlerdata
115 .fnend
116
117 @-------------------------------------------------------------------------------
118 @ The assembler should emit 0x3F and ((offset - 0x104) >> 2).
119 @-------------------------------------------------------------------------------
120 @ CHECK: Section {
121 @ CHECK: Name: .ARM.extab.TEST3
122 @ CHECK: SectionData (
123 @ CHECK: 0000: 00000000 B0003F00 00000000 B03F3F00 |......?......??.|
124 @ CHECK: )
125 @ CHECK: }
126
127
128
129 @-------------------------------------------------------------------------------
130 @ TEST4
131 @-------------------------------------------------------------------------------
132 .section .TEST4
133 .globl func4a
134 .align 2
135 .type func4a,%function
136 .fnstart
137 func4a:
138 .pad #0x204
139 sub sp, sp, #0x204
140 add sp, sp, #0x204
141 bx lr
142 .personality __gxx_personality_v0
143 .handlerdata
144 .fnend
145
146 .globl func4b
147 .align 2
148 .type func4b,%function
149 .fnstart
150 func4b:
151 .pad #0x580
152 sub sp, sp, #0x580
153 add sp, sp, #0x580
154 bx lr
155 .personality __gxx_personality_v0
156 .handlerdata
157 .fnend
158
159 @-------------------------------------------------------------------------------
160 @ The assembler should emit 0xB2 and the ULEB128 encoding of
161 @ ((offset - 0x204) >> 2).
162 @-------------------------------------------------------------------------------
163 @ CHECK: Section {
164 @ CHECK: Name: .ARM.extab.TEST4
165 @ CHECK: SectionData (
166 @ CHECK: 0000: 00000000 B000B200 00000000 01DFB200 |................|
167 @ CHECK: )
168 @ CHECK: }
169
170
171
172 @-------------------------------------------------------------------------------
173 @ TEST5
174 @-------------------------------------------------------------------------------
175 .section .TEST5
176 .globl func4a
177 .align 2
178 .type func4a,%function
179 .fnstart
180 func5a:
181 .pad #-0x4
182 add sp, sp, #0x4
183 sub sp, sp, #0x4
184 bx lr
185 .personality __gxx_personality_v0
186 .handlerdata
187 .fnend
188
189 .globl func5b
190 .align 2
191 .type func5b,%function
192 .fnstart
193 func5b:
194 .pad #-0x104
195 add sp, sp, #0x104
196 sub sp, sp, #0x4
197 bx lr
198 .personality __gxx_personality_v0
199 .handlerdata
200 .fnend
201
202 .globl func5c
203 .align 2
204 .type func5c,%function
205 .fnstart
206 func5c:
207 .pad #-0x204
208 add sp, sp, #0x204
209 sub sp, sp, #0x4
210 bx lr
211 .personality __gxx_personality_v0
212 .handlerdata
213 .fnend
214
215 @-------------------------------------------------------------------------------
216 @ The assembler should emit (0x40 | (-offset - 4)) >> 2. When (-offset - 4)
217 @ is greater than 0x3f, then multiple 0x7f should be emitted.
218 @-------------------------------------------------------------------------------
219 @ CHECK: Section {
220 @ CHECK: Name: .ARM.extab.TEST5
221 @ CHECK: SectionData (
222 @ CHECK: 0000: 00000000 B0B04000 00000000 B0407F00 |......@......@..|
223 @ CHECK: 0010: 00000000 407F7F00 |....@...|
224 @ CHECK: )
225 @ CHECK: }
0 @ RUN: not llvm-mc -triple=armv7-unknown-linux-gnueabi < %s 2> %t
1 @ RUN: FileCheck --check-prefix=CHECK < %t %s
2
3 @ Check the diagnostics for .personality directive.
4
5
6 .syntax unified
7 .text
8
9 @-------------------------------------------------------------------------------
10 @ TEST1: .personality before .fnstart
11 @-------------------------------------------------------------------------------
12 .globl func1
13 .align 2
14 .type func1,%function
15 .personality __gxx_personality_v0
16 @ CHECK: error: .fnstart must precede .personality directive
17 @ CHECK: .personality __gxx_personality_v0
18 @ CHECK: ^
19 .fnstart
20 func1:
21 .fnend
22
23
24
25 @-------------------------------------------------------------------------------
26 @ TEST2: .personality after .handlerdata
27 @-------------------------------------------------------------------------------
28 .globl func2
29 .align 2
30 .type func2,%function
31 .fnstart
32 func2:
33 .handlerdata
34 .personality __gxx_personality_v0
35 @ CHECK: error: .personality must precede .handlerdata directive
36 @ CHECK: .personality __gxx_personality_v0
37 @ CHECK: ^
38 .fnend
0 @ RUN: llvm-mc %s -triple=armv7-unknown-linux-gnueabi -filetype=obj -o - \
1 @ RUN: | llvm-readobj -s -sd -sr | FileCheck %s
2
3 @ Check the .personality directive.
4
5 .syntax unified
6
7 @-------------------------------------------------------------------------------
8 @ TEST1
9 @-------------------------------------------------------------------------------
10 .section .TEST1
11 .globl func1
12 .align 2
13 .type func1,%function
14 .fnstart
15 func1:
16 bx lr
17 .personality __gxx_personality_v0
18 .handlerdata
19 .fnend
20
21
22 @ CHECK: Section {
23 @ CHECK: Name: .TEST1
24 @ CHECK: SectionData (
25 @ CHECK: 0000: 1EFF2FE1 |../.|
26 @ CHECK: )
27 @ CHECK: }
28 @ CHECK: Section {
29 @ CHECK: Name: .ARM.extab.TEST1
30 @ CHECK: Relocations [
31 @ CHECK: 0x0 R_ARM_PREL31 __gxx_personality_v0 0x0
32 @ CHECK: ]
33 @ CHECK: SectionData (
34 @ CHECK: 0000: 00000000 B0B0B000 |........|
35 @ CHECK: )
36 @ CHECK: }
37 @ CHECK: Section {
38 @ CHECK: Name: .ARM.exidx.TEST1
39 @ CHECK: Relocations [
40 @ CHECK: 0x0 R_ARM_PREL31 .TEST1 0x0
41 @ CHECK: 0x4 R_ARM_PREL31 .ARM.extab.TEST1 0x0
42 @ CHECK: ]
43 @ CHECK: SectionData (
44 @ CHECK: 0000: 00000000 00000000 |........|
45 @ CHECK: )
46 @ CHECK: }
47
48
49
50 @-------------------------------------------------------------------------------
51 @ TEST2
52 @-------------------------------------------------------------------------------
53 .section .TEST2
54 .globl func2
55 .align 2
56 .type func2,%function
57 .fnstart
58 func2:
59 bx lr
60 .personality __gxx_personality_v0
61 @ The .handlerdata directive is intentionally ignored. The .fnend @ directive should create the EXTAB entry and flush the unwind opcodes.
62 .fnend
63
64
65 @ CHECK: Section {
66 @ CHECK: Name: .TEST2
67 @ CHECK: SectionData (
68 @ CHECK: 0000: 1EFF2FE1 |../.|
69 @ CHECK: )
70 @ CHECK: }
71 @ CHECK: Section {
72 @ CHECK: Name: .ARM.extab.TEST2
73 @ CHECK: Relocations [
74 @ CHECK: 0x0 R_ARM_PREL31 __gxx_personality_v0 0x0
75 @ CHECK: ]
76 @ CHECK: SectionData (
77 @ CHECK: 0000: 00000000 B0B0B000 |........|
78 @ CHECK: )
79 @ CHECK: }
80 @ CHECK: Section {
81 @ CHECK: Name: .ARM.exidx.TEST2
82 @ CHECK: Relocations [
83 @ CHECK: 0x0 R_ARM_PREL31 .TEST2 0x0
84 @ CHECK: 0x4 R_ARM_PREL31 .ARM.extab.TEST2 0x0
85 @ CHECK: ]
86 @ CHECK: SectionData (
87 @ CHECK: 0000: 00000000 00000000 |........|
88 @ CHECK: )
89 @ CHECK: }
0 @ RUN: not llvm-mc -triple=armv7-unknown-linux-gnueabi < %s 2> %t
1 @ RUN: FileCheck --check-prefix=CHECK < %t %s
2
3 @ Check the diagnostics for .save directive
4
5 @ .save directive should always come after .fnstart directive and
6 @ before .handlerdata directive.
7
8 .syntax unified
9 .text
10
11 @-------------------------------------------------------------------------------
12 @ TEST1: .save before .fnstart
13 @-------------------------------------------------------------------------------
14 .globl func1
15 .align 2
16 .type func1,%function
17 .save {r4, r5, r6, r7}
18 @ CHECK: error: .fnstart must precede .save or .vsave directives
19 @ CHECK: .save {r4, r5, r6, r7}
20 @ CHECK: ^
21 .fnstart
22 func1:
23 .fnend
24
25
26
27 @-------------------------------------------------------------------------------
28 @ TEST2: .save after .handlerdata
29 @-------------------------------------------------------------------------------
30 .globl func2
31 .align 2
32 .type func2,%function
33 .fnstart
34 func2:
35 .handlerdata
36 .save {r4, r5, r6, r7}
37 @ CHECK: error: .save or .vsave must precede .handlerdata directive
38 @ CHECK: .save {r4, r5, r6, r7}
39 @ CHECK: ^
40 .fnend
0 @ RUN: llvm-mc %s -triple=armv7-unknown-linux-gnueabi -filetype=obj -o - \
1 @ RUN: | llvm-readobj -s -sd | FileCheck %s
2
3 @ Check the .save directive
4
5 @ The .save directive records the GPR registers which are pushed to the
6 @ stack. There are 4 different unwind opcodes:
7 @
8 @ 0xB100: pop r[3:0]
9 @ 0xA0: pop r[(4+x):4] @ r[4+x]-r[4] must be consecutive.
10 @ 0xA8: pop r14, r[(4+x):4] @ r[4+x]-r[4] must be consecutive.
11 @ 0x8000: pop r[15:4]
12 @
13 @ If register list specifed by .save directive is possible to be encoded
14 @ by 0xA0 or 0xA8, then the assembler should prefer them over 0x8000.
15
16
17 .syntax unified
18
19 @-------------------------------------------------------------------------------
20 @ TEST1
21 @-------------------------------------------------------------------------------
22 .section .TEST1
23 .globl func1a
24 .align 2
25 .type func1a,%function
26 .fnstart
27 func1a:
28 .save {r0}
29 push {r0}
30 pop {r0}
31 bx lr
32 .personality __gxx_personality_v0
33 .handlerdata
34 .fnend
35
36 .globl func1b
37 .align 2
38 .type func1b,%function
39 .fnstart
40 func1b:
41 .save {r0, r1}
42 push {r0, r1}
43 pop {r0, r1}
44 bx lr
45 .personality __gxx_personality_v0
46 .handlerdata
47 .fnend
48
49 .globl func1c
50 .align 2
51 .type func1c,%function
52 .fnstart
53 func1c:
54 .save {r0, r2}
55 push {r0, r2}
56 pop {r0, r2}
57 bx lr
58 .personality __gxx_personality_v0
59 .handlerdata
60 .fnend
61
62 .globl func1d
63 .align 2
64 .type func1d,%function
65 .fnstart
66 func1d:
67 .save {r1, r2}
68 push {r1, r2}
69 pop {r1, r2}
70 bx lr
71 .personality __gxx_personality_v0
72 .handlerdata
73 .fnend
74
75 .globl func1e
76 .align 2
77 .type func1e,%function
78 .fnstart
79 func1e:
80 .save {r0, r1, r2, r3}
81 push {r0, r1, r2, r3}
82 pop {r0, r1, r2, r3}
83 bx lr
84 .personality __gxx_personality_v0
85 .handlerdata
86 .fnend
87
88 @-------------------------------------------------------------------------------
89 @ The assembler should emit 0xB000 unwind opcode.
90 @-------------------------------------------------------------------------------
91 @ CHECK: Section {
92 @ CHECK: Name: .ARM.extab.TEST1
93 @ CHECK: SectionData (
94 @ CHECK: 0000: 00000000 B001B100 00000000 B003B100 |................|
95 @ CHECK: 0010: 00000000 B005B100 00000000 B006B100 |................|
96 @ CHECK: 0020: 00000000 B00FB100 |........|
97 @ CHECK: )
98 @ CHECK: }
99
100
101
102 @-------------------------------------------------------------------------------
103 @ TEST2
104 @-------------------------------------------------------------------------------
105 .section .TEST2
106 .globl func2a
107 .align 2
108 .type func2a,%function
109 .fnstart
110 func2a:
111 .save {r4}
112 push {r4}
113 pop {r4}
114 bx lr
115 .personality __gxx_personality_v0
116 .handlerdata
117 .fnend
118
119 .globl func2b
120 .align 2
121 .type func2b,%function
122 .fnstart
123 func2b:
124 .save {r4, r5}
125 push {r4, r5}
126 pop {r4, r5}
127 bx lr
128 .personality __gxx_personality_v0
129 .handlerdata
130 .fnend
131
132 .globl func2c
133 .align 2
134 .type func2c,%function
135 .fnstart
136 func2c:
137 .save {r4, r5, r6, r7, r8, r9, r10, r11}
138 push {r4, r5, r6, r7, r8, r9, r10, r11}
139 pop {r4, r5, r6, r7, r8, r9, r10, r11}
140 bx lr
141 .personality __gxx_personality_v0
142 .handlerdata
143 .fnend
144
145 @-------------------------------------------------------------------------------
146 @ The assembler should emit 0xA0 unwind opcode.
147 @-------------------------------------------------------------------------------
148 @ CHECK: Section {
149 @ CHECK: Name: .ARM.extab.TEST2
150 @ CHECK: SectionData (
151 @ CHECK: 0000: 00000000 B0B0A000 00000000 B0B0A100 |................|
152 @ CHECK: 0010: 00000000 B0B0A700 |........|
153 @ CHECK: )
154 @ CHECK: }
155
156
157
158 @-------------------------------------------------------------------------------
159 @ TEST3
160 @-------------------------------------------------------------------------------
161 .section .TEST3
162 .globl func3a
163 .align 2
164 .type func3a,%function
165 .fnstart
166 func3a:
167 .save {r4, r14}
168 push {r4, r14}
169 pop {r4, r14}
170 bx lr
171 .personality __gxx_personality_v0
172 .handlerdata
173 .fnend
174
175 .globl func3b
176 .align 2
177 .type func3b,%function
178 .fnstart
179 func3b:
180 .save {r4, r5, r14}
181 push {r4, r5, r14}
182 pop {r4, r5, r14}
183 bx lr
184 .personality __gxx_personality_v0
185 .handlerdata
186 .fnend
187
188 .globl func3c
189 .align 2
190 .type func3c,%function
191 .fnstart
192 func3c:
193 .save {r4, r5, r6, r7, r8, r9, r10, r11, r14}
194 push {r4, r5, r6, r7, r8, r9, r10, r11, r14}
195 pop {r4, r5, r6, r7, r8, r9, r10, r11, r14}
196 bx lr
197 .personality __gxx_personality_v0
198 .handlerdata
199 .fnend
200
201 @-------------------------------------------------------------------------------
202 @ The assembler should emit 0xA8 unwind opcode.
203 @-------------------------------------------------------------------------------
204 @ CHECK: Section {
205 @ CHECK: Name: .ARM.extab.TEST3
206 @ CHECK: SectionData (
207 @ CHECK: 0000: 00000000 B0B0A800 00000000 B0B0A900 |................|
208 @ CHECK: 0010: 00000000 B0B0AF00 |........|
209 @ CHECK: )
210 @ CHECK: }
211
212
213
214 @-------------------------------------------------------------------------------
215 @ TEST4
216 @-------------------------------------------------------------------------------
217 .section .TEST4
218 .globl func4a
219 .align 2
220 .type func4a,%function
221 .fnstart
222 func4a:
223 .save {r4, r5, r6, r7, r8, r9, r10, r11, r12, r14}
224 push {r4, r5, r6, r7, r8, r9, r10, r11, r12, r14}
225 pop {r4, r5, r6, r7, r8, r9, r10, r11, r12, r14}
226 bx lr
227 .personality __gxx_personality_v0
228 .handlerdata
229 .fnend
230
231 .globl func4b
232 .align 2
233 .type func4b,%function
234 .fnstart
235 func4b:
236 @ Note: r7 is missing intentionally.
237 .save {r4, r5, r6, r8, r9, r10, r11}
238 push {r4, r5, r6, r8, r9, r10, r11}
239 pop {r4, r5, r6, r8, r9, r10, r11}
240 bx lr
241 .personality __gxx_personality_v0
242 .handlerdata
243 .fnend
244
245 .globl func4c
246 .align 2
247 .type func4c,%function
248 .fnstart
249 func4c:
250 @ Note: r7 is missing intentionally.
251 .save {r4, r5, r6, r8, r9, r10, r11, r14}
252 push {r4, r5, r6, r8, r9, r10, r11, r14}
253 pop {r4, r5, r6, r8, r9, r10, r11, r14}
254 bx lr
255 .personality __gxx_personality_v0
256 .handlerdata
257 .fnend
258
259 .globl func4d
260 .align 2
261 .type func4d,%function
262 .fnstart
263 func4d:
264 @ Note: The register list is not start with r4.
265 .save {r5, r6, r7}
266 push {r5, r6, r7}
267 pop {r5, r6, r7}
268 bx lr
269 .personality __gxx_personality_v0
270 .handlerdata
271 .fnend
272
273 .globl func4e
274 .align 2
275 .type func4e,%function
276 .fnstart
277 func4e:
278 @ Note: The register list is not start with r4.
279 .save {r5, r6, r7, r14}
280 push {r5, r6, r7, r14}
281 pop {r5, r6, r7, r14}
282 bx lr
283 .personality __gxx_personality_v0
284 .handlerdata
285 .fnend
286
287 @-------------------------------------------------------------------------------
288 @ The assembler should emit 0x8000 unwind opcode.
289 @-------------------------------------------------------------------------------
290 @ CHECK: Section {
291 @ CHECK: Name: .ARM.extab.TEST4
292 @ CHECK: SectionData (
293 @ CHECK: 0000: 00000000 B0FF8500 00000000 B0F78000 |................|
294 @ CHECK: 0010: 00000000 B0F78400 00000000 B00E8000 |................|
295 @ CHECK: 0020: 00000000 B00E8400 |........|
296 @ CHECK: )
297 @ CHECK: }
0 @ RUN: llvm-mc %s -triple=armv7-unknown-linux-gnueabi -filetype=obj -o - \
1 @ RUN: | llvm-readobj -s -sd -sr -t | FileCheck %s
2
3 @ Check the .group section for the function in comdat section.
4
5 @ In C++, the instantiation of the template will come with linkonce (or
6 @ linkonce_odr) linkage, so that the linker can remove the duplicated
7 @ instantiation. When the exception handling is enabled on those function,
8 @ we have to group the corresponding .ARM.extab and .ARM.exidx with the
9 @ text section together.
10 @
11 @ This test case will check the content of .group section. The section index
12 @ of the grouped sections should be recorded in .group section.
13
14 .syntax unified
15 .section .TEST1,"axG",%progbits,func1,comdat
16 .weak func1
17 .align 2
18 .type func1,%function
19 func1:
20 .fnstart
21 .save {r4, lr}
22 push {r4, lr}
23 .vsave {d8, d9, d10, d11, d12}
24 vpush {d8, d9, d10, d11, d12}
25 .pad #24
26 sub sp, sp, #24
27
28 add sp, sp, #24
29 vpop {d8, d9, d10, d11, d12}
30 pop {r4, pc}
31
32 .globl __gxx_personality_v0
33 .personality __gxx_personality_v0
34 .handlerdata
35 .fnend
36
37
38
39 @-------------------------------------------------------------------------------
40 @ Check the .group section
41 @-------------------------------------------------------------------------------
42 @ CHECK: Sections [
43 @ CHECK: Section {
44 @ CHECK: Index: 1
45 @ CHECK: Name: .group
46 @ CHECK: Type: SHT_GROUP (0x11)
47 @ CHECK: Flags [ (0x0)
48 @ CHECK: ]
49 @ CHECK: SectionData (
50 @-------------------------------------------------------------------------------
51 @ The second, third, and fourth word should correspond to the section index
52 @ of .TEST1, .ARM.extab.TEST1, and .ARM.exidx.TEST1.
53 @-------------------------------------------------------------------------------
54 @ CHECK: 0000: 01000000 05000000 06000000 08000000 |................|
55 @ CHECK: )
56 @ CHECK: }
57
58
59 @-------------------------------------------------------------------------------
60 @ Check the .TEST1 section
61 @-------------------------------------------------------------------------------
62 @ CHECK: Section {
63 @ CHECK: Index: 5
64 @ CHECK: Name: .TEST1
65 @ CHECK: Type: SHT_PROGBITS (0x1)
66 @-------------------------------------------------------------------------------
67 @ The flags should contain SHF_GROUP.
68 @-------------------------------------------------------------------------------
69 @ CHECK: Flags [ (0x206)
70 @ CHECK: SHF_ALLOC (0x2)
71 @ CHECK: SHF_EXECINSTR (0x4)
72 @ CHECK: SHF_GROUP (0x200)
73 @ CHECK: ]
74 @ CHECK: }
75
76
77 @-------------------------------------------------------------------------------
78 @ Check the .ARM.extab.TEST1 section
79 @-------------------------------------------------------------------------------
80 @ CHECK: Section {
81 @ CHECK: Index: 6
82 @ CHECK: Name: .ARM.extab.TEST1
83 @ CHECK: Type: SHT_PROGBITS (0x1)
84 @-------------------------------------------------------------------------------
85 @ The flags should contain SHF_GROUP.
86 @-------------------------------------------------------------------------------
87 @ CHECK: Flags [ (0x202)
88 @ CHECK: SHF_ALLOC (0x2)
89 @ CHECK: SHF_GROUP (0x200)
90 @ CHECK: ]
91 @ CHECK: }
92
93
94 @-------------------------------------------------------------------------------
95 @ Check the .ARM.exidx.TEST1 section
96 @-------------------------------------------------------------------------------
97 @ CHECK: Section {
98 @ CHECK: Index: 8
99 @ CHECK: Name: .ARM.exidx.TEST1
100 @ CHECK: Type: SHT_ARM_EXIDX (0x70000001)
101 @-------------------------------------------------------------------------------
102 @ The flags should contain SHF_GROUP.
103 @-------------------------------------------------------------------------------
104 @ CHECK: Flags [ (0x282)
105 @ CHECK: SHF_ALLOC (0x2)
106 @ CHECK: SHF_GROUP (0x200)
107 @ CHECK: SHF_LINK_ORDER (0x80)
108 @ CHECK: ]
109 @ CHECK: Link: 5
110 @ CHECK: }
111 @ CHECK: ]
112
113
114
115 @-------------------------------------------------------------------------------
116 @ Check symbol func1. It should be weak binding, and belong to .TEST1 section.
117 @-------------------------------------------------------------------------------
118 @ CHECK: Symbols [
119 @ CHECK: Symbol {
120 @ CHECK: Name: func1
121 @ CHECK: Binding: Weak (0x2)
122 @ CHECK: Type: Function (0x2)
123 @ CHECK: Section: .TEST1 (0x5)
124 @ CHECK: }
125 @ CHECK: ]
0 @ RUN: llvm-mc %s -triple=armv7-unknown-linux-gnueabi -filetype=obj -o - \
1 @ RUN: | llvm-readobj -s -sd -sr -t | FileCheck %s
2
3 @ Check whether the section is switched back properly.
4
5 @ The assembler should switch the section back to the corresponding section
6 @ after it have emitted the exception handling indices and tables. In this
7 @ test case, we are checking whether the section is correct when .section
8 @ directives is used.
9
10 @ In this example, func1 and func2 should be defined in .TEST1 section.
11 @ It is incorrect if the func2 is in .text, .ARM.extab.TEST1, or
12 @ .ARM.exidx.TEST1 sections.
13
14 .syntax unified
15
16 .section .TEST1
17
18 .globl func1
19 .align 2
20 .type func1,%function
21 .fnstart
22 func1:
23 bx lr
24 .personality __gxx_personality_v0
25 .handlerdata
26 .fnend
27
28 .globl func2
29 .align 2
30 .type func2,%function
31 .fnstart
32 func2:
33 bx lr
34 .personality __gxx_personality_v0
35 .handlerdata
36 .fnend
37
38
39 @-------------------------------------------------------------------------------
40 @ Check the .text section. This should be empty.
41 @-------------------------------------------------------------------------------
42 @ CHECK: Sections [
43 @ CHECK: Section {
44 @ CHECK: Name: .text
45 @ CHECK: SectionData (
46 @ CHECK: )
47 @ CHECK: }
48
49
50 @-------------------------------------------------------------------------------
51 @ Check the .TEST1 section. There should be two "bx lr" instructions.
52 @-------------------------------------------------------------------------------
53 @ CHECK: Section {
54 @ CHECK: Name: .TEST1
55 @ CHECK: SectionData (
56 @ CHECK: 0000: 1EFF2FE1 1EFF2FE1 |../.../.|
57 @ CHECK: )
58 @ CHECK: }
59
60
61
62 @-------------------------------------------------------------------------------
63 @ Check the .ARM.extab.TEST1 section.
64 @-------------------------------------------------------------------------------
65 @ CHECK: Section {
66 @ CHECK: Name: .ARM.extab.TEST1
67 @ CHECK: Relocations [
68 @ CHECK: 0x0 R_ARM_PREL31 __gxx_personality_v0 0x0
69 @ CHECK: 0x8 R_ARM_PREL31 __gxx_personality_v0 0x0
70 @ CHECK: ]
71 @ CHECK: SectionData (
72 @ CHECK: 0000: 00000000 B0B0B000 00000000 B0B0B000 |................|
73 @ CHECK: )
74 @ CHECK: }
75
76
77 @-------------------------------------------------------------------------------
78 @ Check the .ARM.exidx.TEST1 section.
79 @-------------------------------------------------------------------------------
80 @ CHECK: Section {
81 @ CHECK: Name: .ARM.exidx.TEST1
82 @ CHECK: Link: 4
83 @-------------------------------------------------------------------------------
84 @ The first word of each entry should be relocated to .TEST1 section.
85 @ The second word of each entry should be relocated to
86 @ .ARM.extab.TESET1 section.
87 @-------------------------------------------------------------------------------
88 @ CHECK: Relocations [
89 @ CHECK: 0x0 R_ARM_PREL31 .TEST1 0x0
90 @ CHECK: 0x4 R_ARM_PREL31 .ARM.extab.TEST1 0x0
91 @ CHECK: 0x8 R_ARM_PREL31 .TEST1 0x0
92 @ CHECK: 0xC R_ARM_PREL31 .ARM.extab.TEST1 0x0
93 @ CHECK: ]
94 @-------------------------------------------------------------------------------
95 @ The first word should be the offset to .TEST1.
96 @ The second word should be the offset to .ARM.extab.TEST1
97 @-------------------------------------------------------------------------------
98 @ CHECK: SectionData (
99 @ CHECK: 0000: 00000000 00000000 04000000 08000000 |................|
100 @ CHECK: )
101 @ CHECK: }
102 @ CHECK: ]
103
104
105
106 @-------------------------------------------------------------------------------
107 @ Check the symbols "func1" and "func2". They should belong to .TEST1 section.
108 @-------------------------------------------------------------------------------
109 @ CHECK: Symbols [
110 @ CHECK: Symbol {
111 @ CHECK: Name: func1
112 @ CHECK: Value: 0x0
113 @ CHECK: Size: 0
114 @ CHECK: Binding: Global (0x1)
115 @ CHECK: Type: Function (0x2)
116 @ CHECK: Other: 0
117 @ CHECK: Section: .TEST1 (0x4)
118 @ CHECK: }
119 @ CHECK: Symbol {
120 @ CHECK: Name: func2
121 @ CHECK: Value: 0x4
122 @ CHECK: Size: 0
123 @ CHECK: Binding: Global (0x1)
124 @ CHECK: Type: Function (0x2)
125 @ CHECK: Other: 0
126 @ CHECK: Section: .TEST1 (0x4)
127 @ CHECK: }
128 @ CHECK: ]
0 @ RUN: llvm-mc %s -triple=armv7-unknown-linux-gnueabi -filetype=obj -o - \
1 @ RUN: | llvm-readobj -s -sd -sr -t | FileCheck %s
2
3 @ Check the combination of .section, .fnstart, and .fnend directives.
4
5 @ For the functions in .text section, the exception handling index (EXIDX)
6 @ should be generated in .ARM.exidx, and the exception handling table (EXTAB)
7 @ should be generated in .ARM.extab.
8
9 @ For the functions in custom section specified by .section directives,
10 @ the EXIDX should be generated in ".ARM.exidx[[SECTION_NAME]]", and the EXTAB
11 @ should be generated in ".ARM.extab[[SECTION_NAME]]".
12
13 .syntax unified
14
15 @-------------------------------------------------------------------------------
16 @ .TEST1 section
17 @-------------------------------------------------------------------------------
18 .section .TEST1
19 .globl func1
20 .align 2
21 .type func1,%function
22 .fnstart
23 func1:
24 bx lr
25 .personality __gxx_personality_v0
26 .handlerdata
27 .fnend
28
29
30 @-------------------------------------------------------------------------------
31 @ TEST2 section (without the dot in the beginning)
32 @-------------------------------------------------------------------------------
33 .section TEST2
34 .globl func2
35 .align 2
36 .type func2,%function
37 .fnstart
38 func2:
39 bx lr
40 .personality __gxx_personality_v0
41 .handlerdata
42 .fnend
43
44
45 @-------------------------------------------------------------------------------
46 @ Check the .TEST1 section.
47 @-------------------------------------------------------------------------------
48 @ CHECK: Sections [
49 @ CHECK: Section {
50 @ CHECK: Index: 4
51 @ CHECK: Name: .TEST1
52 @ CHECK: SectionData (
53 @ CHECK: 0000: 1EFF2FE1 |../.|
54 @ CHECK: )
55 @ CHECK: }
56
57 @-------------------------------------------------------------------------------
58 @ Check the .ARM.extab.TEST1 section, the EXTAB of .TEST1 section.
59 @-------------------------------------------------------------------------------
60 @ CHECK: Section {
61 @ CHECK: Name: .ARM.extab.TEST1
62 @ CHECK: Relocations [
63 @ CHECK: 0x0 R_ARM_PREL31 __gxx_personality_v0 0x0
64 @ CHECK: ]
65 @ CHECK: SectionData (
66 @ CHECK: 0000: 00000000 B0B0B000 |........|
67 @ CHECK: )
68 @ CHECK: }
69
70
71 @-------------------------------------------------------------------------------
72 @ Check the.ARM.exidx.TEST1 section, the EXIDX of .TEST1 section.
73 @-------------------------------------------------------------------------------
74 @ CHECK: Section {
75 @ CHECK: Name: .ARM.exidx.TEST1
76
77 @-------------------------------------------------------------------------------
78 @ This section should linked with .TEST1 section.
79 @-------------------------------------------------------------------------------
80 @ CHECK: Link: 4
81
82 @-------------------------------------------------------------------------------
83 @ The first word should be relocated to the code address in .TEST1 section.
84 @ The second word should be relocated to the EHTAB entry in .ARM.extab.TEST1
85 @ section.
86 @-------------------------------------------------------------------------------
87 @ CHECK: Relocations [
88 @ CHECK: 0x0 R_ARM_PREL31 .TEST1 0x0
89 @ CHECK: 0x4 R_ARM_PREL31 .ARM.extab.TEST1 0x0
90 @ CHECK: ]
91 @ CHECK: SectionData (
92 @ CHECK: 0000: 00000000 00000000 |........|
93 @ CHECK: )
94 @ CHECK: }
95
96
97
98 @-------------------------------------------------------------------------------
99 @ Check the TEST2 section (without the dot in the beginning)
100 @-------------------------------------------------------------------------------
101 @ CHECK: Section {
102 @ CHECK: Index: 9
103 @ CHECK: Name: TEST2
104 @ CHECK: SectionData (
105 @ CHECK: 0000: 1EFF2FE1 |../.|
106 @ CHECK: )
107 @ CHECK: }
108
109 @-------------------------------------------------------------------------------
110 @ Check the .ARM.extabTEST2 section, the EXTAB of TEST2 section.
111 @-------------------------------------------------------------------------------
112 @ CHECK: Section {
113 @ CHECK: Name: .ARM.extabTEST2
114 @ CHECK: Relocations [
115 @ CHECK: 0x0 R_ARM_PREL31 __gxx_personality_v0 0x0
116 @ CHECK: ]
117 @ CHECK: SectionData (
118 @ CHECK: 0000: 00000000 B0B0B000 |........|
119 @ CHECK: )
120 @ CHECK: }
121
122
123 @-------------------------------------------------------------------------------
124 @ Check the .ARM.exidxTEST2 section, the EXIDX of TEST2 section.
125 @-------------------------------------------------------------------------------
126 @ CHECK: Section {
127 @ CHECK: Name: .ARM.exidxTEST2
128
129 @-------------------------------------------------------------------------------
130 @ This section should linked with TEST2 section.
131 @-------------------------------------------------------------------------------
132 @ CHECK: Link: 9
133
134 @-------------------------------------------------------------------------------
135 @ The first word should be relocated to the code address in TEST2 section.
136 @ The second word should be relocated to the EHTAB entry in .ARM.extabTEST2
137 @ section.
138 @-------------------------------------------------------------------------------
139 @ CHECK: Relocations [
140 @ CHECK: 0x0 R_ARM_PREL31 TEST2 0x0
141 @ CHECK: 0x4 R_ARM_PREL31 .ARM.extabTEST2 0x0
142 @ CHECK: ]
143 @ CHECK: SectionData (
144 @ CHECK: 0000: 00000000 00000000 |........|
145 @ CHECK: )
146 @ CHECK: }
147 @ CHECK: ]
148
149
150
151 @-------------------------------------------------------------------------------
152 @ Check the symbols and the sections they belong to
153 @-------------------------------------------------------------------------------
154 @ CHECK: Symbols [
155 @ CHECK: Symbol {
156 @ CHECK: Name: func1
157 @ CHECK: Section: .TEST1 (0x4)
158 @ CHECK: }
159 @ CHECK: Symbol {
160 @ CHECK: Name: func2
161 @ CHECK: Section: TEST2 (0x9)
162 @ CHECK: }
163 @ CHECK: ]
0 @ RUN: not llvm-mc -triple=armv7-unknown-linux-gnueabi < %s 2> %t
1 @ RUN: FileCheck --check-prefix=CHECK < %t %s
2
3 @ Check the diagnostics for .setfp directive.
4
5
6 .syntax unified
7 .text
8
9 @-------------------------------------------------------------------------------
10 @ TEST1: .setfp before .fnstart
11 @-------------------------------------------------------------------------------
12 .globl func1
13 .align 2
14 .type func1,%function
15 .setfp fp, sp, #0
16 @ CHECK: error: .fnstart must precede .setfp directive
17 @ CHECK: .setfp fp, sp, #0
18 @ CHECK: ^
19 .fnstart
20 func1:
21 .fnend
22
23
24
25 @-------------------------------------------------------------------------------
26 @ TEST2: .setfp after .handlerdata
27 @-------------------------------------------------------------------------------
28 .globl func2
29 .align 2
30 .type func2,%function
31 .fnstart
32 func2:
33 .handlerdata
34 .setfp fp, sp, #0
35 @ CHECK: error: .setfp must precede .handlerdata directive
36 @ CHECK: .setfp fp, sp, #0
37 @ CHECK: ^
38 .fnend
39
40
41
42 @-------------------------------------------------------------------------------
43 @ TEST3: .setfp with bad fp register
44 @-------------------------------------------------------------------------------
45 .globl func3
46 .align 2
47 .type func3,%function
48 .fnstart
49 func3:
50 .setfp 0, r0, #0
51 @ CHECK: error: frame pointer register expected
52 @ CHECK: .setfp 0, r0, #0
53 @ CHECK: ^
54 .fnend
55
56
57
58 @-------------------------------------------------------------------------------
59 @ TEST4: .setfp with bad sp register
60 @-------------------------------------------------------------------------------
61 .globl func4
62 .align 2
63 .type func4,%function
64 .fnstart
65 func4:
66 .setfp fp, 0, #0
67 @ CHECK: error: stack pointer register expected
68 @ CHECK: .setfp fp, 0, #0
69 @ CHECK: ^
70 .fnend
71
72
73
74 @-------------------------------------------------------------------------------
75 @ TEST5: .setfp with non-sp register as second operand
76 @-------------------------------------------------------------------------------
77 .globl func5
78 .align 2
79 .type func5,%function
80 .fnstart
81 func5:
82 .setfp fp, r0, #0
83 @ CHECK: error: register should be either $sp or the latest fp register
84 @ CHECK: .setfp fp, r0, #0
85 @ CHECK: ^
86 .fnend
0 @ RUN: llvm-mc %s -triple=armv7-unknown-linux-gnueabi -filetype=obj -o - \
1 @ RUN: | llvm-readobj -s -sd | FileCheck %s
2
3 @ Check for .setfp directive.
4
5 @ The .setfp directive will track the offset between the frame pointer and
6 @ the stack pointer. This is required for the function that will change
7 @ the stack pointer out of the function prologue. If the exception is thrown,
8 @ then libunwind will reconstruct the stack pointer from the frame pointer.
9 @ The reconstruction code is implemented by two different unwind opcode:
10 @ (i) the unwind opcode to copy stack offset from the other register, and
11 @ (ii) the unwind opcode to add or substract the stack offset.
12 @
13 @ This file includes several cases separated by different range of -offset
14 @
15 @ (-offset) < 0x00
16 @ (-offset) == 0x00
17 @ 0x04 <= (-offset) <= 0x100
18 @ 0x104 <= (-offset) <= 0x200
19 @ 0x204 <= (-offset)
20
21
22 .syntax unified
23
24 @-------------------------------------------------------------------------------
25 @ TEST1
26 @-------------------------------------------------------------------------------
27 .section .TEST1
28 .globl func1
29 .align 2
30 .type func1,%function
31 .fnstart
32 func1:
33 .setfp fp, sp, #0
34 add fp, sp, #0
35 sub sp, fp, #0
36 bx lr
37 .personality __gxx_personality_v0
38 .handlerdata
39 .fnend
40
41 @-------------------------------------------------------------------------------
42 @ The assembler should emit 0x9B to copy stack pointer from r11.
43 @-------------------------------------------------------------------------------
44 @ CHECK: Section {
45 @ CHECK: Name: .ARM.extab.TEST1
46 @ CHECK: SectionData (
47 @ CHECK: 0000: 00000000 B0B09B00 |........|
48 @ CHECK: )
49 @ CHECK: }
50
51
52
53 @-------------------------------------------------------------------------------
54 @ TEST2
55 @-------------------------------------------------------------------------------
56 .section .TEST2
57 .globl func2a
58 .align 2
59 .type func2a,%function
60 .fnstart
61 func2a:
62 .setfp fp, sp, #-4
63 add fp, sp, #4
64 sub sp, fp, #4
65 bx lr
66 .personality __gxx_personality_v0
67 .handlerdata
68 .fnend
69
70 .globl func2b
71 .align 2
72 .type func2b,%function
73 .fnstart
74 func2b:
75 .setfp fp, sp, #-0x100
76 add fp, sp, #0x100
77 sub sp, fp, #0x100
78 bx lr
79 .personality __gxx_personality_v0
80 .handlerdata
81 .fnend
82
83 @-------------------------------------------------------------------------------
84 @ The assembler should emit 0x9B to copy stack pointer from r11.
85 @ The assembler should emit ((-offset - 4) >> 2) for offset.
86 @-------------------------------------------------------------------------------
87 @ CHECK: Section {
88 @ CHECK: Name: .ARM.extab.TEST2
89 @ CHECK: SectionData (
90 @ CHECK: 0000: 00000000 B0009B00 00000000 B03F9B00 |.............?..|
91 @ CHECK: )
92 @ CHECK: }
93
94
95
96 @-------------------------------------------------------------------------------
97 @ TEST3
98 @-------------------------------------------------------------------------------
99 .section .TEST3
100 .globl func3a
101 .align 2
102 .type func3a,%function
103 .fnstart
104 func3a:
105 .setfp fp, sp, #-0x104
106 sub fp, sp, #0x104
107 add sp, fp, #0x104
108 bx lr
109 .personality __gxx_personality_v0
110 .handlerdata
111 .fnend
112
113 .globl func3b
114 .align 2
115 .type func3b,%function
116 .fnstart
117 func3b:
118 .setfp fp, sp, #-0x200
119 sub fp, sp, #0x200
120 add sp, fp, #0x200
121 bx lr
122 .personality __gxx_personality_v0
123 .handlerdata
124 .fnend
125
126 @-------------------------------------------------------------------------------
127 @ The assembler should emit 0x9B to copy stack pointer from r11.
128 @ The assembler should emit 0x3F and ((-offset - 0x104) >> 2) for offset.
129 @-------------------------------------------------------------------------------
130 @ CHECK: Section {
131 @ CHECK: Name: .ARM.extab.TEST3
132 @ CHECK: SectionData (
133 @ CHECK: 0000: 00000000 003F9B00 00000000 3F3F9B00 |.....?......??..|
134 @ CHECK: )
135 @ CHECK: }
136
137
138
139 @-------------------------------------------------------------------------------
140 @ TEST4
141 @-------------------------------------------------------------------------------
142 .section .TEST4
143 .globl func4a
144 .align 2
145 .type func4a,%function
146 .fnstart
147 func4a:
148 .setfp fp, sp, #-0x204
149 sub fp, sp, #0x204
150 add sp, fp, #0x204
151 bx lr
152 .personality __gxx_personality_v0
153 .handlerdata
154 .fnend
155
156 .globl func4b
157 .align 2
158 .type func4b,%function
159 .fnstart
160 func4b:
161 .setfp fp, sp, #-0x580
162 sub fp, sp, #0x580
163 add sp, fp, #0x580
164 bx lr
165 .personality __gxx_personality_v0
166 .handlerdata
167 .fnend
168
169 @-------------------------------------------------------------------------------
170 @ The assembler should emit 0x9B to copy stack pointer from r11.
171 @ The assembler should emit 0xB2 and the ULEB128 encoding of
172 @ ((-offset - 0x204) >> 2) for offset.
173 @-------------------------------------------------------------------------------
174 @ CHECK: Section {
175 @ CHECK: Name: .ARM.extab.TEST4
176 @ CHECK: SectionData (
177 @ CHECK: 0000: 00000000 00B29B00 00000000 DFB29B01 |................|
178 @ CHECK: 0010: B0B0B001 |....|
179 @ CHECK: )
180 @ CHECK: }
181
182
183
184 @-------------------------------------------------------------------------------
185 @ TEST5
186 @-------------------------------------------------------------------------------
187 .section .TEST5
188 .globl func5a
189 .align 2
190 .type func5a,%function
191 .fnstart
192 func5a:
193 .setfp fp, sp, #0x4
194 add fp, sp, #0x4
195 sub sp, fp, #0x4
196 bx lr
197 .personality __gxx_personality_v0
198 .handlerdata
199 .fnend
200
201 .globl func5b
202 .align 2
203 .type func5b,%function
204 .fnstart
205 func5b:
206 .setfp fp, sp, #0x104
207 add fp, sp, #0x104
208 sub sp, fp, #0x104
209 bx lr
210 .personality __gxx_personality_v0
211 .handlerdata
212 .fnend
213
214 .globl func5c
215 .align 2
216 .type func5c,%function
217 .fnstart
218 func5c:
219 .setfp fp, sp, #0x204
220 add fp, sp, #0x204
221 sub sp, fp, #0x204
222 bx lr
223 .personality __gxx_personality_v0
224 .handlerdata
225 .fnend
226
227 @-------------------------------------------------------------------------------
228 @ The assembler should emit 0x9B to copy stack pointer from r11.
229 @ The assembler should emit (0x40 | (offset - 4)) >> 2 for offset.
230 @ If (offset - 4) is greater than 0x3f, then multiple 0x7f should be emitted.
231 @-------------------------------------------------------------------------------
232 @ CHECK: Section {
233 @ CHECK: Name: .ARM.extab.TEST5
234 @ CHECK: SectionData (
235 @ CHECK: 0000: 00000000 B0409B00 00000000 407F9B00 |.....@......@...|
236 @ CHECK: 0010: 00000000 7F7F9B01 B0B0B040 |...........@|
237 @ CHECK: )
238 @ CHECK: }
0 @ RUN: llvm-mc %s -triple=armv7-unknown-linux-gnueabi -filetype=obj -o - \
1 @ RUN: | llvm-readobj -s -sd -sr -r -t | FileCheck %s
2
3 @ Check whether the section is switched back or not.
4
5 @ The assembler should emit the machine code of "func2" in .text section.
6 @ It is incorrect if the machine code is emitted in .ARM.exidx or .ARM.extab.
7 @ Besides, there should be two entries in .ARM.exidx section.
8
9 .syntax unified
10
11 .text
12 .globl func1
13 .align 2
14 .type func1,%function
15 .fnstart
16 func1:
17 bx lr
18 .fnend
19
20 .globl func2
21 .align 2
22 .type func2,%function
23 .fnstart
24 func2:
25 bx lr
26 .fnend
27
28
29 @-------------------------------------------------------------------------------
30 @ Check the .text section. There should be two "bx lr" instructions.
31 @-------------------------------------------------------------------------------
32 @ CHECK: Sections [
33 @ CHECK: Section {
34 @ CHECK: Name: .text
35 @ CHECK: SectionData (
36 @ CHECK: 0000: 1EFF2FE1 1EFF2FE1 |../.../.|
37 @ CHECK: )
38 @ CHECK: }
39
40
41 @-------------------------------------------------------------------------------
42 @ Check the .ARM.exidx section.
43 @ There should be two entries (two words per entry.)
44 @-------------------------------------------------------------------------------
45 @ CHECK: Section {
46 @ CHECK: Name: .ARM.exidx
47 @-------------------------------------------------------------------------------
48 @ The first word of each entry should be relocated to .text section.
49 @-------------------------------------------------------------------------------
50 @ CHECK: Relocations [
51 @ CHECK: 0x0 R_ARM_PREL31 .text 0x0
52 @ CHECK: 0x0 R_ARM_NONE __aeabi_unwind_cpp_pr0 0x0
53 @ CHECK: 0x8 R_ARM_PREL31 .text 0x0
54 @ CHECK: ]
55 @ CHECK: SectionData (
56 @-------------------------------------------------------------------------------
57 @ The first word should be the offset to .text. The second word should be
58 @ 0xB0B0B080, which means compact model 0 is used (0x80) and the rest of the
59 @ word is filled with FINISH opcode (0xB0).
60 @-------------------------------------------------------------------------------
61 @ CHECK: 0000: 00000000 B0B0B080 04000000 B0B0B080 |................|
62 @ CHECK: )
63 @ CHECK: }
64 @ CHECK: ]
65
66
67
68 @-------------------------------------------------------------------------------
69 @ Check the symbols "func1" and "func2". They should belong to .text section.
70 @-------------------------------------------------------------------------------
71 @ CHECK: Symbols [
72 @ CHECK: Symbol {
73 @ CHECK: Name: func1
74 @ CHECK: Section: .text (0x1)
75 @ CHECK: }
76 @ CHECK: Symbol {
77 @ CHECK: Name: func2
78 @ CHECK: Section: .text (0x1)
79 @ CHECK: }
80 @ CHECK: ]
0 @ RUN: llvm-mc %s -triple=armv7-unknown-linux-gnueabi -filetype=obj -o - \
1 @ RUN: | llvm-readobj -s -sd -sr | FileCheck %s
2
3 @ Check the .fnstart directive and the .fnend directive.
4
5 @ The .fnstart directive and .fnend directive should create an entry in
6 @ exception handling table. For example, if the function is defined in .text
7 @ section, then there should be an entry in .ARM.exidx section.
8
9 .syntax unified
10
11 .text
12 .globl func1
13 .align 2
14 .type func1,%function
15 .fnstart
16 func1:
17 bx lr
18 .fnend
19
20
21
22 @-------------------------------------------------------------------------------
23 @ Check the .text section.
24 @-------------------------------------------------------------------------------
25 @ CHECK: Sections [
26 @ CHECK: Section {
27
28 @-------------------------------------------------------------------------------
29 @ Check the index of .text section. This will be used in .ARM.exidx.
30 @-------------------------------------------------------------------------------
31 @ CHECK: Index: 1
32 @ CHECK: Name: .text
33 @ CHECK: Type: SHT_PROGBITS (0x1)
34 @ CHECK: Flags [ (0x6)
35 @ CHECK: SHF_ALLOC (0x2)
36 @ CHECK: SHF_EXECINSTR (0x4)
37 @ CHECK: ]
38 @ CHECK: SectionData (
39 @ CHECK: 0000: 1EFF2FE1 |../.|
40 @ CHECK: )
41 @ CHECK: }
42
43
44 @-------------------------------------------------------------------------------
45 @ Check the name of the EXIDX section. For the function in the .text section,
46 @ this should be .ARM.exidx. It is incorrect to see .ARM.exidx.text here.
47 @-------------------------------------------------------------------------------
48 @ CHECK: Section {
49 @ CHECK: Name: .ARM.exidx
50 @ CHECK: Type: SHT_ARM_EXIDX (0x70000001)
51 @ CHECK: Flags [ (0x82)
52 @ CHECK: SHF_ALLOC (0x2)
53 @ CHECK: SHF_LINK_ORDER (0x80)
54 @ CHECK: ]
55
56 @-------------------------------------------------------------------------------
57 @ Check the linked section of the EXIDX section. This should be the index
58 @ of the .text section.
59 @-------------------------------------------------------------------------------
60 @ CHECK: Link: 1
61
62 @-------------------------------------------------------------------------------
63 @ The first word should be relocated to the code address in .text section.
64 @ Besides, since this function is using compact model 0, thus we have to
65 @ add an relocation to __aeabi_unwind_cpp_pr0.
66 @-------------------------------------------------------------------------------
67 @ CHECK: Relocations [
68 @ CHECK: 0x0 R_ARM_PREL31 .text 0x0
69 @ CHECK: 0x0 R_ARM_NONE __aeabi_unwind_cpp_pr0 0x0
70 @ CHECK: ]
71
72 @-------------------------------------------------------------------------------
73 @ The first word should be the offset to .text. The second word should be
74 @ 0xB0B0B080, which means compact model 0 is used (0x80) and the rest of the
75 @ word is filled with FINISH opcode (0xB0).
76 @-------------------------------------------------------------------------------
77 @ CHECK: SectionData (
78 @ CHECK: 0000: 00000000 B0B0B080 |........|
79 @ CHECK: )
80 @ CHECK: }
81 @ CHECK: ]
0 @ RUN: not llvm-mc -triple=armv7-unknown-linux-gnueabi < %s 2> %t
1 @ RUN: FileCheck --check-prefix=CHECK < %t %s
2
3 @ Check the diagnostics for .vsave directive
4
5 @ .vsave directive should always come after .fnstart directive
6 @ and before .handlerdata directive.
7
8 .syntax unified
9 .text
10
11 @-------------------------------------------------------------------------------
12 @ TEST1: .vsave before .fnstart
13 @-------------------------------------------------------------------------------
14 .globl func1
15 .align 2
16 .type func1,%function
17 .vsave {d0, d1, d2, d3}
18 @ CHECK: error: .fnstart must precede .save or .vsave directives
19 @ CHECK: .vsave {d0, d1, d2, d3}
20 @ CHECK: ^
21 .fnstart
22 func1:
23 .fnend
24
25
26
27 @-------------------------------------------------------------------------------
28 @ TEST2: .vsave after .handlerdata
29 @-------------------------------------------------------------------------------
30 .globl func2
31 .align 2
32 .type func2,%function
33 .fnstart
34 func2:
35 .handlerdata
36 .vsave {d0, d1, d2, d3}
37 @ CHECK: error: .save or .vsave must precede .handlerdata directive
38 @ CHECK: .vsave {d0, d1, d2, d3}
39 @ CHECK: ^
40 .fnend
0 @ RUN: llvm-mc %s -triple=armv7-unknown-linux-gnueabi -filetype=obj -o - \
1 @ RUN: | llvm-readobj -s -sd -sr | FileCheck %s
2
3 @ Check the .vsave directive
4
5 @ The .vsave directive records the VFP registers which are pushed to the
6 @ stack. There are two different opcodes:
7 @
8 @ 0xC800: pop d[(16+x+y):(16+x)] @ d[16+x+y]-d[16+x] must be consecutive
9 @ 0xC900: pop d[(x+y):x] @ d[x+y]-d[x] must be consecutive
10
11
12 .syntax unified
13
14 @-------------------------------------------------------------------------------
15 @ TEST1
16 @-------------------------------------------------------------------------------
17 .section .TEST1
18 .globl func1a
19 .align 2
20 .type func1a,%function
21 .fnstart
22 func1a:
23 .vsave {d0}
24 vpush {d0}
25 vpop {d0}
26 bx lr
27 .personality __gxx_personality_v0
28 .handlerdata
29 .fnend
30
31 .globl func1b
32 .align 2
33 .type func1b,%function
34 .fnstart
35 func1b:
36 .vsave {d0, d1, d2, d3}
37 vpush {d0, d1, d2, d3}
38 vpop {d0, d1, d2, d3}
39 bx lr
40 .personality __gxx_personality_v0
41 .handlerdata
42 .fnend
43
44 .globl func1c
45 .align 2
46 .type func1c,%function
47 .fnstart
48 func1c:
49 .vsave {d0, d1, d2, d3, d4, d5, d6, d7}
50 vpush {d0, d1, d2, d3, d4, d5, d6, d7}
51 vpop {d0, d1, d2, d3, d4, d5, d6, d7}
52 bx lr
53 .personality __gxx_personality_v0
54 .handlerdata
55 .fnend
56
57 .globl func1d
58 .align 2
59 .type func1d,%function
60 .fnstart
61 func1d:
62 .vsave {d2, d3, d4, d5, d6, d7}
63 vpush {d2, d3, d4, d5, d6, d7}
64 vpop {d2, d3, d4, d5, d6, d7}
65 bx lr
66 .personality __gxx_personality_v0
67 .handlerdata
68 .fnend
69
70 @ CHECK: Section {
71 @ CHECK: Name: .ARM.extab.TEST1
72 @ CHECK: SectionData (
73 @ CHECK: 0000: 00000000 B000C900 00000000 B003C900 |................|
74 @ CHECK: 0010: 00000000 B007C900 00000000 B025C900 |.............%..|
75 @ CHECK: )
76 @ CHECK: }
77
78
79
80 @-------------------------------------------------------------------------------
81 @ TEST2
82 @-------------------------------------------------------------------------------
83 .section .TEST2
84 .globl func2a
85 .align 2
86 .type func2a,%function
87 .fnstart
88 func2a:
89 .vsave {d16}
90 vpush {d16}
91 vpop {d16}
92 bx lr
93 .personality __gxx_personality_v0
94 .handlerdata
95 .fnend
96
97 .globl func2b
98 .align 2
99 .type func2b,%function
100 .fnstart
101 func2b:
102 .vsave {d16, d17, d18, d19}
103 vpush {d16, d17, d18, d19}
104 vpop {d16, d17, d18, d19}
105 bx lr
106 .personality __gxx_personality_v0
107 .handlerdata
108 .fnend
109
110 .globl func2c
111 .align 2
112 .type func2c,%function
113 .fnstart
114 func2c:
115 .vsave {d16, d17, d18, d19, d20, d21, d22, d23, d24, d25, d26, d27, d28, d29, d30, d31}
116 vpush {d16, d17, d18, d19, d20, d21, d22, d23, d24, d25, d26, d27, d28, d29, d30, d31}
117 vpop {d16, d17, d18, d19, d20, d21, d22, d23, d24, d25, d26, d27, d28, d29, d30, d31}
118 bx lr
119 .personality __gxx_personality_v0
120 .handlerdata
121 .fnend
122
123 @ CHECK: Section {
124 @ CHECK: Name: .ARM.extab.TEST2
125 @ CHECK: SectionData (
126 @ CHECK: 0000: 00000000 B000C800 00000000 B003C800 |................|
127 @ CHECK: 0010: 00000000 B00FC800 |........|
128 @ CHECK: )
129 @ CHECK: }