Quickly bisected tcc for mentioned regressions and could spot the related changes:
commit-id 5675177b7fa3d8e4de935c80834ef672a25621f2 which caused problem (1) with macro-expansion in *.S assembly files commit-id 64552b3faa39ee7948a9ea21bfcc11045b90c70d which caused i386-tcc to crash (2) reproducibly when compiling linux-tcc kernel Attached are two hotfix patches which revert related changes and latest i386-tcc mob/HEAD as of today passed initial acceptance testing again. @grishka please review and feel free to apply because myself cannot inspect tcc internals in detail further at this point. Please note myself can test i386-tcc only with tinycc/OS port, and no other ARCH (http://tinyfront.mooo.com/docs.html) Greetings Michael On 2026-11-19 18:12, Michael Ackermann wrote: > Hi, > > some time in between: > Dec 17 2025 commit 34eed88a70fc8238cd5b623cc96b8bf0e40392ed (OK) > and latest > Oct 16 2026 commit e23dabed154a8495f3ac1ff3cc9d04fa1c207893 (FAIL) > > A somewhat severe regression seems to have been introduced, > confirmed with i386-tcc when compiling https://codeberg.org/aggi/linux-tcc > with contained Kbuild.sh script: > > 1) while compiling with Kbuild.sh/CC|AS=i386-tcc > linux-tcc.git/usr/src/linux/arch/i386/kernel/entry.S:141: error: register > expected > -> In this case the macro expansion for SAVE_ALL seems to fail, which did work > until Dec 2025 with a functional linux kernel emitted. > > 2) while compiling with Kbuild.sh/CC=i386-tcc > linux-tcc.git/usr/src/linux/arch/i386/kernel/acpi.c > Segmentation fault (core dumped) > -> In this case compiling mentioned c source crashes tcc > > I cannot rule out any side-effects of my local development setup, > but i386-tcc did work flawlessly until Dec 2025 emitting kernel (AS and CC) > and too processing a complete userspace of ~500builds here was fine: > http://tinyfront.mooo.com/downloads/x86-embedded/666666/tinyfront-packages.list > > Strangely when compiling such complete userspace with most recent tcc version > no irregularities were spotted and those userspace pieces passed initial > runtime testing today, but all of the sudden Kbuild.sh errors when trying > to re-build kernel. I can only reliably isolate the problem to the recent > git-pull of latest tcc sources. > > Bisecting accross a hundred commits might take a while, so i rather ask for > confirmation from tinycc-devel if any issue is known already. > Please let me know if there is an easy fix for this before i begin bisecting > for hours and days. > > Question: had there been any issues to run Kbuild.sh yourself for some > quick testing when pushing commits to mob? I mean, kernel build finishes > quickly and it's too easily booted inside some VM to see if it's working. > A most valuable test-case for i386-tcc at least more than once already. > > Side notes: > I too would be curious when this problem was introduced, because i did not > do regular nightly builds and git-pull once a year only since i do > maintain another 500ebuilds for tcc already, and too began re-factoring > https://codeberg.org/aggi/tiny-bootstrap for a complete system-bootstrap > of tinycc mob/HEAD (with plans to add the missing kernel piece until december > this year for a bootstrapped linux-tcc/busybox/vi/i386-tcc live.iso released) > For this i too managed to cut short the dependency graph of bootloader > compilation of some older syslinux/isolinux.asm with i386-tcc/yasm toolchain > already (see tiny-bootstrap/steps-tiny/syslinux-3.86 if you wish) > Furthermore i intended to re-base some pnut-cc related patchset onto latest > mob/HEAD for the bootstrapping stages of tcc, and i would prefer to do > it with a known good working state of tcc itself, hence my worries expressed a > while ago on tinycc-devel tcc might become destablized, > which it seems it slightly did blocking progress on mob branch currently. > > Thank You. > > -- > Michael Ackermann > --
this patch fixes regression (1) caused by commit id 5675177b7fa3d8e4de935c80834ef672a25621f2 linux-tcc.git/usr/src/linux/arch/i386/kernel/entry.S:141: error: register expected caused by failed macro expansion for SAVE_ALL #define side effects of this change are unknown but i386-tcc behaved without it https://lists.nongnu.org/archive/html/tinycc-devel/2026-11/msg00006.html 2026-11-19 aggi diff --git a/tccpp.c b/tccpp.c index 269b3b41..f4469538 100644 --- a/tccpp.c +++ b/tccpp.c @@ -3712,7 +3712,7 @@ ST_FUNC void preprocess_start(TCCState *s1, int filetype) s1->pack_stack[0] = 0; s1->pack_stack_ptr = s1->pack_stack; - set_idnum('$', s1->dollars_in_identifiers ? IS_ID : 0); + set_idnum('$', !is_asm && s1->dollars_in_identifiers ? IS_ID : 0); set_idnum('.', is_asm ? IS_ID : 0); if (!(filetype & AFF_TYPE_ASM)) {
this patch fixes regression (2) caused by commit id 64552b3faa39ee7948a9ea21bfcc11045b90c70d i386-tcc crashes with a core-dump reproducibly when compiling various linux-tcc kernel sources root cause of this is unknown and related changes are reverted https://lists.nongnu.org/archive/html/tinycc-devel/2026-11/msg00006.html 2026-11-19 aggi diff --git a/tcc.h b/tcc.h index 0840f44f..496ecfb5 100644 --- a/tcc.h +++ b/tcc.h @@ -675,7 +675,6 @@ typedef struct AttributeDef { int alias_target; /* token */ int asm_label; /* associated asm label */ char attr_mode; /* __attribute__((__mode__(...))) */ - char new_section; /* section is new */ } AttributeDef; /* inline functions */ diff --git a/tccelf.c b/tccelf.c index 9e2d1364..c81161dc 100644 --- a/tccelf.c +++ b/tccelf.c @@ -750,13 +750,13 @@ ST_FUNC int set_elf_sym(Section *s, addr_t value, unsigned long size, /* keep first-found weak definition, ignore subsequents */ } else if (sym_vis == STV_HIDDEN || sym_vis == STV_INTERNAL) { /* ignore hidden symbols after */ - } else if (s->sh_flags & SHF_DYNSYM) { - /* we accept that two DLL define the same symbol */ } else if (!IS_BSS(s1, shndx) && IS_BSS(s1, esym->st_shndx)) { /* data symbol gets precedence over common/bss */ goto do_patch; } else if (IS_BSS(s1, shndx)) { /* data symbol keeps precedence over common/bss */ + } else if (s->sh_flags & SHF_DYNSYM) { + /* we accept that two DLL define the same symbol */ } else if (esym->st_other & ST_ASM_SET) { /* If the existing symbol came from an asm .set we can override. */ @@ -766,7 +766,7 @@ ST_FUNC int set_elf_sym(Section *s, addr_t value, unsigned long size, printf("new_bind=%x new_shndx=%x new_vis=%x old_bind=%x old_shndx=%x old_vis=%x\n", sym_bind, shndx, new_vis, esym_bind, esym->st_shndx, esym_vis); #endif - tcc_error_noabort("link symbol '%s' defined twice", name); + tcc_error_noabort("'%s' defined twice", name); } } else { esym->st_other = other; @@ -1565,6 +1565,94 @@ ST_FUNC int set_global_sym(TCCState *s1, const char *name, Section *sec, addr_t ELFW(ST_INFO)(name ? STB_GLOBAL : STB_LOCAL, STT_NOTYPE), 0, shn, name); } +#ifndef ELF_OBJ_ONLY +static int set_linker_sym(TCCState *s1, const char *name, + Section *sec, addr_t offs) +{ + int sym_index = find_elf_sym(symtab_section, name); + ElfW(Sym) *sym = sym_index + ? &((ElfW(Sym) *)symtab_section->data)[sym_index] : NULL; + /* Mirror the set_elf_sym cases where the new definition wins. */ + int is_linker_sym = !sym || sym->st_shndx == SHN_UNDEF + || ELFW(ST_BIND)(sym->st_info) == STB_WEAK + || (sec && sec != bss_section + && ((sym->st_other & ST_ASM_SET) + || sym->st_shndx == SHN_COMMON + || sym->st_shndx == bss_section->sh_num)); + + sym_index = set_global_sym(s1, name, sec, offs); + if (is_linker_sym) + get_sym_attr(s1, sym_index, 1)->linker_sym = 1; + return sym_index; +} + +static void provide_linker_sym(TCCState *s1, const char *name, + Section *sec, addr_t offs) +{ + int sym_index = find_elf_sym(symtab_section, name); + + if (sym_index) { + if (((ElfW(Sym) *)symtab_section->data)[sym_index].st_shndx != SHN_UNDEF) + return; + } else if (!s1->dynsymtab_section + || !find_elf_sym(s1->dynsymtab_section, name)) { + return; + } + set_linker_sym(s1, name, sec, offs); +} + +static void update_linker_sym(TCCState *s1, const char *name, + Section *sec, addr_t offs) +{ + int sym_index = find_elf_sym(symtab_section, name); + + if (sym_index && sym_index < s1->nb_sym_attrs + && s1->sym_attrs[sym_index].linker_sym) { + ElfW(Sym) *sym = &((ElfW(Sym) *)symtab_section->data)[sym_index]; + + sym->st_value = offs; + sym->st_shndx = sec->sh_num; + if (s1->dynsym) { + sym_index = find_elf_sym(s1->dynsym, name); + if (sym_index) { + sym = &((ElfW(Sym) *)s1->dynsym->data)[sym_index]; + sym->st_value = offs; + sym->st_shndx = sec->sh_num; + } + } + } +} + +static void finalize_linker_symbols(TCCState *s1, int *sec_order) +{ + Section *etext = text_section; + Section *edata = data_section; + Section *end = bss_section; + Section *s; + int i; + + /* Follow the final loadable-section order rather than assuming that + .text, .data and .bss are the last sections of their regions. */ + for (i = 1; i < s1->nb_sections; ++i) { + s = s1->sections[sec_order[i]]; + if (!(s->sh_flags & SHF_ALLOC)) + continue; + end = s; + if (!(s->sh_flags & SHF_WRITE)) + etext = s; + if (s->sh_type != SHT_NOBITS) + edata = s; + } + + update_linker_sym(s1, "_etext", etext, etext->sh_size); + update_linker_sym(s1, "etext", etext, etext->sh_size); + update_linker_sym(s1, "_edata", edata, edata->sh_size); + update_linker_sym(s1, "edata", edata, edata->sh_size); + update_linker_sym(s1, "_end", end, end->sh_size); + update_linker_sym(s1, "end", end, end->sh_size); +} +#endif + static void add_init_array_defines(TCCState *s1, const char *section_name) { Section *s; @@ -1885,39 +1973,6 @@ ST_FUNC void tcc_add_runtime(TCCState *s1) } #endif /* ndef TCC_TARGET_PE */ -/* set _etext/_edata/_end f=0:set f=1:when_needed f=2,3:just_update */ -static void set_linker_sym(TCCState *s1, const char *name, Section *sec, int f) -{ - int sym_index, esym_index, defined; - ElfW(Sym) *sym, *esym; - sym_index = find_elf_sym(symtab_section, name); - sym = (ElfW(Sym) *)symtab_section->data + sym_index; - esym_index = find_elf_sym(s1->dynsymtab_section, name); - esym = (ElfW(Sym) *)s1->dynsymtab_section->data + esym_index; - defined = sym->st_shndx != SHN_UNDEF - || (esym->st_shndx != SHN_UNDEF && esym->st_size); - switch (f) { - case 1: /* old symbols w/o '_' */ - if (!(sym_index || esym_index) || defined) - break; - case 0: - if (defined) { - tcc_warning("linker symbol '%s' already defined", name); - break; - } - sym_index = set_global_sym(s1, name, sec, -1); - get_sym_attr(s1, sym_index, 1)->linker_sym = 1; - break; - default: /* update (bss only) */ - if (get_sym_attr(s1, sym_index, 0)->linker_sym) - sym->st_value = sec->data_offset; - } -#ifndef ELF_OBJ_ONLY - if (name[0] == '_') - set_linker_sym(s1, name + 1, sec, f + 1); -#endif -} - /* add various standard linker symbols (must be done after the sections are filled (for example after allocating common symbols)) */ @@ -1927,13 +1982,22 @@ static void tcc_add_linker_symbols(TCCState *s1) int i; Section *s; - set_linker_sym(s1, "_etext", text_section, 0); - set_linker_sym(s1, "_edata", data_section, 0); - set_linker_sym(s1, "_end", bss_section, 0); +#ifndef ELF_OBJ_ONLY + set_linker_sym(s1, "_etext", text_section, -1); + set_linker_sym(s1, "_edata", data_section, -1); + set_linker_sym(s1, "_end", bss_section, -1); + /* These conventional ELF symbols have PROVIDE semantics. */ + provide_linker_sym(s1, "etext", text_section, -1); + provide_linker_sym(s1, "edata", data_section, -1); + provide_linker_sym(s1, "end", bss_section, -1); +#else + set_global_sym(s1, "_etext", text_section, -1); + set_global_sym(s1, "_edata", data_section, -1); + set_global_sym(s1, "_end", bss_section, -1); +#endif #if TARGETOS_OpenBSD set_global_sym(s1, "__executable_start", NULL, ELF_START_ADDR); #endif - #ifdef TCC_TARGET_RISCV64 /* XXX should be .sdata+0x800, not .data+0x800 */ set_global_sym(s1, "__global_pointer$", data_section, 0x800); @@ -1978,7 +2042,7 @@ ST_FUNC void resolve_common_syms(TCCState *s1) /* Allocate common symbols in BSS. */ for_each_elem(symtab_section, 1, sym, ElfW(Sym)) { - if (sym->st_shndx == SHN_COMMON && sym->st_size) { + if (sym->st_shndx == SHN_COMMON) { /* symbol alignment is in st_value for SHN_COMMONs */ sym->st_value = section_add(bss_section, sym->st_size, sym->st_value); @@ -1987,8 +2051,7 @@ ST_FUNC void resolve_common_syms(TCCState *s1) } /* Now assign linker provided symbols their value. */ - if (s1->output_type != TCC_OUTPUT_DLL) - tcc_add_linker_symbols(s1); + tcc_add_linker_symbols(s1); } #ifndef ELF_OBJ_ONLY @@ -2076,16 +2139,13 @@ static void bind_exe_dynsyms(TCCState *s1, int is_PIE) - if STT_FUNC or STT_GNU_IFUNC symbol -> add it in PLT - if STT_OBJECT symbol -> add it in .bss section with suitable reloc */ for_each_elem(symtab_section, 1, sym, ElfW(Sym)) { - if (sym->st_shndx == SHN_UNDEF - /* bss symbols may be initialized in the shared library */ - || sym->st_shndx == SHN_COMMON - || sym->st_shndx == bss_section->sh_num) { + if (sym->st_shndx == SHN_UNDEF) { name = (char *) symtab_section->link->data + sym->st_name; sym_index = find_elf_sym(s1->dynsymtab_section, name); - esym = &((ElfW(Sym) *)s1->dynsymtab_section->data)[sym_index]; - if (sym_index && esym->st_shndx != SHN_UNDEF) { + if (sym_index) { if (is_PIE) continue; + esym = &((ElfW(Sym) *)s1->dynsymtab_section->data)[sym_index]; type = ELFW(ST_TYPE)(esym->st_info); if ((type == STT_FUNC) || (type == STT_GNU_IFUNC)) { /* Indirect functions shall have STT_FUNC type in executable @@ -2104,19 +2164,15 @@ static void bind_exe_dynsyms(TCCState *s1, int is_PIE) } else if (type == STT_OBJECT) { unsigned long offset; ElfW(Sym) *dynsym; - if (sym->st_shndx == bss_section->sh_num) { - offset = sym->st_value; - } else { - offset = bss_section->data_offset; - /* XXX: which alignment ? */ - offset = (offset + 16 - 1) & -16; - bss_section->data_offset = offset + esym->st_size; - } + offset = bss_section->data_offset; + /* XXX: which alignment ? */ + offset = (offset + 16 - 1) & -16; set_elf_sym (s1->symtab, offset, esym->st_size, esym->st_info, 0, bss_section->sh_num, name); index = put_elf_sym(s1->dynsym, offset, esym->st_size, esym->st_info, 0, bss_section->sh_num, name); + /* Ensure R_COPY works for weak symbol aliases */ if (ELFW(ST_BIND)(esym->st_info) == STB_WEAK) { for_each_elem(s1->dynsymtab_section, 1, dynsym, ElfW(Sym)) { @@ -2131,10 +2187,13 @@ static void bind_exe_dynsyms(TCCState *s1, int is_PIE) } } } + put_elf_reloc(s1->dynsym, bss_section, offset, R_COPY, index); + offset += esym->st_size; + bss_section->data_offset = offset; } - } else if (sym->st_shndx == SHN_UNDEF) { + } else { /* STB_WEAK undefined symbols are accepted */ /* XXX: _fp_hw seems to be part of the ABI, so we ignore it */ if (ELFW(ST_BIND)(sym->st_info) == STB_WEAK || @@ -2145,8 +2204,6 @@ static void bind_exe_dynsyms(TCCState *s1, int is_PIE) } } } - /* update _end symbol with new bss length */ - set_linker_sym(s1, "_end", bss_section, 2); } /* Bind symbols of libraries: export all non local symbols of executable that @@ -3136,6 +3193,7 @@ static int elf_output_file(TCCState *s1, const char *filename) sec_order = tcc_malloc(sizeof(int) * 2 * s1->nb_sections); /* compute section to program header mapping */ layout_sections(s1, sec_order, &dyninf); + finalize_linker_symbols(s1, sec_order); if (dynamic) { /* put in GOT the dynamic section address and relocate PLT */ @@ -3583,7 +3641,7 @@ invalid: } } done: - ret = !s1->nb_errors - 1; /* errors possibly from set_elf_sym() */ + ret = 0; the_end: tcc_free(symtab); tcc_free(strtab); diff --git a/tccgen.c b/tccgen.c index ddf451d6..85e36707 100644 --- a/tccgen.c +++ b/tccgen.c @@ -4046,9 +4046,7 @@ redo: case TOK_SECTION2: skip('('); astr = parse_mult_str("section name")->data; - n = tcc_state->nb_sections; ad->section = find_section(tcc_state, astr); - ad->new_section = n < tcc_state->nb_sections; skip(')'); break; case TOK_ALIAS1: @@ -8543,21 +8541,17 @@ static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r, vset(type, r, addr); } } else { - CType *tp = type; - int is_const; - - while ((tp->t & (VT_BTYPE|VT_ARRAY)) == (VT_PTR|VT_ARRAY)) - tp = &tp->ref->type; - is_const = tp->t & VT_CONSTANT; - /* allocate symbol in corresponding section */ sec = ad->section; if (!sec) { + CType *tp = type; + while ((tp->t & (VT_BTYPE|VT_ARRAY)) == (VT_PTR|VT_ARRAY)) + tp = &tp->ref->type; if (type->t & VT_TLS) { sec = find_section(tcc_state, has_init ? ".tdata" : ".tbss"); sec->sh_flags = SHF_ALLOC | SHF_WRITE | SHF_TLS; sec->sh_type = has_init ? SHT_PROGBITS : SHT_NOBITS; - } else if (is_const) { + } else if (tp->t & VT_CONSTANT) { sec = rodata_section; } else if (has_init) { sec = data_section; @@ -8565,21 +8559,15 @@ static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r, tcc_warning("rw data: %s", get_tok_str(v, 0));*/ } else if (tcc_state->nocommon) sec = bss_section; - } else if (ad->new_section) { - /* XXX: DWIM logic: set section flags according to first usage */ - if (!is_const) { - sec->sh_flags |= SHF_WRITE; - if (!has_init) - sec->sh_type = SHT_NOBITS; - } } -#ifdef CONFIG_TCC_BCHECK - if (bcheck) - size = size + 1; /* add padding */ -#endif if (sec) { addr = section_add(sec, size, align); +#ifdef CONFIG_TCC_BCHECK + /* add padding if bound check */ + if (bcheck) + section_add(sec, 1, 1); +#endif } else { addr = align; /* SHN_COMMON is special, symbol value is align */ sec = common_section; @@ -8609,7 +8597,7 @@ static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r, /* then add global bound info */ bounds_ptr = section_ptr_add(bounds_section, 2 * sizeof(addr_t)); bounds_ptr[0] = 0; /* relocated */ - bounds_ptr[1] = size - 1; + bounds_ptr[1] = size; } #endif } @@ -9034,12 +9022,11 @@ static int decl(int l) skip_or_save_block(&fn->func_str); } else { /* compute text section */ - cur_text_section = text_section; - if (ad.section) { - cur_text_section = ad.section; - if (ad.new_section) - ad.section->sh_flags = text_section->sh_flags; - } + cur_text_section = ad.section; + if (!cur_text_section) + cur_text_section = text_section; + else if (cur_text_section->sh_num > bss_section->sh_num) + cur_text_section->sh_flags = text_section->sh_flags; gen_function(sym); } break;
signature.asc
Description: Digital signature
_______________________________________________ Tinycc-devel mailing list [email protected] https://lists.nongnu.org/mailman/listinfo/tinycc-devel
