Direct use of ld (was "Problem with gnu linker")
- Love4Boobies
- Member
- Posts: 2111
- Joined: Fri Mar 07, 2008 5:36 pm
- Location: Bucharest, Romania
Direct use of ld (was "Problem with gnu linker")
I'd like to add that, as a matter of good practice, ld shouldn't be used by the programmer directly. It was designed to be the back end for GCC and should be used via GCC.
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
[ Project UDI ]
Re: Problem with the gnu linker (ld.exe)
Aside from our Bare Bones tutorial disagreeing with you, what makes you think he did so? Even if used through GCC, the PE error message would be generated by ld. (Or would it not?)Love4Boobies wrote:I'd like to add that, as a matter of good practice, ld shouldn't be used by the programmer directly. It was designed to be the back end for GCC and should be used via GCC.
Every good solution is obvious once you've found it.
Re: Problem with the gnu linker (ld.exe)
Well no, it's not. It's not even distributed in the same package as GCC.Love4Boobies wrote:I'd like to add that, as a matter of good practice, ld shouldn't be used by the programmer directly. It was designed to be the back end for GCC and should be used via GCC.
Re: Problem with the gnu linker (ld.exe)
So I need to install gcc if I want to do pure assembler programming? Or maybe I can just write my own linker.
- NickJohnson
- Member
- Posts: 1249
- Joined: Tue Mar 24, 2009 8:11 pm
- Location: Sunnyvale, California
Re: Problem with the gnu linker (ld.exe)
... binutils is not GCC. GCC depends on binutils, but not vice versa. GNU ld and as are part of binutils.iansjack wrote:So I need to install gcc if I want to do pure assembler programming? Or maybe I can just write my own linker.
Re: Problem with the gnu linker (ld.exe)
Sorry, the sarcastic nature of my post wasn't clear enough. I am well aware that ld is nothing to do with gcc, just a tool that it uses.
I am amused by the presumption that a programmer cannot be trusted to use the tool directly. I'm guessing that next I'll be warned about using objdump - why on earth would I want to know what is actually in my object files? (Before anyone takes that rhetorical question seriously - don't.)
I am amused by the presumption that a programmer cannot be trusted to use the tool directly. I'm guessing that next I'll be warned about using objdump - why on earth would I want to know what is actually in my object files? (Before anyone takes that rhetorical question seriously - don't.)
- Love4Boobies
- Member
- Posts: 2111
- Joined: Fri Mar 07, 2008 5:36 pm
- Location: Bucharest, Romania
Re: Problem with the gnu linker (ld.exe)
If the Bare Bones tutorial disagrees with me, I stand corrected.Solar wrote:Aside from our Bare Bones tutorial disagreeing with you,
You are right about this one. I was under the impression that ld's error code was used by GCC in printing the linking error message but this is apparently not true so I can't really know it's what he was doing at all.Solar wrote:what makes you think he did so? Even if used through GCC, the PE error message would be generated by ld. (Or would it not?)
It doesn't really matter how it's distributed. I don't know whether this still holds, but glibc used to be distributed as a separate package from GCC even if it was designed to be used only with GCC. Furthermore, GCC provides a way to pass arguments to ld via its command line specifically because the developers of GCC are aware that GCC is meant to be the front end. Last but not least, think of POSIX for a second---it deprecated ld utility in favour of using the same utility for both compiling and linking, which means implementations can still use ld as a back end if they so wish.JamesM wrote:Well no, it's not. It's not even distributed in the same package as GCC.Love4Boobies wrote:I'd like to add that, as a matter of good practice, ld shouldn't be used by the programmer directly. It was designed to be the back end for GCC and should be used via GCC.
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
[ Project UDI ]
- Combuster
- Member
- Posts: 9301
- Joined: Wed Oct 18, 2006 3:45 am
- Libera.chat IRC: [com]buster
- Location: On the balcony, where I can actually keep 1½m distance
- Contact:
Re: Direct use of ld (was "Problem with gnu linker")
I'm well aware that your the solo endeavour to promote host gcc for crosscompiling because it apparently works and happens to support ELF. But any form of apparent authority on this one got lost after reading this:
At any rate, I
- Don't need stuff dragged in to deal with C in non-C projects
- Don't want a poorly documented channel that arranges things with the linker without my knowledge
- Want to be independent of compiler choice as GCC is not going to be the self-hosted compiler.
And for the educational value towards others, I believe that teaching people shortcuts for which they are unable to understand the underlying choices is a really, really bad idea when people trust your wisdom based on your post count.
Therefore I advice against using GCC pretending to be just the linker. In this business, you need to know what you're doing, and using ld directly enforces that practice.
In other words, this looks like preaching on subjects you haven't mastered yourself.Love4Boobies wrote:I was under the impression that ld's error code was used by GCC in printing the linking error message
At any rate, I
- Don't need stuff dragged in to deal with C in non-C projects
- Don't want a poorly documented channel that arranges things with the linker without my knowledge
- Want to be independent of compiler choice as GCC is not going to be the self-hosted compiler.
And for the educational value towards others, I believe that teaching people shortcuts for which they are unable to understand the underlying choices is a really, really bad idea when people trust your wisdom based on your post count.
Therefore I advice against using GCC pretending to be just the linker. In this business, you need to know what you're doing, and using ld directly enforces that practice.
Re: Direct use of ld (was "Problem with gnu linker")
Rubbish. glibc is a library, not part of a compiler suite; it's not designed just to work with gcc.It doesn't really matter how it's distributed. I don't know whether this still holds, but glibc used to be distributed as a separate package from GCC even if it was designed to be used only with GCC.
Re: Direct use of ld (was "Problem with gnu linker")
You must use GCC (and binutils) to build glibc. It will not build with other toolchains. However, once the library is built, it can be linked with programs that are compiled with other toolchains.iansjack wrote:Rubbish. glibc is a library, not part of a compiler suite; it's not designed just to work with gcc.It doesn't really matter how it's distributed. I don't know whether this still holds, but glibc used to be distributed as a separate package from GCC even if it was designed to be used only with GCC.
If a trainstation is where trains stop, what is a workstation ?
- gravaera
- Member
- Posts: 737
- Joined: Tue Jun 02, 2009 4:35 pm
- Location: Supporting the cause: Use \tabs to indent code. NOT \x20 spaces.
Re: Direct use of ld (was "Problem with gnu linker")
High postcount is sooo mainstream \o/Combuster wrote:...when people trust your wisdom based on your post count.
17:56 < sortie> Paging is called paging because you need to draw it on pages in your notebook to succeed at it.
- Love4Boobies
- Member
- Posts: 2111
- Joined: Fri Mar 07, 2008 5:36 pm
- Location: Bucharest, Romania
Re: Direct use of ld (was "Problem with gnu linker")
It doesn't randomly happen to support ELF. It supports whichever ABI(s) your installation currently targets. I'm not trying to promote anything, but trying to save people the time required to build cross utilities in the cases they aren't actually needed---which is obviously not always.Combuster wrote:I'm well aware that your the solo endeavour to promote host gcc for crosscompiling because it apparently works and happens to support ELF.
Given what I've learnt from previous mistakes, I'd rather keep the discussion technical rather than to throw little insults around. Hope you will do the same. At any rate, I believe the fact that I use GCC as the front end for ld is a fair justification for not needing to know exactly how they interact.Combuster wrote:But any form of apparent authority on this one got lost after reading this:
In other words, this looks like preaching on subjects you haven't mastered yourself.Love4Boobies wrote:I was under the impression that ld's error code was used by GCC in printing the linking error message
But this isn't really inherent to GCC. After all, GCC does support other languages as well.Combuster wrote:At any rate, I
- Don't need stuff dragged in to deal with C in non-C projects
There are two things that fall under this category: startup files and libraries. Each has a command-line option, and there's one that either turns both on or off.Combuster wrote:- Don't want a poorly documented channel that arranges things with the linker without my knowledge
This is a fair point; I guess I was thinking the reverse case: easily using GCC with any linker. GCC has command-line options for using another linker and/or pass additional flags to the linker.Combuster wrote:- Want to be independent of compiler choice as GCC is not going to be the self-hosted compiler.
But I don't want to avoid answering your concern entirely so I will at least note that, as I've mentioned above, POSIX defines utilities that are both compilers and the link editors. Hence, one can at least aspire for independence in compliant environments. (It's true that POSIX only does this for C and Fortran, but consistency is a pretty safe assumption, I would say.)
That's generally true. However, the question is whether these really are shortcuts or whether the community has simply just settled on a particular practice and is now suffering from the NIH syndrome. I'm not trying to point any fingers; just saying that I do consider my way of doing things more elegant rather than a hack. While elegance may be a subject for debate, I believe the use of the word shortcut to be unjust here.Combuster wrote:And for the educational value towards others, I believe that teaching people shortcuts for which they are unable to understand the underlying choices is a really, really bad idea when people trust your wisdom based on your post count.
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
[ Project UDI ]
- Combuster
- Member
- Posts: 9301
- Joined: Wed Oct 18, 2006 3:45 am
- Libera.chat IRC: [com]buster
- Location: On the balcony, where I can actually keep 1½m distance
- Contact:
Re: Direct use of ld (was "Problem with gnu linker")
Which pretty much proves the point that GCC can not be used as a linker without dealing with the compiler part specifically.
- Love4Boobies
- Member
- Posts: 2111
- Joined: Fri Mar 07, 2008 5:36 pm
- Location: Bucharest, Romania
Re: Direct use of ld (was "Problem with gnu linker")
Sure, think of it as encapsulation. Besides, I find that the number of cases where this is the cleaner solution (and thus simpler) outweighs the cases where one has to deal with turning off compiler switches that are typical of hosted environments.
Given that I'm not imposing my views on anyone, I think it's okay for me to recommend the things that I consider to be better even if they may disagree with your views.
Given that I'm not imposing my views on anyone, I think it's okay for me to recommend the things that I consider to be better even if they may disagree with your views.
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
[ Project UDI ]