public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* RFC: allow a first "=" to mean sysroot for all paths in linker-scripts?
@ 2014-05-27  2:32 Hans-Peter Nilsson
  2014-05-28 13:26 ` Hans-Peter Nilsson
  2014-06-09 13:56 ` Nicholas Clifton
  0 siblings, 2 replies; 4+ messages in thread
From: Hans-Peter Nilsson @ 2014-05-27  2:32 UTC (permalink / raw)
  To: binutils

(Basically all the verbiage below boils down to the subject line.)

Is there a reason not to allow a first character '=' to mean
sysroot-prefix for all paths inside linker scripts?  Today, it's
interpreted that way for SEARCH_DIR, but elsewhere it's a syntax
error.  Allowing this would remove the ambiguity there is today,
in that the interpretation of absolute paths depends on
how/where the linker script is found during linking.

When you deal with build-systems that copy target toolchain
files around, including DSOs and linker scripts, and point at
them with linker options, this helps e.g. sysrooted toolchains
to fit in a non-sysrooted environment and would stop some
accidental misconfigurations from appearing to work.  For
example, as most readers of this list knows, for a sysrooted or
native system, the glibc libc.so is a linker script with the
equivalent of this line:
 GROUP ( /lib/libc.so.6 /lib/libc_nonshared.a  AS_NEEDED ( /lib/ld.so.1 ) )
where the paths are interpreted by the BFD linker to mean
"prefix all those absolute paths with sysroot" if the script is
found as a subdirectory of the linker sysroot (the configured
default or specified) or "no prefix" if found elsewhere.  I
haven't looked at what gold does.  This may look like a feature
but IMHO has a horrible potential to pick up the wrong files.
At least there's visible breakage for cross-builds when the
target system is different to the host system.  Less obvious
breakage when the host and target are superficially compatible.

For a non-sysrooted cross-toolchain you make the above line work
by adjusting those paths manually in the installed script,
prefixing with the installation prefix.  That'd remove the
accidental ambiguity and work for the sysrooted installation
too, but unfortunately that effectively stops otherwise
unaltered relocation of the toolchain (moving it around in the
build environment file-system), where it would otherwise work
out of the box when moved, IIUC.

Thus the interest in forcing the sysroot prefix.  Luckily,
there's existing syntax, the "=" character.  Even luckier, today
you get a syntax error if the above line reads:
 GROUP ( =/lib/libc.so.6 =/lib/libc_nonshared.a  AS_NEEDED ( =/lib/ld.so.1 ) )
so it seems no existing valid use needs to be considered for
unquoted paths.  For quoted paths there's theoretical conflict
with an actual path by that name, but IMHO that argument would
be trumped by consistency with the SEARCH_DIR interpretation.
Native non-sysroot installations can even use the same script as
the default is "" without a configured sysroot.  (ISTR use of
sysrooted native linkers, but are there any, where the default
sysroot isn't ""?)

So again, how about treating "=" as the sysroot prefix for
*all* paths in linker scripts?
What to do about quoted paths?
(I suggest both quoted and unquoted "="-prefixed paths to work.)

I'm looking for a "patches are welcome" reply, or a valid reason
to not follow through, or of course potential issues with the
suggestion.

brgds, H-P

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

* Re: RFC: allow a first "=" to mean sysroot for all paths in linker-scripts?
  2014-05-27  2:32 RFC: allow a first "=" to mean sysroot for all paths in linker-scripts? Hans-Peter Nilsson
@ 2014-05-28 13:26 ` Hans-Peter Nilsson
  2014-06-09 13:56 ` Nicholas Clifton
  1 sibling, 0 replies; 4+ messages in thread
From: Hans-Peter Nilsson @ 2014-05-28 13:26 UTC (permalink / raw)
  To: binutils

Bump for the request for comments.
Also, tweaked bits in the TL;DR.

> From: Hans-Peter Nilsson <hp@axis.com>
> Date: Tue, 27 May 2014 04:32:30 +0200

> Is there a reason not to allow a first character '=' to mean
> sysroot-prefix for all paths inside linker scripts?  Today, it's
> interpreted that way for SEARCH_DIR, but elsewhere it's a syntax
> error.

(when not quoted)

>  GROUP ( /lib/libc.so.6 /lib/libc_nonshared.a  AS_NEEDED ( /lib/ld.so.1 ) )

(for those who didn't read the original post, the suggestion is to
allow "GROUP ( =/lib/libc.so.6 =/lib/libc_nonshared.a  AS_NEEDED ( =/lib/ld.so.1 ) )"
where the sysroot would be forced as opposed to "it depends".)

> For a non-sysrooted cross-toolchain you make the above line work
> by adjusting those paths manually in the installed script,
> prefixing with the installation prefix.

...but requires the sysroot be replicated within the sysroot
(e.g. by a parent-directory-chasing symlink) so your outermost
sysroot directory path component better not have a name-conflict
with a library. :)

