Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regression suite: undefined reference to `__tls_get_addr' #752

Closed
bluewww opened this issue Oct 27, 2020 · 9 comments
Closed

Regression suite: undefined reference to `__tls_get_addr' #752

bluewww opened this issue Oct 27, 2020 · 9 comments

Comments

@bluewww
Copy link

bluewww commented Oct 27, 2020

When I run make report-gcc with gdb-sim (by commenting out the PATH extension step pointing to qemu) I see various failures
like this

spawn -ignore SIGHUP /scratch/bluew/riscv-gnu-vanilla/build-gcc-newlib-stage2/gcc/xgcc -B/scratch/bluew/riscv-gnu-vanilla/build-gcc-newlib-stage2/gcc/ /scratch/bluew/riscv-gnu-vanilla/riscv-gcc/gcc/testsuite/gcc.dg/tls/opt-12.c -march=rv32imafc -mabi=ilp32f -mcmodel=medlow -fno-diagnostics-show-caret -fno-diagnostics-show-line-numbers -fdiagnostics-color=never -O2 -fpic -lm -o ./opt-12.exe
/scratch/bluew/riscv-gnu-vanilla/toolchain/riscv32-unknown-elf/bin/ld: /tmp/cclwKr50.o: in function `.L0 ':
opt-12.c:(.text+0x28): undefined reference to `__tls_get_addr'
/scratch/bluew/riscv-gnu-vanilla/toolchain/riscv32-unknown-elf/bin/ld: opt-12.c:(.text.startup+0x14): undefined reference to `__tls_get_addr'
collect2: error: ld returned 1 exit status
compiler exited with status 1
FAIL: gcc.dg/tls/opt-12.c (test for excess errors)
Excess errors:
opt-12.c:(.text+0x28): undefined reference to `__tls_get_addr'
/scratch/bluew/riscv-gnu-vanilla/toolchain/riscv32-unknown-elf/bin/ld: opt-12.c:(.text.startup+0x14): undefined reference to `__tls_get_addr'

using
riscv-sim/-march=rv32imafc/-mabi=ilp32f/-mcmodel=medlow

These failures are all related to the missing symbol `__tls_get_addr'.

When running the regression suite with qemu, it just skips over those tests I believe (maybe because there is no executable produced?)

@jim-wilson
Copy link
Collaborator

I would not expect the TLS (Thread Local Storage) tests to work for an embedded elf target. Our newlib port does not have TLS support. They should not be run at all. This testcase gcc.dg/tls/opt-12.c has a line
/* { dg-require-effective-target tls_runtime } */
and the tls_runtime target check will try to compile and run a TLS program, and it should fail, so this test should not be run. I see
UNSUPPORTED: gcc.dg/tls/opt-12.c
in a rv32-elf gcc/testsuite/gcc/gcc.log file that I have.

The TLS tests should work for a linux target.

If you check the gcc.log file, you should see where it tried to compile a tls_runtimeX.c file, where X is a random number (probably a process id), and this should get the same __tls_get_addr link error, which will disable all TLS tests.

@bluewww
Copy link
Author

bluewww commented Oct 27, 2020

The compilation of the tls_runtimeX.c files does not fail at all. No __tls_get_addr errors.
Edit:
I ran the test suite with make -j128 report-gcc.

@jim-wilson
Copy link
Collaborator

You can find check_effective_target_tls_runtime in gcc/testsuite/lib/target-supports.exp. You could try extracting the C code from there and compiling it with the options in the gcc.log file to see what is happening.

In my gcc.log file I see
spawn -ignore SIGHUP /scratch/jimw/fsf-testing/X-mainline-unpatched-32/build-gc
c-newlib-stage2/gcc/xgcc -B/scratch/jimw/fsf-testing/X-mainline-unpatched-32/bu
ild-gcc-newlib-stage2/gcc/ tls_runtime13276.c -march=rv32i -mabi=ilp32 -mcmodel
=medlow -fdiagnostics-plain-output -lm -o tls_runtime13276.exe^M
/scratch/jimw/fsf-testing/X-mainline-unpatched-32/build-install/riscv32-unknown
-elf/bin/ld: /tmp/ccvavu3e.o: in function .L0 ':^M tls_runtime13276.c:(.text+0x18): undefined reference to __tls_get_addr'^M
collect2: error: ld returned 1 exit status^M
compiler exited with status 1

The march/mabi/mcmodel options should not matter. Make sure it is the right compiler with no unexpected options.

