Skip to content

Commit

Permalink
all: add @[_linker_section] for global variable
Browse files Browse the repository at this point in the history
  • Loading branch information
felipensp authored May 5, 2024
1 parent 58527cc commit 6944f61
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
8 changes: 8 additions & 0 deletions vlib/v/checker/checker.v
Original file line number Diff line number Diff line change
Expand Up @@ -2240,6 +2240,14 @@ fn (mut c Checker) branch_stmt(node ast.BranchStmt) {
}

fn (mut c Checker) global_decl(mut node ast.GlobalDecl) {
required_args_attr := ['_linker_section']
for attr_name in required_args_attr {
if attr := node.attrs.find_first(attr_name) {
if attr.arg == '' {
c.error('missing argument for @[${attr_name}] attribute', attr.pos)
}
}
}
for mut field in node.fields {
c.check_valid_snake_case(field.name, 'global name', field.pos)
if field.name in c.global_names {
Expand Down
3 changes: 3 additions & 0 deletions vlib/v/gen/c/cgen.v
Original file line number Diff line number Diff line change
Expand Up @@ -6095,6 +6095,9 @@ fn (mut g Gen) global_decl(node ast.GlobalDecl) {
if node.attrs.contains('export') {
attributes += 'VV_EXPORTED_SYMBOL '
}
if attr := node.attrs.find_first('_linker_section') {
attributes += '__attribute__ ((section ("${attr.arg}"))) '
}
for field in node.fields {
if g.pref.skip_unused {
if field.name !in g.table.used_globals {
Expand Down

0 comments on commit 6944f61

Please sign in to comment.