From a571fe7931d54c660f0d1b1fdcbc1d858fa6c502 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Thu, 15 Jan 2026 20:42:51 +0300 Subject: refactor: enhance cross-platform compatibility for section attributes Introduce platform-specific segment name prefixes and suffixes for `__attribute__(section)` based on operating system. On Apple systems, define `SEGMENT_NAME_PREFIX` and `SEGMENT_NAME_SUFFIX` to ensure appropriate handling of section attributes. --- src/codegen/codegen.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/codegen') diff --git a/src/codegen/codegen.c b/src/codegen/codegen.c index 91f5bb5..86295e4 100644 --- a/src/codegen/codegen.c +++ b/src/codegen/codegen.c @@ -10,6 +10,14 @@ #include "ast.h" #include "zprep_plugin.h" +#ifdef __APPLE__ +#define SEGMENT_NAME_PREFIX "__TEXT," +#define SEGMENT_NAME_SUFFIX ",regular,pure_instructions" +#else +#define SEGMENT_NAME_PREFIX "" +#define SEGMENT_NAME_SUFFIX "" +#endif + // static function for internal use. static char *g_current_func_ret_type = NULL; static void codegen_match_internal(ParserContext *ctx, ASTNode *node, FILE *out, int use_result) @@ -1367,7 +1375,7 @@ void codegen_node_single(ParserContext *ctx, ASTNode *node, FILE *out) { fprintf(out, ", "); } - fprintf(out, "section(\"%s\")", node->func.section); + fprintf(out, "section(\"%s%s%s\")", SEGMENT_NAME_PREFIX, node->func.section, SEGMENT_NAME_SUFFIX); } #undef EMIT_ATTR fprintf(out, ")) "); -- cgit v1.2.3