public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* Deliberate deduplication of -rpath arguments in ld.bfd and ld.gold?
@ 2022-07-06  9:06 Stephan Bergmann
  2022-07-06 11:32 ` Michael Matz
  0 siblings, 1 reply; 2+ messages in thread
From: Stephan Bergmann @ 2022-07-06  9:06 UTC (permalink / raw)
  To: binutils

Over in the comments at <https://reviews.llvm.org/D129142> "[LLD][ELF] 
Drop duplicates from rpath" we wonder what the rationale might be that 
both ld.bfd and ld.gold apparently deliberately drop duplicated -rpath 
arguments with identical paths (as in

> $ cat test.c
> void f(void) {}
> $ gcc -c test.c
> $ ld.bfd -rpath=/path -rpath=/path -shared test.o
> $ readelf -d a.out | grep RUNPATH
>  0x000000000000001d (RUNPATH)            Library runpath: [/path]

for example).

For the relevant code in ld.bfd see `/* First see whether OPTARG is 
already in the path.  */` ever since 
<https://sourceware.org/git/?p=binutils-gdb.git;a=commitdiff;h=252b5132c753830d5fd56823373aed85f2a0db63> 
"19990502 sourceware import") and for the relevant code in ld.gold see 
`// Eliminate duplicates.` since 
<https://sourceware.org/git/?p=binutils-gdb.git;a=commitdiff;h=41f542e70b89b9ea2875c438b0c9a60ac46092dd> 
"Add support for -rpath."


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Deliberate deduplication of -rpath arguments in ld.bfd and ld.gold?
  2022-07-06  9:06 Deliberate deduplication of -rpath arguments in ld.bfd and ld.gold? Stephan Bergmann
@ 2022-07-06 11:32 ` Michael Matz
  0 siblings, 0 replies; 2+ messages in thread
From: Michael Matz @ 2022-07-06 11:32 UTC (permalink / raw)
  To: Stephan Bergmann; +Cc: binutils

Hello,

On Wed, 6 Jul 2022, Stephan Bergmann via Binutils wrote:

> Over in the comments at <https://reviews.llvm.org/D129142> "[LLD][ELF] Drop
> duplicates from rpath" we wonder what the rationale might be that both ld.bfd
> and ld.gold apparently deliberately drop duplicated -rpath arguments with
> identical paths

The rationale would be "avoid waste in the real world".  If you don't do 
that then you will find that when building certain software it will end up 
with hundreds of copies of things like "RUNPATH 
/usr/lib/my-strange-module-path/" because its build-system is strange, and 
blindly collects linker arguments from e.g. pkg-config files, but doesn't 
remove duplicates itself.  As the runtime linker doesn't do duplicate 
removal either (speed!) it would then end up looking into loading the same 
non-existing file that same hundred times.

Instead of fixing all these build systems, something simply has to remove 
the duplicates and the linker is the most sensible choice.


Ciao,
Michael.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-07-06 11:32 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-06  9:06 Deliberate deduplication of -rpath arguments in ld.bfd and ld.gold? Stephan Bergmann
2022-07-06 11:32 ` Michael Matz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).