gcc -static gives GNU/Linux instead of SYSV?
Victor van der Veen
vvdveen at gmail.com
Fri Jun 17 13:01:47 UTC 2011
Using hexedit, one could change the 8th byte of the binary into 0
(instead of 3). This changes the header and also fixes my problem I had
in a later stage. It is still strange that it is set to GNU/Linux by
default.
More references via StackOverflow:
http://stackoverflow.com/questions/2764533/how-do-i-compile-on-linux-to-share-with-all-distributions
http://stackoverflow.com/questions/2020961/why-would-the-elf-header-of-a-shared-library-specify-linux-as-the-osabi
Victor
On Fri, 2011-06-17 at 14:21 +0200, Victor van der Veen wrote:
> Hi all,
>
> Not sure if this is a bug or a feature, but when compiling the following
> program (called main.c, using Ubuntu 11.04 or 10.10):
>
> #include <string.h>
> #include <stdio.h>
> int main(int argc, char **argv) {
> char buff[32];
> if (argc >= 2) strcpy(buff, argv[1]);
> return (0);
> }
>
> with
>
> #gcc main.c -o main
> #gcc -static main.c -o main_static
>
> and then do a file command on the executables, I get unexpected results:
>
> #file main
> main: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV),
> dynamically linked (uses shared libs), for GNU/Linux 2.6.15, not
> stripped
>
> #file main_static
> main_static: ELF 32-bit LSB executable, Intel 80386, version 1
> (GNU/Linux), statically linked, for GNU/Linux 2.6.15, not stripped
>
> Note that the main_static binary is identified as GNU/Linux, while main
> is SYSV. On Ubuntu 7.04, however, things are better. The same sequence
> of commands ends up with:
>
> #file main_static
> main: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for
> GNU/Linux 2.6.8, statically linked, not stripped
>
> This header differences (readelf -h calls it OS/ABI) gives me trouble
> doing other stuff.
>
> I found [1], but that doesn't help me much further.
>
> Is this a bug? Or a feature? :) How do I compile main.c statically and
> end up with a SYSV type binary in the end?
>
> Thanks in advance,
>
> Bye,
> Victor
>
> [1]. http://comments.gmane.org/gmane.comp.gcc.help/34230
>
More information about the Ubuntu-devel-discuss
mailing list