Skip to content

Commit

Permalink
LdScript,C,C++: make ref tag entries for sections in __attribute__((s…
Browse files Browse the repository at this point in the history
…ection("SECTION"))) found in C/C++ code

input.c:

  extern void f0 (void) __attribute__ ((section ("sec")));

tags:

  sec input-1.c	\
        /^extern void f0 (void) __attribute__ ((section ("sec")));$/;"	\
	kind:inputSection	line:1	language:LdScript	\
	roles:destination

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
  • Loading branch information
masatake committed Dec 17, 2023
1 parent ce196a6 commit 3d7fd14
Show file tree
Hide file tree
Showing 20 changed files with 188 additions and 24 deletions.
2 changes: 2 additions & 0 deletions Tmain/list-roles.d/stdout-expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ Julia n/module imported on loaded by "import"
Julia n/module namespace on only some symbols in it are imported
Julia n/module used on loaded by "using"
Kconfig k/kconfig source on kconfig file loaded with source directive
LdScript i/inputSection destination on specified as the destination of code and data
LdScript i/inputSection discarded on discarded when linking
LdScript i/inputSection mapped on mapped to output section
LdScript s/symbol entrypoint on entry points
Expand Down Expand Up @@ -204,6 +205,7 @@ Julia n/module imported on loaded by "import"
Julia n/module namespace on only some symbols in it are imported
Julia n/module used on loaded by "using"
Kconfig k/kconfig source on kconfig file loaded with source directive
LdScript i/inputSection destination on specified as the destination of code and data
LdScript i/inputSection discarded on discarded when linking
LdScript i/inputSection mapped on mapped to output section
LdScript s/symbol entrypoint on entry points
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
--sort=no
--kinds-C=+p
--param-CPreProcessor._expand=1
--fields-C=+{section}{macrodef}
--fields=+S
--fields=+rl
--extras=+r
--languages=-LdScript
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
f input.c /^char f [] __attribute__((section("__ksymtab_strings"), used, aligned(1)));$/;" v language:C typeref:typename:char[] roles:def section:__ksymtab_strings
a input.c /^struct duart a __attribute__ ((section ("DUART_A"))) = { 0 };$/;" v language:C typeref:struct:duart roles:def section:DUART_A
b input.c /^struct duart b __attribute__ ((section ("DUART_B"))) = { 0 };$/;" v language:C typeref:struct:duart roles:def section:DUART_B
stack input.c /^char stack[10000] __attribute__ ((section ("STACK"))) = { 0 };$/;" v language:C typeref:typename:char[10000] roles:def section:STACK
init_data input.c /^int init_data __attribute__ ((section ("INITDATA")));$/;" v language:C typeref:typename:int roles:def section:INITDATA
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/* Variables */
char f [] __attribute__((section("__ksymtab_strings"), used, aligned(1)));

