Page 1 of 1
Direct use of ld (was "Problem with gnu linker")
Posted: Fri Jun 22, 2012 4:27 am
by Love4Boobies
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)
Posted: Fri Jun 22, 2012 10:42 am
by Solar
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.
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?)
Re: Problem with the gnu linker (ld.exe)
Posted: Fri Jun 22, 2012 11:12 am
by JamesM
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.
Well no, it's not. It's not even distributed in the same package as GCC.
Re: Problem with the gnu linker (ld.exe)
Posted: Fri Jun 22, 2012 12:23 pm
by iansjack
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)
Posted: Fri Jun 22, 2012 1:10 pm
by NickJohnson
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.
... binutils is not GCC. GCC depends on binutils, but not vice versa. GNU ld and as are part of binutils.
Re: Problem with the gnu linker (ld.exe)
Posted: Fri Jun 22, 2012 1:48 pm
by iansjack
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.)
Re: Problem with the gnu linker (ld.exe)
Posted: Sun Jun 24, 2012 6:36 am
by Love4Boobies
Solar wrote:Aside from our Bare Bones tutorial disagreeing with you,
If the
Bare Bones tutorial disagrees with me, I stand corrected.
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?)
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.
JamesM wrote: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.
Well no, it's not. It's not even distributed in the same package as 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. 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.
Re: Direct use of ld (was "Problem with gnu linker")
Posted: Sun Jun 24, 2012 2:29 pm
by Combuster
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:
Love4Boobies wrote:I was under the impression that ld's error code was used by GCC in printing the linking error message
In other words, this looks like preaching on subjects you haven't mastered yourself.
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")
Posted: Sun Jun 24, 2012 3:10 pm
by iansjack
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.
Rubbish. glibc is a library, not part of a compiler suite; it's not designed just to work with gcc.
Re: Direct use of ld (was "Problem with gnu linker")
Posted: Sun Jun 24, 2012 3:21 pm
by gerryg400
iansjack wrote: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.
Rubbish. glibc is a library, not part of a compiler suite; it's not designed just to work with gcc.
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.
Re: Direct use of ld (was "Problem with gnu linker")
Posted: Sun Jun 24, 2012 5:06 pm
by gravaera
Combuster wrote:...when people trust your wisdom based on your post count.
High postcount is sooo mainstream \o/
Re: Direct use of ld (was "Problem with gnu linker")
Posted: Sun Jun 24, 2012 9:08 pm
by Love4Boobies
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.
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:But any form of apparent authority on this one got lost after reading this:
Love4Boobies wrote:I was under the impression that ld's error code was used by GCC in printing the linking error message
In other words, this looks like preaching on subjects you haven't mastered yourself.
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:At any rate, I
- Don't need stuff dragged in to deal with C in non-C projects
But this isn't really inherent to GCC. After all, GCC does support other languages as well.
Combuster wrote:- Don't want a poorly documented channel that arranges things with the linker without my knowledge
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:- Want to be independent of compiler choice as GCC is not going to be the self-hosted compiler.
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.
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.)
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.
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.
Re: Direct use of ld (was "Problem with gnu linker")
Posted: Sun Jun 24, 2012 10:43 pm
by Combuster
Which pretty much proves the point that GCC can not be used as a linker without dealing with the compiler part specifically.
Re: Direct use of ld (was "Problem with gnu linker")
Posted: Thu Jun 28, 2012 11:54 am
by Love4Boobies
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.