Page 1 of 1

Why using GCC instead of LD on Barebones tutorial?

Posted: Wed Dec 02, 2020 4:51 pm
by kaseiicy
The title says it all, can someone explain it to me? My confusions is because, LD is literally the Linker so why use GCC instead of LD?

As stated in the tutorial:
Note: Some tutorials suggest linking with i686-elf-ld rather than the compiler, however this prevents the compiler from performing various tasks during linking.
What are these 'various tasks' and how they influence in the quality of the generated binary if there's any?

Re: Why using GCC instead of LD on Barebones tutorial?

Posted: Wed Dec 02, 2020 5:53 pm
by austanss
AFAIK, all GCC does is invoke LD. I could be wrong, but I'm pretty sure that's what happens.

Re: Why using GCC instead of LD on Barebones tutorial?

Posted: Wed Dec 02, 2020 9:56 pm
by nullplan
kaseiicy wrote:What are these 'various tasks' and how they influence in the quality of the generated binary if there's any?
GCC could be performing link-time optimization with the correct plugins applied. This means, essentially, that it would optimize the whole program as if everything was written into one big file. This allows the compiler to inline across file boundaries, thus eliminating more calls. The result might be a smaller or faster executable.

Other than that, the compiler also configures a few things about the linker, like adding libgcc to the command line. Finally, GCC does not call its ld directly, it calls collect2, and collect2 may actually do something.

Re: Why using GCC instead of LD on Barebones tutorial?

Posted: Fri Dec 18, 2020 11:21 pm
by kaseiicy
Thx you all to explaining :)