/* Taken form gcc's info document. */
struct duart a __attribute__ ((section ("DUART_A"))) = { 0 };
struct duart b __attribute__ ((section ("DUART_B"))) = { 0 };
char stack[10000] __attribute__ ((section ("STACK"))) = { 0 };
int init_data __attribute__ ((section ("INITDATA")));
2 changes: 1 addition & 1 deletion Units/parser-cxx.r/attribute-sections.cpp.d/args.ctags
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
--param-CPreProcessor._expand=1
--fields-C=+{section}{macrodef}
--fields=+S
--fields=+r
--fields=+rl
--extras=+r
57 changes: 37 additions & 20 deletions Units/parser-cxx.r/attribute-sections.cpp.d/expected.tags
Original file line number Diff line number Diff line change
@@ -1,20 +1,37 @@
f input.c /^char f [] __attribute__((section("__ksymtab_strings"), used, aligned(1)));$/;" v typeref:typename:char[] roles:def section:__ksymtab_strings
a input.c /^struct duart a __attribute__ ((section ("DUART_A"))) = { 0 };$/;" v typeref:struct:duart roles:def section:DUART_A
b input.c /^struct duart b __attribute__ ((section ("DUART_B"))) = { 0 };$/;" v typeref:struct:duart roles:def section:DUART_B
stack input.c /^char stack[10000] __attribute__ ((section ("STACK"))) = { 0 };$/;" v typeref:typename:char[10000] roles:def section:STACK
init_data input.c /^int init_data __attribute__ ((section ("INITDATA")));$/;" v typeref:typename:int roles:def section:INITDATA
COMMAND_LINE_SIZE input-0.c /^#define COMMAND_LINE_SIZE /;" d file: roles:def macrodef:127
__section input-0.c /^#define __section(section) __attribute__((__section_/;" d file: signature:(section) roles:def macrodef:__attribute__((__section__(section)))
__initdata input-0.c /^#define __initdata /;" d file: roles:def macrodef:__section(".init.data")
b0 input-0.c /^char __initdata b0[COMMAND_LINE_SIZE];$/;" v typeref:typename:char[127] roles:def section:.init.data
b1 input-0.c /^char b1[COMMAND_LINE_SIZE] __initdata;$/;" v typeref:typename:char[127] roles:def section:.init.data
f0 input-1.c /^extern void f0 (void) __attribute__ ((section ("bar0p")));$/;" p typeref:typename:void file: signature:(void) roles:def section:bar0p
f0 input-1.c /^void f0 (void) __attribute__ ((section ("bar0")))$/;" f typeref:typename:void signature:(void) roles:def section:bar0
f1 input-1.c /^extern void __attribute__ ((section ("bar1p"))) f1 (void);$/;" p typeref:typename:void file: signature:(void) roles:def section:bar1p
f1 input-1.c /^void __attribute__ ((section ("bar1"))) f1 (void)$/;" f typeref:typename:void signature:(void) roles:def section:bar1
f2 input-1.c /^extern __attribute__ ((section ("bar2p"))) void f2 (void);$/;" p typeref:typename:void file: signature:(void) roles:def section:bar2p
f2 input-1.c /^__attribute__ ((section ("bar2"))) void f2 (void)$/;" f typeref:typename:void signature:(void) roles:def section:bar2
f3 input-1.c /^__attribute__ ((section ("bar3p"))) extern void f3 (void);$/;" p typeref:typename:void file: signature:(void) roles:def section:bar3p
f3 input-1.c /^__attribute__ ((section ("bar3"))) extern void f3 (void)$/;" f typeref:typename:void signature:(void) roles:def section:bar3
f4 input-1.c /^__attribute__ ((section ("bar4p"))) static void f4 (void);$/;" p typeref:typename:void file: signature:(void) roles:def section:bar4p
f4 input-1.c /^__attribute__ ((section ("bar4"))) static void f4 (void)$/;" f typeref:typename:void file: signature:(void) roles:def section:bar4
__ksymtab_strings input.c /^char f [] __attribute__((section("__ksymtab_strings"), used, aligned(1)));$/;" i language:LdScript roles:destination
f input.c /^char f [] __attribute__((section("__ksymtab_strings"), used, aligned(1)));$/;" v language:C typeref:typename:char[] roles:def section:__ksymtab_strings
DUART_A input.c /^struct duart a __attribute__ ((section ("DUART_A"))) = { 0 };$/;" i language:LdScript roles:destination
a input.c /^struct duart a __attribute__ ((section ("DUART_A"))) = { 0 };$/;" v language:C typeref:struct:duart roles:def section:DUART_A
DUART_B input.c /^struct duart b __attribute__ ((section ("DUART_B"))) = { 0 };$/;" i language:LdScript roles:destination
b input.c /^struct duart b __attribute__ ((section ("DUART_B"))) = { 0 };$/;" v language:C typeref:struct:duart roles:def section:DUART_B
STACK input.c /^char stack[10000] __attribute__ ((section ("STACK"))) = { 0 };$/;" i language:LdScript roles:destination
stack input.c /^char stack[10000] __attribute__ ((section ("STACK"))) = { 0 };$/;" v language:C typeref:typename:char[10000] roles:def section:STACK
INITDATA input.c /^int init_data __attribute__ ((section ("INITDATA")));$/;" i language:LdScript roles:destination
init_data input.c /^int init_data __attribute__ ((section ("INITDATA")));$/;" v language:C typeref:typename:int roles:def section:INITDATA
COMMAND_LINE_SIZE input-0.c /^#define COMMAND_LINE_SIZE /;" d language:C file: roles:def macrodef:127
__section input-0.c /^#define __section(section) __attribute__((__section_/;" d language:C file: signature:(section) roles:def macrodef:__attribute__((__section__(section)))
__initdata input-0.c /^#define __initdata /;" d language:C file: roles:def macrodef:__section(".init.data")
.init.data input-0.c /^char __initdata b0[COMMAND_LINE_SIZE];$/;" i language:LdScript roles:destination
b0 input-0.c /^char __initdata b0[COMMAND_LINE_SIZE];$/;" v language:C typeref:typename:char[127] roles:def section:.init.data
.init.data input-0.c /^char b1[COMMAND_LINE_SIZE] __initdata;$/;" i language:LdScript roles:destination
b1 input-0.c /^char b1[COMMAND_LINE_SIZE] __initdata;$/;" v language:C typeref:typename:char[127] roles:def section:.init.data
bar0p input-1.c /^extern void f0 (void) __attribute__ ((section ("bar0p")));$/;" i language:LdScript roles:destination
f0 input-1.c /^extern void f0 (void) __attribute__ ((section ("bar0p")));$/;" p language:C typeref:typename:void file: signature:(void) roles:def section:bar0p
bar0 input-1.c /^{$/;" i language:LdScript roles:destination
f0 input-1.c /^void f0 (void) __attribute__ ((section ("bar0")))$/;" f language:C typeref:typename:void signature:(void) roles:def section:bar0
bar1p input-1.c /^extern void __attribute__ ((section ("bar1p"))) f1 (void);$/;" i language:LdScript roles:destination
f1 input-1.c /^extern void __attribute__ ((section ("bar1p"))) f1 (void);$/;" p language:C typeref:typename:void file: signature:(void) roles:def section:bar1p
bar1 input-1.c /^{$/;" i language:LdScript roles:destination
f1 input-1.c /^void __attribute__ ((section ("bar1"))) f1 (void)$/;" f language:C typeref:typename:void signature:(void) roles:def section:bar1
bar2p input-1.c /^extern __attribute__ ((section ("bar2p"))) void f2 (void);$/;" i language:LdScript roles:destination
f2 input-1.c /^extern __attribute__ ((section ("bar2p"))) void f2 (void);$/;" p language:C typeref:typename:void file: signature:(void) roles:def section:bar2p
bar2 input-1.c /^{$/;" i language:LdScript roles:destination
f2 input-1.c /^__attribute__ ((section ("bar2"))) void f2 (void)$/;" f language:C typeref:typename:void signature:(void) roles:def section:bar2
bar3p input-1.c /^__attribute__ ((section ("bar3p"))) extern void f3 (void);$/;" i language:LdScript roles:destination
f3 input-1.c /^__attribute__ ((section ("bar3p"))) extern void f3 (void);$/;" p language:C typeref:typename:void file: signature:(void) roles:def section:bar3p
bar3 input-1.c /^{$/;" i language:LdScript roles:destination
f3 input-1.c /^__attribute__ ((section ("bar3"))) extern void f3 (void)$/;" f language:C typeref:typename:void signature:(void) roles:def section:bar3
bar4p input-1.c /^__attribute__ ((section ("bar4p"))) static void f4 (void);$/;" i language:LdScript roles:destination
f4 input-1.c /^__attribute__ ((section ("bar4p"))) static void f4 (void);$/;" p language:C typeref:typename:void file: signature:(void) roles:def section:bar4p
bar4 input-1.c /^{$/;" i language:LdScript roles:destination
f4 input-1.c /^__attribute__ ((section ("bar4"))) static void f4 (void)$/;" f language:C typeref:typename:void file: signature:(void) roles:def section:bar4
1 change: 1 addition & 0 deletions docs/man-pages.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Man pages
ctags-lang-javascript(7) <man/ctags-lang-javascript.7.rst>
ctags-lang-julia(7) <man/ctags-lang-julia.7.rst>
ctags-lang-kconfig(7) <man/ctags-lang-kconfig.7.rst>
ctags-lang-ldscript(7) <man/ctags-lang-ldscript.7.rst>
ctags-lang-markdown(7) <man/ctags-lang-markdown.7.rst>
ctags-lang-python(7) <man/ctags-lang-python.7.rst>
ctags-lang-r(7) <man/ctags-lang-r.7.rst>
Expand Down
1 change: 1 addition & 0 deletions docs/man/ctags-lang-c++.7.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@ Change since "0.0"
SEE ALSO
--------
:ref:`ctags(1) <ctags(1)>`,
:ref:`ctags-lang-ldscript(7) <ctags-lang-ldscript(7)>`,
`The new C/C++ parser <https://docs.ctags.io/en/latest/parser-cxx.html>`_ (https://docs.ctags.io/en/latest/parser-cxx.html)
1 change: 1 addition & 0 deletions docs/man/ctags-lang-c.7.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@ Change since "0.0"
SEE ALSO
--------
:ref:`ctags(1) <ctags(1)>`,
:ref:`ctags-lang-ldscript(7) <ctags-lang-ldscript(7)>`,
`The new C/C++ parser <https://docs.ctags.io/en/latest/parser-cxx.html>`_ (https://docs.ctags.io/en/latest/parser-cxx.html)
1 change: 1 addition & 0 deletions docs/man/ctags-lang-cuda.7.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ Change since "0.0"
SEE ALSO
--------
:ref:`ctags(1) <ctags(1)>`,
:ref:`ctags-lang-ldscript(7) <ctags-lang-ldscript(7)>`,
`The new C/C++ parser <https://docs.ctags.io/en/latest/parser-cxx.html>`_ (https://docs.ctags.io/en/latest/parser-cxx.html)
37 changes: 37 additions & 0 deletions docs/man/ctags-lang-ldscript.7.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
.. _ctags-lang-ldscript(7):

==============================================================
ctags-lang-ldscript
==============================================================

Random notes about tagging LdScript source code with Universal Ctags

:Version: 6.0.0
:Manual group: Universal Ctags
:Manual section: 7

SYNOPSIS
--------
| **ctags** ... --languages=+LdScript ...
| **ctags** ... --language-force=LdScript ...
| **ctags** ... --map-LdScript=+.lds ...
| **ctags** ... --map-LdScript=+.lds.S ...
DESCRIPTION
-----------
This man page gathers random notes about tagging LdScript source code.

VERSIONS
--------

Change since "0.0"
~~~~~~~~~~~~~~~~~~

* New role ``destination`` for ``inputSection`` kind

SEE ALSO
--------
:ref:`ctags(1) <ctags(1)>`,
:ref:`ctags-lang-c(7) <ctags-lang-c(7)>`,
:ref:`ctags-lang-c++(7) <ctags-lang-c++(7)>`,
:ref:`ctags-lang-cuda(7) <ctags-lang-cuda(7)>`
4 changes: 4 additions & 0 deletions docs/news/HEAD.rst
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ Changes about parser specific kinds, roles, fields, and extras

+ New kind `variable`

* LdScript

+ New role `destination` for `inputSection` kind

* Markdown

+ New kind `hashtag`
Expand Down
1 change: 1 addition & 0 deletions man/GNUmakefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ GEN_IN_MAN_FILES = \
ctags-lang-javascript.7 \
ctags-lang-julia.7 \
ctags-lang-kconfig.7 \
ctags-lang-ldscript.7 \
ctags-lang-markdown.7 \
ctags-lang-python.7 \
ctags-lang-r.7 \
Expand Down
1 change: 1 addition & 0 deletions man/ctags-lang-c++.7.rst.in
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@ Change since "0.0"
SEE ALSO
--------
ctags(1),
ctags-lang-ldscript(7),
`The new C/C++ parser <https://docs.ctags.io/en/latest/parser-cxx.html>`_ (https://docs.ctags.io/en/latest/parser-cxx.html)
1 change: 1 addition & 0 deletions man/ctags-lang-c.7.rst.in
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@ Change since "0.0"
SEE ALSO
--------
ctags(1),
ctags-lang-ldscript(7),
`The new C/C++ parser <https://docs.ctags.io/en/latest/parser-cxx.html>`_ (https://docs.ctags.io/en/latest/parser-cxx.html)
1 change: 1 addition & 0 deletions man/ctags-lang-cuda.7.rst.in
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ Change since "0.0"
SEE ALSO
--------
ctags(1),
ctags-lang-ldscript(7),
`The new C/C++ parser <https://docs.ctags.io/en/latest/parser-cxx.html>`_ (https://docs.ctags.io/en/latest/parser-cxx.html)
37 changes: 37 additions & 0 deletions man/ctags-lang-ldscript.7.rst.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
.. _ctags-lang-ldscript(7):

==============================================================
ctags-lang-ldscript
==============================================================
---------------------------------------------------------------------
Random notes about tagging LdScript source code with Universal Ctags
---------------------------------------------------------------------
:Version: @VERSION@
:Manual group: Universal Ctags
:Manual section: 7

SYNOPSIS
--------
| **@CTAGS_NAME_EXECUTABLE@** ... --languages=+LdScript ...
| **@CTAGS_NAME_EXECUTABLE@** ... --language-force=LdScript ...
| **@CTAGS_NAME_EXECUTABLE@** ... --map-LdScript=+.lds ...
| **@CTAGS_NAME_EXECUTABLE@** ... --map-LdScript=+.lds.S ...

DESCRIPTION
-----------
This man page gathers random notes about tagging LdScript source code.

VERSIONS
--------

Change since "0.0"
~~~~~~~~~~~~~~~~~~

* New role ``destination`` for ``inputSection`` kind

SEE ALSO
--------
ctags(1),
ctags-lang-c(7),
ctags-lang-c++(7),
ctags-lang-cuda(7)
7 changes: 7 additions & 0 deletions parsers/cxx/cxx.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ parserDefinition * CParser (void)

static selectLanguage selectors[] = { selectByObjectiveCKeywords, NULL };

static parserDependency dependencies [] = {
[0] = { DEPTYPE_FOREIGNER, "LdScript", NULL },
};

parserDefinition* def = parserNew("C");

def->kindTable = cxxTagGetCKindDefinitions();
Expand All @@ -93,6 +97,8 @@ parserDefinition * CParser (void)
def->initialize = cxxCParserInitialize;
def->finalize = cxxParserCleanup;
def->selectLanguage = selectors;
def->dependencies = dependencies;
def->dependencyCount = ARRAY_SIZE (dependencies);
def->useCork = CORK_QUEUE|CORK_SYMTAB; // We use corking to block output until the end of file

def->versionCurrent = 1;
Expand All @@ -114,6 +120,7 @@ parserDefinition * CppParser (void)
};
static parserDependency dependencies [] = {
{ DEPTYPE_KIND_OWNER, "C" },
{ DEPTYPE_FOREIGNER, "LdScript", NULL },
};

static selectLanguage selectors[] = { selectByObjectiveCKeywords, NULL };
Expand Down
30 changes: 28 additions & 2 deletions parsers/cxx/cxx_side_chain.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,34 @@ static void cxxScanAttrExtractSection(const CXXToken * pToken)

Assert(vStringLength(pArgToken->pszWord));

// Remove doubule quote characters surrounding the constant string.
vStringChop(pArgToken->pszWord);
cxxTagSetField(CXXTagFieldSection, vStringValue(pArgToken->pszWord)+1, true);

tagEntryInfo e;
static langType lang = LANG_AUTO;

if(lang == LANG_AUTO)
lang = getNamedLanguage("LdScript", 0);
if(lang == LANG_IGNORE)
goto out;

static kindDefinition * kdef = NULL;
if(kdef == NULL)
kdef = getLanguageKindForName (lang, "inputSection");
if(kdef == NULL)
goto out;

static roleDefinition *rdef = NULL;
if(rdef == NULL)
rdef = getLanguageRoleForName (lang, kdef->id, "destination");
if(rdef == NULL)
goto out;

initForeignRefTagEntry(&e, vStringValue(pArgToken->pszWord)+1,
lang, kdef->id, rdef->id);
makeTagEntry(&e);

out:
vStringPut(pArgToken->pszWord, '"');
}

Expand All @@ -63,7 +88,8 @@ static void cxxScanAttributes(const CXXTokenChain * pAttrChain)
return;

CXXToken * t = pAttrChain->pHead;
bool bSection = cxxTagFieldEnabled(CXXTagFieldSection);
bool bSection = cxxTagFieldEnabled(CXXTagFieldSection)
&& (cxxParserCurrentLanguageIsC() || cxxParserCurrentLanguageIsCPP());

while(t)
{
Expand Down
7 changes: 6 additions & 1 deletion parsers/ldscript.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,13 @@ static roleDefinition LdScriptSymbolRoles [] = {
typedef enum {
LD_SCRIPT_INPUT_SECTION_MAPPED,
LD_SCRIPT_INPUT_SECTION_DISCARDED,
LD_SCRIPT_INPUT_SECTION_DESTINATION,
} ldScriptInputSectionRole;

static roleDefinition LdScriptInputSectionRoles [] = {
{ true, "mapped", "mapped to output section" },
{ true, "discarded", "discarded when linking" },
{ true, "destination", "specified as the destination of code and data" },
};

typedef enum {
Expand All @@ -58,7 +60,7 @@ static kindDefinition LdScriptKinds [] = {
.referenceOnly = false, ATTACH_ROLES(LdScriptSymbolRoles)},
{ true, 'v', "version", "versions" },
{ true, 'i', "inputSection", "input sections",
.referenceOnly = true, ATTACH_ROLES(LdScriptInputSectionRoles)},
.referenceOnly = false, ATTACH_ROLES(LdScriptInputSectionRoles)},
};

enum {
Expand Down Expand Up @@ -914,5 +916,8 @@ extern parserDefinition* LdScriptParser (void)

def->useCork = CORK_QUEUE|CORK_SYMTAB;

def->versionCurrent = 1;
def->versionAge = 1;

return def;
}

0 comments on commit 3d7fd14

Please sign in to comment.