brgds, H-P

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

* Re: RFC: allow a first "=" to mean sysroot for all paths in linker-scripts?
  2014-05-27  2:32 RFC: allow a first "=" to mean sysroot for all paths in linker-scripts? Hans-Peter Nilsson
  2014-05-28 13:26 ` Hans-Peter Nilsson
@ 2014-06-09 13:56 ` Nicholas Clifton
  2014-10-09  2:55   ` [PATCH 0/6] Allow a first "=" to mean sysroot for all paths in linker-scripts Hans-Peter Nilsson
  1 sibling, 1 reply; 4+ messages in thread
From: Nicholas Clifton @ 2014-06-09 13:56 UTC (permalink / raw)
  To: Hans-Peter Nilsson, binutils

Hi Hans-Peter,

> Is there a reason not to allow a first character '=' to mean
> sysroot-prefix for all paths inside linker scripts?

No...

> So again, how about treating "=" as the sysroot prefix for
> *all* paths in linker scripts?

A good idea - please submit a patch.

> What to do about quoted paths?
> (I suggest both quoted and unquoted "="-prefixed paths to work.)

Hmm, I can think of no situation where a user would want to use = as a 
valid first character of a real filepath, so quoted and unquoted 
prefixes are fine.

Cheers
   Nick


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

* [PATCH 0/6] Allow a first "=" to mean sysroot for all paths in linker-scripts
  2014-06-09 13:56 ` Nicholas Clifton
@ 2014-10-09  2:55   ` Hans-Peter Nilsson
  0 siblings, 0 replies; 4+ messages in thread
From: Hans-Peter Nilsson @ 2014-10-09  2:55 UTC (permalink / raw)
  To: binutils; +Cc: nickc

> From: Nicholas Clifton <nickc@redhat.com>
> Date: Mon, 9 Jun 2014 15:56:22 +0200

> Hi Hans-Peter,
> 
> > Is there a reason not to allow a first character '=' to mean
> > sysroot-prefix for all paths inside linker scripts?
> 
> No...
> 
> > So again, how about treating "=" as the sysroot prefix for
> > *all* paths in linker scripts?
> 
> A good idea - please submit a patch.
> 
> > What to do about quoted paths?
> > (I suggest both quoted and unquoted "="-prefixed paths to work.)
> 
> Hmm, I can think of no situation where a user would want to use = as a 
> valid first character of a real filepath, so quoted and unquoted 
> prefixes are fine.

So, here we go, a patch-set to implement this.  I haven't done
the same for gold though.  I had a brief look: it appears it
doesn't currently support a "=" as in SEARCH_DIR("=/file/path")
so at least it's not inconsistent. :)

Again, the automatic and context-sensitive semantics of naked
absolute paths for sysrooted configurations may look like a
feature but can actually pick up the wrong files.  See
<http://sourceware.org/ml/binutils/2014-05/msg00222.html> for
original RFC.

Hopefully after this, the glibc project can consider
autoconf-checking if the linker being used supports a "=" prefix
and then always prefix that in its libc.so, like
 GROUP ( =/lib/libc.so.6 =/lib/libc_nonshared.a  AS_NEEDED ( =/lib/ld.so.1 ) )
as this'll work for both sysrooted and non-sysrooted
configurations.  The default sysroot for the *linker* is "" (and
then that's also the only supported option to --sysroot).

(I also have a glimmer of a hope that some day cross-toolchains
will default to have sysroot enabled with a value like
<prefix>/<triplet>/sys-root, so you'd have sane semantics when
linking dynamically and with no need to pass configure options
other than --target and --prefix.)

brgds, H-P

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

end of thread, other threads:[~2014-10-09  2:55 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-05-27  2:32 RFC: allow a first "=" to mean sysroot for all paths in linker-scripts? Hans-Peter Nilsson
2014-05-28 13:26 ` Hans-Peter Nilsson
2014-06-09 13:56 ` Nicholas Clifton
2014-10-09  2:55   ` [PATCH 0/6] Allow a first "=" to mean sysroot for all paths in linker-scripts Hans-Peter Nilsson

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).