:: Re: [DNG] gcc can link garbage into…
Top Pagina
Delete this message
Reply to this message
Auteur: Edward Bartolo
Datum:  
Aan: KatolaZ
CC: dng
Onderwerp: Re: [DNG] gcc can link garbage into an executable.
Hi,

Many thanks for helping me. I inspected the bash command history to
learn what was causing gcc to link 'bogus' executables and found the
cause was -c precisely as you explained. When I removed it a valid
executable was produced that could be run without problems.

Edward

On 10/06/2016, KatolaZ <katolaz@???> wrote:
> On Fri, Jun 10, 2016 at 01:42:45PM +0200, Edward Bartolo wrote:
>> Hi,
>>
>> While dissecting the sysvinits (/sbin/init) internals I found that gcc
>> can link garbage into an executable file. Attempting to run the
>> resultant garbage results in unknown executable format or something
>> similar.
>>
>> I used the -c directive directly on the source code. The command is this:
>> gcc -ansi -O2 -W -Wall -D_GNU_SOURCE -c startos.init.c -o startos.init
>>
>
> It is not gcc "linking garbage into an executable file". With the
> command above you are not *linking* anything. You are just compiling
> your .c into a relocatable .o "object file", which contains only the
> machine code of your program, and nothing else. In orer to transform
> it to an executable, you should then link it "with some more
> stuff(tm)", e.g. by using ld.
>
> Anyway, the easiest way to obtain an executable is by letting gcc do
> the linking, at least in this *basic* case. If you just get rid of the
> "-c" and let gcc handle the rest, you will end up having a proper
> executable file into "startos.init".
>
> HND
>
> KatolaZ
>
> --
> [ ~.,_  Enzo Nicosia aka KatolaZ - GLUGCT -- Freaknet Medialab  ]
> [     "+.  katolaz [at] freaknet.org --- katolaz [at] yahoo.it  ]
> [       @)   http://kalos.mine.nu ---  Devuan GNU + Linux User  ]
> [     @@)  http://maths.qmul.ac.uk/~vnicosia --  GPG: 0B5F062F  ]
> [ (@@@)  Twitter: @KatolaZ - skype: katolaz -- github: KatolaZ  ]
> _______________________________________________
> Dng mailing list
> Dng@???
> https://mailinglists.dyne.org/cgi-bin/mailman/listinfo/dng

>