iains / gcc-11-branch

GCC 11 for Darwin with experimental Arm64 support. Current release 11.5-darwin-r0 [July 2024]
GNU General Public License v2.0
2 stars 2 forks source link

rpath search order the way you want it? #4

Closed kencu closed 2 years ago

kencu commented 2 years ago

using gcc-11-3-darwin-pre-r2 the extra rpath search directory is added and all looks great from here.

% gfortran-mp-11 hello.f90

 % ./a.out
  Hello World!

 % otool -L a.out
 a.out:
         @rpath/libgfortran.5.dylib (compatibility version 6.0.0, current
 version 6.0.0)
         @rpath/libgcc_s.1.1.dylib (compatibility version 1.0.0, current
 version 1.1.0)
         @rpath/libquadmath.0.dylib (compatibility version 1.0.0, current
 version 1.0.0)
         /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current
 version 1311.100.3)

 % otool -l a.out | grep LC_RPATH -A 2
           cmd LC_RPATH
       cmdsize 40
          path /opt/local/lib/libgcc (offset 12)
 --
           cmd LC_RPATH
       cmdsize 32
          path @loader_path (offset 12)
 --
           cmd LC_RPATH
       cmdsize 72
          path /opt/local/lib/gcc11/gcc/x86_64-apple-darwin21/11.3.0
 (offset 12)
 --
           cmd LC_RPATH
       cmdsize 40
          path /opt/local/lib/gcc11 (offset 12)

I just thought I'd ask about the optimal order for those rpath search directories. What do you think people would expect?

I wonder if libraries at @loader_path should be first in the search -- would people expect that adjacent libraries would be the ones found first and used?

iains commented 2 years ago

'tis tricky - the reason that I put it first is that the usual reasoning is "the user added this on purpose, so we should look there first" That means that the path will override the compiler defaults - which allows newer libraries in the --with-darwin-add-path to take precedence.

Of course, the converse argument is equally valid (i.e. the compiler was tested with the libraries installed with it, so do not disturb).

I went for the first - it seems probably more flexible for your use-cases (since you specifically intend to make use of the most recent version of each named lib)

iains commented 2 years ago

NOTE: AFAIR -rpath /some/place/else will precede any of the defaults - so there should be a 'get out of jail' mechanism if something fails - but we can adjust this if needed.

It's a very easy thing to change the ordering - but one has to make some choice :)

iains commented 2 years ago

I probably should rename the option to something like --with-darwin-additional-rpath= before anyone uses it in anger (open to more succinct alternatives)

iains commented 2 years ago

--with-darwin-extra-runpath ? --with-darwin-extra-rpath ?

kencu commented 2 years ago

IMO - either of these sound quite clear to me. Of course the bikeshed can be many colours

--with-darwin-additional-rpath= --with-darwin-extra-rpath=

iains commented 2 years ago

going with --with-darwin-extra-rpath= shorter is usually better, so long as the meaning is clear. This is in 12.1r1 and 11.3.r2 (and will be in 10.4r0 I hope).