diff --git a/Units/parser-asm.r/gas-section.d/args.ctags b/Units/parser-asm.r/gas-section.d/args.ctags index 673485de14..009f16c72e 100644 --- a/Units/parser-asm.r/gas-section.d/args.ctags +++ b/Units/parser-asm.r/gas-section.d/args.ctags @@ -1,3 +1,3 @@ --sort=no --extras=+r ---fields=+rlK +--fields=+rlKe diff --git a/Units/parser-asm.r/gas-section.d/expected.tags b/Units/parser-asm.r/gas-section.d/expected.tags index ddf2345966..6a97a59c8d 100644 --- a/Units/parser-asm.r/gas-section.d/expected.tags +++ b/Units/parser-asm.r/gas-section.d/expected.tags @@ -5,5 +5,11 @@ limit input.s /^limit: .double 0.29$/;" label language:Asm roles:def .inittext input-0.s /^ .section ".inittext","ax"$/;" inputSection language:LdScript roles:destination intcall input-0.s /^ .globl intcall$/;" symbol language:LdScript inputSection:.inittext roles:def intcall input-0.s /^intcall:$/;" label language:Asm roles:def -define_ftsec input-1.s /^.macro define_ftsec name$/;" macro language:Asm roles:def +define_ftsec input-1.s /^.macro define_ftsec name$/;" macro language:Asm roles:def end:5 .head.text.\\name\\() input-1.s /^ .section ".head.text.\\name\\()","ax",@progbits$/;" inputSection language:LdScript roles:destination +.tramp.ftrace.text input-2.s /^.pushsection ".tramp.ftrace.text","aw",@progbits;$/;" inputSection language:LdScript roles:destination end:11 +ftrace_tramp_text input-2.s /^.globl ftrace_tramp_text$/;" symbol language:LdScript inputSection:.tramp.ftrace.text roles:def +ftrace_tramp_text input-2.s /^ftrace_tramp_text:$/;" label language:Asm roles:def +.tramp.ftrace.init input-2.s /^.pushsection ".tramp.ftrace.init","aw",@progbits;$/;" inputSection language:LdScript roles:destination end:17 +ftrace_tramp_init input-2.s /^.globl ftrace_tramp_init$/;" symbol language:LdScript inputSection:.tramp.ftrace.init roles:def +ftrace_tramp_init input-2.s /^ftrace_tramp_init:$/;" label language:Asm roles:def diff --git a/Units/parser-asm.r/gas-section.d/input-2.s b/Units/parser-asm.r/gas-section.d/input-2.s new file mode 100644 index 0000000000..b4fb319f49 --- /dev/null +++ b/Units/parser-asm.r/gas-section.d/input-2.s @@ -0,0 +1,18 @@ +/* Derived from linux/arch/powerpc/kernel/trace/ftrace_64_pg_entry.S */ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Split from ftrace_64.S + */ + +.pushsection ".tramp.ftrace.text","aw",@progbits; +.globl ftrace_tramp_text +ftrace_tramp_text: + .space 32 +.popsection + +.pushsection ".tramp.ftrace.init","aw",@progbits; +.globl ftrace_tramp_init +ftrace_tramp_init: + .space 32 +.popsection + diff --git a/parsers/asm.c b/parsers/asm.c index c0ad38a8b1..c95ecb085e 100644 --- a/parsers/asm.c +++ b/parsers/asm.c @@ -20,6 +20,7 @@ #include "dependency.h" #include "entry.h" #include "keyword.h" +#include "numarray.h" #include "param.h" #include "parse.h" #include "read.h" @@ -32,6 +33,8 @@ * DATA DECLARATIONS */ typedef enum { + K_PSUEDO_FOREIGN_LD_SCRIPT_POP_SECTION = -6, + K_PSUEDO_FOREIGN_LD_SCRIPT_PUSH_SECTION = -5, K_PSUEDO_FOREIGN_LD_SCRIPT_SYMBOL = -4, K_PSUEDO_FOREIGN_LD_SCRIPT_SECTION = -3, K_PSUEDO_MACRO_END = -2, @@ -53,7 +56,9 @@ typedef enum { OP_GLOBAL, OP_LABEL, OP_MACRO, + OP_POPSECTION, OP_PROC, + OP_PUSHSECTION, OP_RECORD, OP_SECTIONS, OP_SECTION, @@ -110,6 +115,8 @@ static const keywordTable AsmKeywords [] = { /* These are used in GNU as. */ { "section", OP_SECTION }, + { "pushsection", OP_PUSHSECTION }, + { "popsection", OP_POPSECTION }, { "equiv", OP_EQU }, { "eqv", OP_EQU }, @@ -131,7 +138,9 @@ static const opKind OpKinds [] = { { OP_GLOBAL, K_PSUEDO_FOREIGN_LD_SCRIPT_SYMBOL }, { OP_LABEL, K_LABEL }, { OP_MACRO, K_MACRO }, + { OP_POPSECTION, K_PSUEDO_FOREIGN_LD_SCRIPT_POP_SECTION }, { OP_PROC, K_LABEL }, + { OP_PUSHSECTION, K_PSUEDO_FOREIGN_LD_SCRIPT_PUSH_SECTION }, { OP_RECORD, K_TYPE }, { OP_SECTIONS, K_NONE }, { OP_SECTION, K_PSUEDO_FOREIGN_LD_SCRIPT_SECTION }, @@ -272,6 +281,7 @@ static int makeAsmTag ( const bool nameFollows, const bool directive, int *sectionScope, + intArray *sectionScopeStack, int *macroScope, bool useCpp) { @@ -329,10 +339,25 @@ static int makeAsmTag ( *macroScope = macro_tag->extensionFields.scopeIndex; } break; + case K_PSUEDO_FOREIGN_LD_SCRIPT_POP_SECTION: + if (intArrayCount (sectionScopeStack) > 0) + { + int top = intArrayRemoveLast (sectionScopeStack); + tagEntryInfo *section_tag = getEntryInCorkQueue (top); + if (section_tag) + setTagEndLine (section_tag, + useCpp? cppGetInputLineNumber (): getInputLineNumber ()); + if (intArrayCount (sectionScopeStack) > 0) + *sectionScope = intArrayLast (sectionScopeStack); + } + break; + case K_PSUEDO_FOREIGN_LD_SCRIPT_PUSH_SECTION: case K_PSUEDO_FOREIGN_LD_SCRIPT_SYMBOL: case K_PSUEDO_FOREIGN_LD_SCRIPT_SECTION: r = makeTagForLdScript (vStringValue (operator), kind_for_directive, sectionScope, useCpp); + if (kind_for_directive == K_PSUEDO_FOREIGN_LD_SCRIPT_PUSH_SECTION) + intArrayAdd (sectionScopeStack, *sectionScope); break; default: r = makeAsmSimpleTag (operator, kind_for_directive, useCpp); @@ -603,9 +628,11 @@ static const unsigned char *readLineViaCpp (const char *commentChars) if (str) { const char *section = strrstr (vStringValue (line), ".section"); + if (!section) + section = strrstr (vStringValue (line), ".pushsection"); if (section && isEligibleAsSectionName(str)) { - section += strlen(".section"); + section += (section[1] == 's')? strlen(".section"): strlen(".pushsection"); while (isspace((unsigned char)*section)) section++; if (*section == '\0') @@ -799,6 +826,7 @@ static void findAsmTagsCommon (bool useCpp) int sectionScope = CORK_NIL; int macroScope = CORK_NIL; + intArray *sectionScopeStack = intArrayNew (); while ((line = asmReadLineFromInputFile (commentCharsInMOL, useCpp)) != NULL) { @@ -863,7 +891,7 @@ static void findAsmTagsCommon (bool useCpp) nameFollows = true; } int r = makeAsmTag (name, operator, labelCandidate, nameFollows, directive, - §ionScope, ¯oScope, useCpp); + §ionScope, sectionScopeStack, ¯oScope, useCpp); tagEntryInfo *e = getEntryInCorkQueue (r); if (e && e->langType == Lang_asm && e->kindIndex == K_MACRO && isRoleAssigned(e, ROLE_DEFINITION_INDEX)) @@ -873,6 +901,7 @@ static void findAsmTagsCommon (bool useCpp) if (useCpp) cppTerminate (); + intArrayDelete (sectionScopeStack); vStringDelete (name); vStringDelete (operator); }