From ba0899d9094afe64e9271c226752857e71dab80e Mon Sep 17 00:00:00 2001 From: Stefan Date: Sun, 21 Sep 2025 14:06:59 +0200 Subject: [PATCH] tccasm.c: Make .init and .fini sections executable GAS selects default attributes for a section based on its name and makes the sections .text, .init, .fini executable. The crti.s and crtn.s files of musl rely on these defaults and don't set the "x" flag for the .init and .fini sections. Unfortunately TCC does not care for .init and .fini section defaults in assembler or C code. Fix this for assembler code. --- tccasm.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tccasm.c b/tccasm.c index f31eab5a..b6fc34e5 100644 --- a/tccasm.c +++ b/tccasm.c @@ -907,6 +907,10 @@ static void asm_parse_directive(TCCState *s1, int global) sets alignment to PTR_SIZE. The assembler behaves different. */ if (old_nb_section != s1->nb_sections) { cur_text_section->sh_addralign = 1; + /* Make .init and .fini sections executable by default. + GAS does so, too, and musl relies on it. */ + if (!strcmp(sname, ".init") || !strcmp(sname, ".fini")) + flags |= SHF_EXECINSTR; cur_text_section->sh_flags = flags; } }