Skip to content

Commit 857cbeb

Browse files
committed
0061-tccgen-an-initialized-definition-after-a-tentative-o.patch
proposed by Github CI 2026-11-25 regression testing stabilization caused by commit id 64552b3 spotted while compiling linux-tcc kernel (see Kbuild.sh) i386-tcc crashed with a core-dump reproducibly when compiling various linux-tcc kernel *.c sources for references see: https://lists.nongnu.org/archive/html/tinycc-devel/2026-11/msg00082.html
1 parent 786d305 commit 857cbeb

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

‎tccgen.c‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8558,12 +8558,32 @@ static void decl_initializer_alloc(CType *type, AttributeDef *ad, int r,
85588558
if (!has_init)
85598559
sec->sh_type = SHT_NOBITS;
85608560
}
8561+
} else if (has_init && sec->sh_type == SHT_NOBITS) {
8562+
/* the section's first object had no initializer (a tentative
8563+
definition: the kernel's "static __videocard video_vga;"
8564+
before its initialized definition), so it became NOBITS;
8565+
an initialized object makes it PROGBITS again, with the
8566+
bytes of what was allocated so far */
8567+
sec->sh_type = SHT_PROGBITS;
8568+
section_realloc(sec, sec->data_offset);
85618569
}
85628570

85638571
#ifdef CONFIG_TCC_BCHECK
85648572
if (bcheck)
85658573
size = size + 1; /* add padding */
85668574
#endif
8575+
if (sec && v && ad->section) {
8576+
/* a tentative definition in the same named section that is
8577+
still the last object there: the definition takes its place
8578+
(otherwise the kernel's "static __videocard x; ... static
8579+
__videocard x = {..}" would leave a zeroed copy in the
8580+
.videocards table) */
8581+
Sym *ps = sym_find(v);
8582+
ElfSym *es;
8583+
if (ps && ps->c && !(ps->type.t & VT_EXTERN) && (es = elfsym(ps))
8584+
&& es->st_shndx == sec->sh_num && es->st_value + es->st_size == sec->data_offset)
8585+
sec->data_offset = es->st_value;
8586+
}
85678587
if (sec) {
85688588
addr = section_add(sec, size, align);
85698589
} else {

0 commit comments

Comments
 (0)