Skip to content

Asm: extract section from .pushsection directive #4216

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Units/parser-asm.r/gas-section.d/args.ctags
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
--sort=no
--extras=+r
--fields=+rlK
--fields=+rlKe
8 changes: 7 additions & 1 deletion Units/parser-asm.r/gas-section.d/expected.tags
Original file line number Diff line number Diff line change
Expand Up @@ -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
18 changes: 18 additions & 0 deletions Units/parser-asm.r/gas-section.d/input-2.s
Original file line number Diff line number Diff line change
@@ -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

33 changes: 31 additions & 2 deletions parsers/asm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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,
Expand All @@ -53,7 +56,9 @@
OP_GLOBAL,
OP_LABEL,
OP_MACRO,
OP_POPSECTION,
OP_PROC,
OP_PUSHSECTION,
OP_RECORD,
OP_SECTIONS,
OP_SECTION,
Expand Down Expand Up @@ -110,6 +115,8 @@

/* These are used in GNU as. */
{ "section", OP_SECTION },
{ "pushsection", OP_PUSHSECTION },
{ "popsection", OP_POPSECTION },
{ "equiv", OP_EQU },
{ "eqv", OP_EQU },

Expand All @@ -131,7 +138,9 @@
{ 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 },
Expand Down Expand Up @@ -272,6 +281,7 @@
const bool nameFollows,
const bool directive,
int *sectionScope,
intArray *sectionScopeStack,
int *macroScope,
bool useCpp)
{
Expand Down Expand Up @@ -329,10 +339,25 @@
*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);

Check warning on line 351 in parsers/asm.c

View check run for this annotation

Codecov / codecov/patch

parsers/asm.c#L351

Added line #L351 was not covered by tests
}
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);
Expand Down Expand Up @@ -603,9 +628,11 @@
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')
Expand Down Expand Up @@ -799,6 +826,7 @@

int sectionScope = CORK_NIL;
int macroScope = CORK_NIL;
intArray *sectionScopeStack = intArrayNew ();

while ((line = asmReadLineFromInputFile (commentCharsInMOL, useCpp)) != NULL)
{
Expand Down Expand Up @@ -863,7 +891,7 @@
nameFollows = true;
}
int r = makeAsmTag (name, operator, labelCandidate, nameFollows, directive,
&sectionScope, &macroScope, useCpp);
&sectionScope, sectionScopeStack, &macroScope, useCpp);
tagEntryInfo *e = getEntryInCorkQueue (r);
if (e && e->langType == Lang_asm
&& e->kindIndex == K_MACRO && isRoleAssigned(e, ROLE_DEFINITION_INDEX))
Expand All @@ -873,6 +901,7 @@
if (useCpp)
cppTerminate ();

intArrayDelete (sectionScopeStack);
vStringDelete (name);
vStringDelete (operator);
}
Expand Down
Loading