diff options
| author | Vitaly Takmazov <vitalyster@gmail.com> | 2026-01-15 20:42:51 +0300 |
|---|---|---|
| committer | Vitaly Takmazov <vitalyster@gmail.com> | 2026-01-15 20:42:51 +0300 |
| commit | a571fe7931d54c660f0d1b1fdcbc1d858fa6c502 (patch) | |
| tree | 056039f66098e1a8ef4b6544fb09d5a77f708a90 | |
| parent | 4edfbefa7562bf503966bccfc43fd3dcc202fe9e (diff) | |
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.
| -rw-r--r-- | src/codegen/codegen.c | 10 |
1 files changed, 9 insertions, 1 deletions
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, ")) "); |
