From 6944f61721b0336ddcac1f5f596640375eb36a29 Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Sun, 5 May 2024 19:30:11 -0300 Subject: [PATCH] all: add @[_linker_section] for global variable --- vlib/v/checker/checker.v | 8 ++++++++ vlib/v/gen/c/cgen.v | 3 +++ 2 files changed, 11 insertions(+) diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 82a9538a333208..6b9fab0c77597b 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -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 { diff --git a/vlib/v/gen/c/cgen.v b/vlib/v/gen/c/cgen.v index 63886b5add11e5..076aec56d7ad07 100644 --- a/vlib/v/gen/c/cgen.v +++ b/vlib/v/gen/c/cgen.v @@ -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 {