Why using GCC instead of LD on Barebones tutorial?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
kaseiicy
Posts: 4
Joined: Wed Jul 08, 2020 7:12 am

Why using GCC instead of LD on Barebones tutorial?

Post 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?
User avatar
austanss
Member
Member
Posts: 377
Joined: Sun Oct 11, 2020 9:46 pm
Location: United States

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

Post by austanss »

AFAIK, all GCC does is invoke LD. I could be wrong, but I'm pretty sure that's what happens.
Skylight: https://github.com/austanss/skylight

I make stupid mistakes and my vision is terrible. Not a good combination.

NOTE: Never respond to my posts with "it's too hard".
nullplan
Member
Member
Posts: 1790
Joined: Wed Aug 30, 2017 8:24 am

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

Post 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.
Carpe diem!
kaseiicy
Posts: 4
Joined: Wed Jul 08, 2020 7:12 am

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

Post by kaseiicy »

Thx you all to explaining :)
Post Reply