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

RPath compiler wrapper breaking precompiled header builds #3371

Closed
paulmelis opened this issue Jun 23, 2020 · 2 comments · Fixed by #3424
Closed

RPath compiler wrapper breaking precompiled header builds #3371

paulmelis opened this issue Jun 23, 2020 · 2 comments · Fixed by #3424
Milestone

Comments

@paulmelis
Copy link

This issue was found when building OpenCV-4.0.1-foss-2018b-Python-3.6.6.eb with EB 4.1.1. The build has multiple errors undefined reference to main. This is caused by the rpath wrappers adding -Wl,-rpath=... options to the g++ call, which turns otherwise compile-only commands to generate precompiled headers (-x c++-header) into commands that link.

See easybuild-OpenCV-4.0.1-20200623.143513.mcEaZ.log.gz for the full logs. But it can also be shown using only the generated rpath wrapper to compile a simple file:

paulm@tcn180 14:43 ~$ m list
Currently Loaded Modulefiles:
 1) surfsara   2) 2019   3) EasyBuild/4.1.1   4) compilerwrappers   5) eb/4.1.1(default)   6) GCCcore/8.2.0   7) zlib/1.2.11-GCCcore-8.2.0   8) binutils/2.31.1-GCCcore-8.2.0   9) GCC/8.2.0-2.31.1  

paulm@tcn180:~$ cat t.cc
#include <cstdio>

# Straight g++ call, no wrappers, succeeds
paulm@tcn180 14:45 ~$ /sw/arch/RedHatEnterpriseServer7/EB_production/2019/software/GCCcore/8.2.0/bin/g++ -x c++-header t.cc
paulm@tcn180 14:45 ~$ 

# Wrapped call, fails
paulm@tcn180 14:45 ~$ /scratch-shared/paulm/eb-3OiLzK/tmpvR7vdm/rpath_wrappers/gxx_wrapper/g++ -x c++-header t.cc 
/lib/../lib64/crt1.o(.text+0x20): error: undefined reference to 'main'
collect2: error: ld returned 1 exit status

# Straight g++ call with -Wl,-rpath addition, no wrappers, fails
paulm@tcn180 14:46 ~$ /sw/arch/RedHatEnterpriseServer7/EB_production/2019/software/GCCcore/8.2.0/bin/g++ -x c++-header -Wl,-rpath=/tmp/doh t.cc
/lib/../lib64/crt1.o(.text+0x20): error: undefined reference to 'main'
collect2: error: ld returned 1 exit status

We (me and @casparvl) suggest that the rpath wrappers check for the -x c++-header (and similar) options to make sure an otherwise correct call of g++ is not turned into one that fails. Note that there is a bit of a mist as to the expected behaviour of GCC with various options, as the docs aren't entirely clear:

  • For example, calling g++ t.cc fails if t.cc does not contain a main function as it does linking of the generated object code. But calling g++ -x c++-header t.cc apparently turns on compile-only mode and succeeds (but the gcc docs only say: "To create a precompiled header file, simply compile it as you would any other file, if necessary using the -x option to make the driver treat it as a C or C++ header file")
  • Adding -Wl,-rpath=... makes GCC link (although the docs do not specify this), unless -c is used, in which case linking is never done.
  • The examples in the GCC docs of using precompiled headers do not use -c when using -x c++-header. But upstream package could be more explicit by using -c -x c++-header, which would still work when the RPATH wrappers would add -Wl,-rpath=..., but it can't really be expected of those packages to handle that case of downstream building.
@boegel
Copy link
Member

boegel commented Jul 4, 2020

Ugh, what a mess, thanks for the detailed analysis @paulmelis!

I agree that letting the rpath wrapper check for -x c++header and similar options makes sense...

@boegel
Copy link
Member

boegel commented Aug 28, 2020

This should be fixed with the changes in #3424...

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