https://gcc.gnu.org/bugzilla/show_bug.cgi?id=31798

David Grayson <davidegrayson at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |davidegrayson at gmail dot com

--- Comment #5 from David Grayson <davidegrayson at gmail dot com> ---
This bug is still present, at least in GCC 6.3.0.  I have not tried a newer
version.

== Workarounds ==

For any GCC users getting an undefined reference error for "raise", you should
try providing the "-static" option to GCC when you link your program.

Alternatively, if you are compiling GCC yourself, you should find the
definition of LINK_GCC_C_SEQUENCE_SPEC in GCC's source code and change it to be
this:

    --start-group %G %L --end-group

In my case, I am building a GCC 6.3.0 cross-compiler to target musl Linux, and
the definition I had to change was in "gcc/config/gnu-user.h".

You can see my build scripts here if you are interested in using GCC to build
static programs targeting Windows and Linux:

https://github.com/DavidEGrayson/nixcrpkgs


== Comments ==

Thank you for diagnosing this correctly, Rich Felker.  Also, your
musl-cross-make project was useful to me.

The core problem here is that LINK_GCC_C_SEQUENCE_SPEC is sometimes defined
like this:

    %{static:--start-group} %G %L %{static:--end-group}%{!static:%G}

You can run "gcc -dumpspecs" and look for "link_gcc_c_sequence" to see how it
was defined in your version of GCC.  The %G basically stands for "-lgcc" and
the %L basically stands for "-lc".  

The problem with that line is that it is confusing two different concepts:

A) The program is being linked with "-static".
B) The libc and GCC libraries used by the program are static.

A implies B, but B does not imply A.  I am using GCC to build static
applications so I don't have a shared version of libc or the GCC libraries, and
I want my programs to compile and link correctly even if the "-static" argument
is not supplied.

Why was this marked as "WORKSFORME", which is defined in by this bug tracker to
be "All attempts at reproducing this bug were futile, and ..."?  From the
conversation here it sure seems like there was no attempt to understand the
configuration of the original poster's GCC and system libraries and actually
reproduce the issue.  If anyone wants help reproducing this issue, I can easily
show you how to do it using my build scripts from the nixcrpkgs project.  One
of the advantages of Nix is that it's great for expressing how to build
software and compositions of software in a reliable and predictable way, so if
you have a Linux system you can just run a few commands and get the exact same
error I was getting when I tried to build a "hello world" program for the
Raspberry Pi.

Reply via email to