[Bug 274211] lang/tcc: Crashes with SIGSEGV on 14.x / 15.0-CURRENT when compiling hello world

From: <bugzilla-noreply_at_freebsd.org>
Date: Mon, 02 Oct 2023 11:14:43 UTC
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=274211

            Bug ID: 274211
           Summary: lang/tcc: Crashes with SIGSEGV on 14.x / 15.0-CURRENT
                    when compiling hello world
           Product: Ports & Packages
           Version: Latest
          Hardware: amd64
                OS: Any
            Status: New
          Severity: Affects Only Me
          Priority: ---
         Component: Individual Port(s)
          Assignee: ports-bugs@FreeBSD.org
          Reporter: freebsd@igalic.co

given the following hello.c:

```
#include <stdio.h>

int main (int argc, const char **argv) {
        printf("Hello, World!\n");
        return 0;
}
```

when invoking tcc to compile a binary (tcc -o hello hello.c)

we get a SIGSEGV in tcc_load_object_file. Here's the full lldb output, with tcc
compiled with `-O0 -g`:

```
meena@defbix /u/p/l/t/w/tinycc-release_0_9_26 ❯❯❯ lldb ./tcc --
/home/meena/src/hello.c -o hello
(lldb) target create "./tcc"
Current executable set to '/usr/ports/lang/tcc/work/tinycc-release_0_9_26/tcc'
(x86_64).
(lldb) settings set -- target.run-args  "/home/meena/src/hello.c" "-o" "hello"
(lldb) run
Process 20766 launched: '/usr/ports/lang/tcc/work/tinycc-release_0_9_26/tcc'
(x86_64)
Process 20766 stopped
* thread #1, name = 'tcc', stop reason = signal SIGSEGV: invalid address (fault
address: 0x1c)
    frame #0: 0x000000000022aa26
tcc`tcc_load_object_file(s1=0x00002e6d3ec09000, fd=3, file_offset=0) at
tccelf.c:2533:51
   2530         if (sh->sh_link > 0)
   2531             s->link = sm_table[sh->sh_link].s;
   2532         if (sh->sh_type == SHT_RELX) {
-> 2533             s->sh_info = sm_table[sh->sh_info].s->sh_num;
   2534             /* update backward link */
   2535             s1->sections[s->sh_info]->reloc = s;
   2536         }
(lldb) bt all
* thread #1, name = 'tcc', stop reason = signal SIGSEGV: invalid address (fault
address: 0x1c)
  * frame #0: 0x000000000022aa26
tcc`tcc_load_object_file(s1=0x00002e6d3ec09000, fd=3, file_offset=0) at
tccelf.c:2533:51
    frame #1: 0x00000000002112fe
tcc`tcc_add_file_internal(s1=0x00002e6d3ec09000, filename="/usr/lib/crt1.o",
flags=0) at libtcc.c:1181:19
    frame #2: 0x0000000000211538
tcc`tcc_add_library_internal(s=0x00002e6d3ec09000, fmt="%s/%s",
filename="crt1.o", flags=0, paths=0x00002e6d3ec08010, nb_paths=1) at
libtcc.c:1254:13
    frame #3: 0x00000000002115bf tcc`tcc_add_crt(s=0x00002e6d3ec09000,
filename="crt1.o") at libtcc.c:1270:15
    frame #4: 0x0000000000211864 tcc`tcc_set_output_type(s=0x00002e6d3ec09000,
output_type=1) at libtcc.c:1360:13
    frame #5: 0x000000000020e6a3 tcc`main(argc=4, argv=0x0000000820c88778) at
tcc.c:302:5
    frame #6: 0x0000000822e9dbea libc.so.7`__libc_start1(argc=4,
argv=0x0000000820c88778, env=0x0000000820c887a0, cleanup=<unavailable>,
mainX=(tcc`main at tcc.c:245)) at libc_start1.c:157:7
    frame #7: 0x000000000020e3c0 tcc`_start at crt1_s.S:83
(lldb) 

```

n.b.: Given that this bug only occurs on 14.x / 15.0-CURRENT, chances are that
it's got something to do with recent libc/csu changes.

also note that setting ARCHLEVEL=scalar doesn't change the behaviour.

-- 
You are receiving this mail because:
You are the assignee for the bug.