tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Tinycc-devel] Unable to compile binary with random memmove problem


From: Steve Fan
Subject: [Tinycc-devel] Unable to compile binary with random memmove problem
Date: Mon, 21 Oct 2024 20:28:35 +0800

Hi, I'm working on porting tcc to WebAssembly, and I use musl libc for this. I fetched the musl libc from Debian package repo, and I made it so that I'm 100% sure that the correct binaries and header files are shipped to the embedded Emscripten/WebAssembly build.

However, I spotted that while i386 and x86_64 codegen mostly works, the arm and arm64 is sometimes plagued with memmove/__aeabi_memmove4/__aeabi_memmove8 problem.

```

tcc: error: undefined symbol '__aeabi_memmove4'
tcc: error: undefined symbol '__aeabi_memmove8

```

I turned on -vv and I see that for some reason the object file for memmove is skipped in the ELF parser, and thus it is indeed a missing symbol for no obvious reason. I just compiled it with the examples, but built-in functions equivalent (__builtin_memmove) for some reason works, but only if I explicitly used it, then the rest will also be redirected to this call too.

I also hacked around tcc_load_alacarte, and I placed a strcmp of the current archive object name to memmove:

```

    do {
        bound = 0;
        for (p = ar_names, i = 0; i < nsyms; i++, p += strlen(p)+1) {
            Section *s = symtab_section;
            sym_index = find_elf_sym(s, p);
            if (!strcmp(p, "memmove")) {
                printf("memmove: %i\n", sym_index);
            }

```

And indeed it is 0:

```

memmove: 0
memmove: 0
memmove: 0
memmove: 0

```

If I removed the !sym_index check, then the memmove symbol can be loaded, but by doing this you will have to load the entire archive to the GOT -- not good either, and also you will have new problems with that hack:

```

tcc: error: undefined symbol '__muldc3'
tcc: error: undefined symbol '__mulsc3'
tcc: error: undefined symbol '__mulxc3'
tcc: error: undefined symbol '__bound_new_region'*

```

I'm highly suspicious of find_elf_sym function, specifically elf_hash, maybe it is somewhat returning a false positive?


Stefan




reply via email to

[Prev in Thread] Current Thread [Next in Thread]