I've never tried a -j number as high as 128. I think about 16 is the highest i've tried. It is possible that there is a bug in the testsuite that causes it to fail at high -j values. We have seen cases where a tcl/expect variable got set for some testcases and then we forgot to unset it when done, which may cause failures for following tests that depend on the exact order in which the tests are run, which depends on the -j factor. But that seems unlikely. Probably something simpler has gone wrong but not obvious what that might be.

@bluewww
Copy link
Author

bluewww commented Oct 28, 2020

Is there a way to tell dejganu to not delete all the tmp files it used/produced? Otherwise I will try and play around with target-supports.exp

@bluewww
Copy link
Author

bluewww commented Oct 28, 2020

I'm compiling this from target-supports.exp

__thread int thr __attribute__((tls_model("global-dynamic"))) = 0;
int main (void) { return thr; }

with

../../toolchain/bin/riscv32-unknown-elf-gcc tls-bug.c -march=rv32imafc -mabi=ilp32f -mcmodel=medlow   -fno-diagnostics-show-caret -fno-diagnostics-show-line-numbers -fdiagnostics-color=never        -lm  -o tls_runtime77550.exe

basically verbatim from gcc.log, but explicitely invoking the compiler (calling xgcc instead as int he log gives me a missing crt0.o)

I can't get it to fail linking. nm does show any symbol with the name __tls_get_addr. I tried various variations of the command. I also tried a 8.2 and another 9.2 version of the compiler.

@jim-wilson
Copy link
Collaborator

I don't know why that works in the gcc log but not directly. I suspect a hidden environment variable is set somewhere. You can fix this by adding a -B option that points at the dir with the crt0.o file, and put a trailing slash at the end to tell gcc that it is a dir name. Or you can just use the compiler in the install tree which is simpler.

I don't know if there is an option to avoid deleting temp files. You can pass -v options to get verbose info, the more -v options the more verbose it is, but that may not help. You can use something like RUNTESTFLAGS="-v -v -v -v" to do that.

If you add -S, you should see a call to __tls_get_addr, and there should be no definition in newlib libc.a.

@bluewww
Copy link
Author

bluewww commented Oct 28, 2020

./toolchain/bin/riscv32-unknown-elf-nm ./toolchain/riscv32-unknown-elf/lib/libc.a | grep tls is empty
./toolchain/bin/riscv32-unknown-elf-nm ./toolchain/riscv32-unknown-elf/lib/libc_nano.a | grep tls is empty too. So I suppose there is no __tls_get_addr to link against as expected.

I ammended the exact command in gcc.log with -B pointing to the library folder of my toolchain installation and it now compiles sucsessfully. After also adding -S I get the following assembly:

        .file   "tls-bug.c"                                                                                                                               
        .option nopic                                                                                                                                     
        .attribute arch, "rv32i2p0_m2p0_a2p0_f2p0_c2p0"                                                                                                   
        .attribute unaligned_access, 0                                                                                                                    
        .attribute stack_align, 16                                                                                                                        
        .text                                                                                                                                             
        .globl  thr                                                                                                                                       
        .section        .tbss,"awT",@nobits                                                                                                               
        .align  2                                                                                                                                         
        .type   thr, @object                                                                                                                              
        .size   thr, 4                                                                                                                                    
thr:                                                                                                                                                      
        .zero   4                                                                                                                                         
        .text                                                                                                                                             
        .align  1                                                                                                                                         
        .globl  main                                                                                                                                      
        .type   main, @function                                                                                                                           
main:                                                                                                                                                     
        addi    sp,sp,-16                                                                                                                                 
        sw      s0,12(sp)                                                                                                                                 
        addi    s0,sp,16                                                                                                                                  
        lui     a5,%tprel_hi(thr)                                                                                                                         
        add     a5,a5,tp,%tprel_add(thr)                                                                                                                  
        lw      a5,%tprel_lo(thr)(a5)                                                                                                                     
        mv      a0,a5                                                                                                                                     
        lw      s0,12(sp)                                                                                                                                 
        addi    sp,sp,16                                                                                                                                  
        jr      ra                                                                                                                                        
        .size   main, .-main                                                                                                                              
        .ident  "GCC: (GNU) 9.2.0"    

I'm not sure where I'm going wrong

@jim-wilson
Copy link
Collaborator

I would suggest ignoring the testsuite failures. They aren't important. If they are bothering you, you can put them in the allow lists in the test dir so that make report will ignore them.

The toolchain is maintained by volunteer labor, and getting the testsuite to pass without error is more work than we have time to do.

@bluewww
Copy link
Author

bluewww commented Oct 28, 2020

Thanks for the help I will use the allow list

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants