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

C file in ltsmaster druntime sometimes fails to link on openSUSE with PIE #2816

Open
bmwiedemann opened this issue Aug 16, 2018 · 7 comments

Comments

@bmwiedemann
Copy link
Contributor

When working on reproducible builds for openSUSE, I found that building the ldc package for openSUSE Factory, randomly fails. I got a partial strace file of 80MB showing calls to cmake, make and

[pid 3466159] execve("/home/abuild/rpmbuild/BUILD/ldc-1.10.0-src/ldc-0.17.5-src/build/bin/ldc2", ["/home/abuild/rpmbuild/BUILD/ldc-1.10.0-src/ldc-0.17.5-src/build/bin/ldc2", "-singleobj", "-g", "-wi", "-O3", "-of=/home/abuild/rpmbuild/BUILD/ldc-1.10.0-src/build/bin/ldc-prune-cache", "-enable-inlining", "-Hkeep-all-bodies", "-release", "-I=/home/abuild/rpmbuild/BUILD/ldc-1.10.0-src", "-I=/home/abuild/rpmbuild/BUILD/ldc-1.10.0-src/build", "-I=/home/abuild/rpmbuild/BUILD/ldc-1.10.0-src/dmd", "-J=/home/abuild/rpmbuild/BUILD/ldc-1.10.0-src/dmd", "-J=/home/abuild/rpmbuild/BUILD/ldc-1.10.0-src/res", "-d-version=IN_LLVM", "/home/abuild/rpmbuild/BUILD/ldc-1.10.0-src/tools/ldc-prune-cache.d", "/home/abuild/rpmbuild/BUILD/ldc-1.10.0-src/driver/cache_pruning.d"], 0x7ffe5e21b5a8 /* 54 vars */ <unfinished ...>

[pid 3466211] execve("/usr/lib64/gcc/x86_64-suse-linux/8/collect2", ["/usr/lib64/gcc/x86_64-suse-linux/8/collect2", "-plugin", "/usr/lib64/gcc/x86_64-suse-linux/8/liblto_plugin.so", "-plugin-opt=/usr/lib64/gcc/x86_64-suse-linux/8/lto-wrapper", "-plugin-opt=-fresolution=/tmp/ccBQvQpg.res", "-plugin-opt=-pass-through=-lgcc", "-plugin-opt=-pass-through=-lgcc_s", "-plugin-opt=-pass-through=-lc", "-plugin-opt=-pass-through=-lgcc", "-plugin-opt=-pass-through=-lgcc_s", "--build-id", "--eh-frame-hdr", "-m", "elf_x86_64", "-dynamic-linker", "/lib64/ld-linux-x86-64.so.2", "-pie", "-o", "/home/abuild/rpmbuild/BUILD/ldc-1.10.0-src/build/bin/ldc-prune-cache", "/usr/lib64/gcc/x86_64-suse-linux/8/../../../../lib64/Scrt1.o", "/usr/lib64/gcc/x86_64-suse-linux/8/../../../../lib64/crti.o", "/usr/lib64/gcc/x86_64-suse-linux/8/crtbeginS.o", "-L/home/abuild/rpmbuild/BUILD/ldc-1.10.0-src/ldc-0.17.5-src/build/lib", "-L/usr/lib64/gcc/x86_64-suse-linux/8", "-L/usr/lib64/gcc/x86_64-suse-linux/8/../../../../lib64", "-L/lib/../lib64", "-L/usr/lib/../lib64", "-L/usr/lib64/gcc/x86_64-suse-linux/8/../../../../x86_64-suse-linux/lib", "-L/usr/lib64/gcc/x86_64-suse-linux/8/../../..", "/home/abuild/rpmbuild/BUILD/ldc-1.10.0-src/build/bin/ldc-prune-cache.o", "-lphobos2-ldc", "-ldruntime-ldc", "--gc-sections", "-lrt", "-ldl", "-lpthread", "-lm", "-lgcc", "--as-needed", "-lgcc_s", "--no-as-needed", "-lc", "-lgcc", "--as-needed", "-lgcc_s", "--no-as-needed", "/usr/lib64/gcc/x86_64-suse-linux/8/crtendS.o", "/usr/lib64/gcc/x86_64-suse-linux/8/../../../../lib64/crtn.o"], 0x2590fe0 /* 60 vars */) = 0

/lib64/gcc/x86_64-suse-linux/8/../../../../x86_64-suse-linux/bin/ld: /home/abuild/rpmbuild/BUILD/ldc-1.10.0-src/ldc-0.17.5-src/build/lib/libdruntime-ldc.a(errno.c.o): relocation R_X86_64_PC32 against symbol `__errno_location@@GLIBC_2.2.5' can not be used when making a PIE object; recompile with -fPIC
@joakim-noah
Copy link
Contributor

Hmm, -fPIC isn't supplied when building that C file? Should be pretty easy to add that flag, no? That file is actually no longer used in master, been thinking about submitting a pull to remove it.

@kinke
Copy link
Member

kinke commented Aug 16, 2018

The C files for druntime/Phobos should all get -fPIC here.
As to why that would fail randomly - absolutely no idea.

@kinke
Copy link
Member

kinke commented Aug 16, 2018

Ah, that's ltsmaster failing, which doesn't have that setting. It also doesn't allow for the RT_CFLAGS variable to be set in the CMake cmdline, so that patching this line is probably the way to go.

@bmwiedemann
Copy link
Contributor Author

I changed ldc-1.10.0-src/runtime/CMakeLists.txt to have

set(RT_CFLAGS             "-fPIC"                                  CACHE STRING "Runtime extra C compiler flags, separated by ' '")

but it still produces such errors. The randomness usually comes from variations in dependency/order when more than 1 rule exists to make a target. E.g. see the example of https://bugzilla.sudo.ws/show_bug.cgi?id=842

@kinke
Copy link
Member

kinke commented Aug 18, 2018

I'd suggest switching to ninja; we've had similar issues with make (-G Ninja in CMake command line, then build with ninja).

@bmwiedemann
Copy link
Contributor Author

ninja does not improve things, so the problem is probably rather with the cmake configs:

[ 1107s] /usr/lib64/gcc/x86_64-suse-linux/8/../../../../x86_64-suse-linux/bin/ld
: /home/abuild/rpmbuild/BUILD/ldc-1.10.0-src/ldc-0.17.5-src/build/lib/libdruntim
e-ldc.a(errno.c.o): relocation R_X86_64_PC32 against symbol `__errno_location@@G
LIBC_2.2.5' can not be used when making a PIE object; recompile with -fPIC
[ 1107s] /usr/lib64/gcc/x86_64-suse-linux/8/../../../../x86_64-suse-linux/bin/ld: final link failed: bad value
[ 1107s] collect2: error: ld returned 1 exit status
[ 1107s] Error: /usr/bin/gcc failed with status: 1
[ 1107s] ninja: build stopped: subcommand failed.

@kinke
Copy link
Member

kinke commented Aug 19, 2018

I guess it's both (the make troubles don't apply to ltsmaster, but to master). - You 'need' to adapt the 0.17.5/ltsmaster CMake config, not 1.10/master's, which should already default to -fPIC as mentioned earlier.

@joakim-noah joakim-noah changed the title ldc sometimes fails to compile C file in druntime sometimes fails to link on openSUSE with PIE Aug 31, 2018
@joakim-noah joakim-noah changed the title C file in druntime sometimes fails to link on openSUSE with PIE C file in ltsmaster druntime sometimes fails to link on openSUSE with PIE Aug 31, 2018
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

3 participants