Bug 214404 - base/gcc: and base/binutils -r424540 for TARGET_ARCH=powerpc64 example: file placement and gcc/g++ internal file lookups do not match so gcc/g++ do not work
Summary: base/gcc: and base/binutils -r424540 for TARGET_ARCH=powerpc64 example: file ...
Status: Open
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Only Me
Assignee: freebsd-toolchain (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-11-10 18:39 UTC by Mark Millard
Modified: 2020-06-17 07:42 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mark Millard 2016-11-10 18:39:37 UTC
[This is after dealing with mpfr 3.1.4 vs. 3.1.5, adding gcc and g++ commands to my environment, and updating pkg.plist for TARGET_ARCH=powerpc64 . This is use on the powerpc64 context, not the cross build.]

The gcc (and cc) from base/gcc 's freebsd-gcc-5.4.0.txz for powerpc64 (via cross builds) by default can not find ld from either the system ( /usr/bin/ld ) or from base/binutils 's FreeBSD-binutils-2.25.1_3,1.txz expanded content :

> # cc main.c
> collect2: fatal error: cannot find 'ld'
> compilation terminated.

Before showing truss output that reports for where ld is searched for: here is were it actually is (along with some other files that match the pattern that I used):

> # find / -name "*ld" -print | grep "[/-]ld$"
> /usr/src/contrib/netbsd-tests/usr.bin/ld
> /usr/src/contrib/binutils/ld
> /usr/src/gnu/usr.bin/binutils/ld
> /usr/bin/ld
> /usr/ports/devel/bcc/files/patch-ld
> /usr/powerpc64-freebsd/bin/ld

(The "env ABI=FreeBSD:12:powerpc64 pkg-static add FreeBSD-binutils-2.25.1_3,1.txz" generated that last line's file.)

The "truss -f output cc main.c" output shows none of those paths being involved. It does show a stat for:

> /usr/bin/powerpc64-portbld-freebsd12.0-powerpc64-freebsd-ld

and another for:

> /bin/powerpc64-portbld-freebsd12.0-powerpc64-freebsd-ld

among others. (ld is not the only thing with such a naming convention for what is before the tool's base name.) None of the paths end in "/ld" : all end in "-ld". None of the lookups are directly in /usr either: if /usr is involved in the path then so is at least one subdirectory.

The truss "ld" lookup reports are included in the output below, they are all not-found failures:

> # truss -f cc main.c 2>&1 | grep '[/-]ld"' 
>  2873: stat("/usr/libexec/gcc/powerpc64-portbld-freebsd12.0/5.4.0/real-ld",0xffffffffffffd2f8) ERR#2 'No such file or directory'
>  2873: stat("/usr/libexec/gcc/powerpc64-portbld-freebsd12.0/5.4.0/real-ld",0xffffffffffffd2f8) ERR#2 'No such file or directory'
>  2873: stat("/usr/libexec/gcc/powerpc64-portbld-freebsd12.0/real-ld",0xffffffffffffd2f8) ERR#2 'No such file or directory'
>  2873: stat("/usr/lib/gcc/powerpc64-portbld-freebsd12.0/5.4.0/real-ld",0xffffffffffffd2f8) ERR#2 'No such file or directory'
>  2873: stat("/usr/lib/gcc/powerpc64-portbld-freebsd12.0/real-ld",0xffffffffffffd2f8) ERR#2 'No such file or directory'
>  2873: stat("/usr/libexec/gcc/powerpc64-portbld-freebsd12.0/5.4.0/collect-ld",0xffffffffffffd2f8) ERR#2 'No such file or directory'
>  2873: stat("/usr/libexec/gcc/powerpc64-portbld-freebsd12.0/5.4.0/collect-ld",0xffffffffffffd2f8) ERR#2 'No such file or directory'
>  2873: stat("/usr/libexec/gcc/powerpc64-portbld-freebsd12.0/collect-ld",0xffffffffffffd2f8) ERR#2 'No such file or directory'
>  2873: stat("/usr/lib/gcc/powerpc64-portbld-freebsd12.0/5.4.0/collect-ld",0xffffffffffffd2f8) ERR#2 'No such file or directory'
>  2873: stat("/usr/lib/gcc/powerpc64-portbld-freebsd12.0/collect-ld",0xffffffffffffd2f8) ERR#2 'No such file or directory'
>  2873: stat("/usr/libexec/gcc/powerpc64-portbld-freebsd12.0/5.4.0/powerpc64-freebsd-ld",0xffffffffffffd2f8) ERR#2 'No such file or directory'
>  2873: stat("/usr/libexec/gcc/powerpc64-portbld-freebsd12.0/5.4.0/powerpc64-freebsd-ld",0xffffffffffffd2f8) ERR#2 'No such file or directory'
>  2873: stat("/usr/libexec/gcc/powerpc64-portbld-freebsd12.0/powerpc64-freebsd-ld",0xffffffffffffd2f8) ERR#2 'No such file or directory'
>  2873: stat("/usr/lib/gcc/powerpc64-portbld-freebsd12.0/5.4.0/powerpc64-freebsd-ld",0xffffffffffffd2f8) ERR#2 'No such file or directory'
>  2873: stat("/usr/lib/gcc/powerpc64-portbld-freebsd12.0/powerpc64-freebsd-ld",0xffffffffffffd2f8) ERR#2 'No such file or directory'
>  2873: stat("/sbin/powerpc64-portbld-freebsd12.0-powerpc64-freebsd-ld",0xffffffffffffd2f8) ERR#2 'No such file or directory'
>  2873: stat("/bin/powerpc64-portbld-freebsd12.0-powerpc64-freebsd-ld",0xffffffffffffd2f8) ERR#2 'No such file or directory'
>  2873: stat("/usr/sbin/powerpc64-portbld-freebsd12.0-powerpc64-freebsd-ld",0xffffffffffffd2f8) ERR#2 'No such file or directory'
>  2873: stat("/usr/bin/powerpc64-portbld-freebsd12.0-powerpc64-freebsd-ld",0xffffffffffffd2f8) ERR#2 'No such file or directory'
>  2873: stat("/usr/local/sbin/powerpc64-portbld-freebsd12.0-powerpc64-freebsd-ld",0xffffffffffffd2f8) ERR#2 'No such file or directory'
>  2873: stat("/usr/local/bin/powerpc64-portbld-freebsd12.0-powerpc64-freebsd-ld",0xffffffffffffd2f8) ERR#2 'No such file or directory'
>  2873: stat("/home/markmi/bin/powerpc64-portbld-freebsd12.0-powerpc64-freebsd-ld",0xffffffffffffd2f8) ERR#2 'No such file or directory'

Other files' naming differences are not necessarily the same so I list some for reference.

First: all the "truss -f cc main.c" references to /usr/bin/ are:

> # truss -f cc main.c 2>&1 | grep /usr/bin/
>  3040: access("/usr/bin/cc",X_OK)		 = 0 (0x0)
>  3040: stat("/usr/bin/cc",{ mode=-r-xr-xr-x ,inode=21028101,size=2628488,blksize=32768 }) = 0 (0x0)
>  3040: lstat("/usr/bin/cc",{ mode=lrwxr-xr-x ,inode=21028094,size=33,blksize=32768 }) = 0 (0x0)
>  3040: readlink("/usr/bin/cc","powerpc64-portbld-freebsd12.0-gcc",1023) = 33 (0x21)
>  3040: lstat("/usr/bin/powerpc64-portbld-freebsd12.0-gcc",{ mode=-r-xr-xr-x ,inode=21028101,size=2628488,blksize=32768 }) = 0 (0x0)
>  3040: access("/usr/bin/cc",X_OK)		 = 0 (0x0)
>  3040: stat("/usr/bin/cc",{ mode=-r-xr-xr-x ,inode=21028101,size=2628488,blksize=32768 }) = 0 (0x0)
>  3040: lstat("/usr/bin/cc",{ mode=lrwxr-xr-x ,inode=21028094,size=33,blksize=32768 }) = 0 (0x0)
>  3040: readlink("/usr/bin/cc","powerpc64-portbld-freebsd12.0-gcc",1023) = 33 (0x21)
>  3040: lstat("/usr/bin/powerpc64-portbld-freebsd12.0-gcc",{ mode=-r-xr-xr-x ,inode=21028101,size=2628488,blksize=32768 }) = 0 (0x0)
>  3042: execve("/usr/bin/as",0x506600c8,0x50668000) = 8 (0x8)
>  3043: stat("/usr/bin/powerpc64-portbld-freebsd12.0-powerpc64-freebsd-ld",0xffffffffffffd2b8) ERR#2 'No such file or directory'
>  3043: stat("/usr/bin/powerpc64-portbld-freebsd12.0-gnm",0xffffffffffffd2b8) ERR#2 'No such file or directory'
>  3043: stat("/usr/bin/powerpc64-portbld-freebsd12.0-nm",0xffffffffffffd2b8) ERR#2 'No such file or directory'
>  3043: stat("/usr/bin/powerpc64-portbld-freebsd12.0-gstrip",0xffffffffffffd2b8) ERR#2 'No such file or directory'
>  3043: stat("/usr/bin/powerpc64-portbld-freebsd12.0-strip",0xffffffffffffd2b8) ERR#2 'No such file or directory'
>  3043: stat("/usr/bin/cc",{ mode=-r-xr-xr-x ,inode=21028101,size=2628488,blksize=32768 }) = 0 (0x0)
>  3043: access("/usr/bin/cc",X_OK)		 = 0 (0x0)

By contrast what is in the file system for the failing references above (pd, nm, strip) is:

> # find / -name "*ld" -print | grep "[/-]ld$"
> /usr/src/contrib/netbsd-tests/usr.bin/ld
> /usr/src/contrib/binutils/ld
> /usr/src/gnu/usr.bin/binutils/ld
> /usr/bin/ld
> /usr/ports/devel/bcc/files/patch-ld
> /usr/powerpc64-freebsd/bin/ld

Compare that last to what the stat from the truss run shows:

> /usr/bin/powerpc64-portbld-freebsd12.0-powerpc64-freebsd-ld


> # find / -name "*gnm" -print | grep "[/-]gnm$"

(Yep: no gnm: nm used instead.)

> # find / -name "*nm" -print | grep "[/-]nm$"
> /usr/src/contrib/llvm/tools/llvm-nm
> /usr/src/contrib/elftoolchain/nm
> /usr/src/usr.bin/clang/llvm-nm
> /usr/src/usr.bin/nm
> /usr/bin/nm
> /usr/bin/llvm-nm
> /usr/bin/powerpc64-portbld-freebsd12.0-gcc-nm

Compare that last to what the stat from the truss run shows:

> /usr/bin/powerpc64-portbld-freebsd12.0-nm


> # find / -name "*gstrip" -print | grep "[/-]gstrip$"

(Yep: no gstrip: strip used instead.)

> # find / -name "*strip" -print | grep "[/-]strip$"
> /usr/bin/strip

Compare that to what the stat from the truss run shows:

> /usr/bin/powerpc64-portbld-freebsd12.0-strip


In my context the system cross build made its own powerpc64
binutils. /usr/bin/strip is not from base/binutils :

> # zcat FreeBSD-binutils-2.25.1_3,1.txz | tar -tf - | grep strip
> #

(No match.)


So adding what is missing (result shown):

> # ls -lt /usr/bin/ | head
> total 608956
> lrwxr-xr-x   1 root  wheel         14 Nov  9 05:38 powerpc64-portbld-freebsd12.0-strip -> /usr/bin/strip
> lrwxr-xr-x   1 root  wheel         36 Nov  9 05:38 powerpc64-portbld-freebsd12.0-nm -> powerpc64-portbld-freebsd12.0-gcc-nm
> lrwxr-xr-x   1 root  wheel         29 Nov  9 05:19 powerpc64-portbld-freebsd12.0-powerpc64-freebsd-ld -> /usr/powerpc64-freebsd/bin/ld
> lrwxr-xr-x   1 root  wheel         33 Nov  8 21:51 c++ -> powerpc64-portbld-freebsd12.0-g++
> lrwxr-xr-x   1 root  wheel         33 Nov  8 21:51 cc -> powerpc64-portbld-freebsd12.0-gcc
> lrwxr-xr-x   1 root  wheel         33 Nov  8 21:51 cpp -> powerpc64-portbld-freebsd12.0-cpp
> lrwxr-xr-x   1 root  wheel         33 Nov  8 21:51 g++ -> powerpc64-portbld-freebsd12.0-g++
> lrwxr-xr-x   1 root  wheel         33 Nov  8 21:51 gcc -> powerpc64-portbld-freebsd12.0-gcc
> lrwxr-xr-x   1 root  wheel         34 Nov  8 21:51 gcov -> powerpc64-portbld-freebsd12.0-gcov
> # 


leads to ld being found in a cc but ld not finding the libraries it needs, here:

> # cc main.c
> /usr/bin/powerpc64-portbld-freebsd12.0-powerpc64-freebsd-ld: cannot find crt1.o: No such file or directory
> /usr/bin/powerpc64-portbld-freebsd12.0-powerpc64-freebsd-ld: cannot find crti.o: No such file or directory
> /usr/bin/powerpc64-portbld-freebsd12.0-powerpc64-freebsd-ld: cannot find crtbegin.o: No such file or directory
> collect2: error: ld returned 1 exit status

In the file system are the following (more than just crt1.o , crti.o , and crtbegin.o shown):

> # find / -name "*crt*.o" -print
> /usr/lib/crtend.o
> /usr/lib/crti.o
> /usr/lib/Scrt1.o
> /usr/lib/crtbegin.o
> /usr/lib/crtbeginT.o
> /usr/lib/crtn.o
> /usr/lib/crtendS.o
> /usr/lib/crtbeginS.o
> /usr/lib/crt1.o
> /usr/lib/crtsavres.o
> /usr/lib/gcrt1.o

"truss -f cc main.cc" shows that one of

/usr/lib/gcc/powerpc64-portbld-freebsd12.0/5.4.0/
or:
/usr/powerpc64-portbld-freebsd12.0/lib/powerpc64-portbld-freebsd12.0/5.4.0/
or:
/usr/powerpc64-portbld-freebsd12.0/lib/

is expected in order to find crt1.o or crti.o or crtbegin.o or crtend.o or crtn.o :
(I did any ../ collapsing above)

> # truss -f cc main.c 2>&1 | grep crt
>  3138: access("/usr/lib/gcc/powerpc64-portbld-freebsd12.0/5.4.0/crt1.o",R_OK) ERR#2 'No such file or directory'
>  3138: access("/usr/lib/gcc/powerpc64-portbld-freebsd12.0/5.4.0/../../../../powerpc64-portbld-freebsd12.0/lib/powerpc64-portbld-freebsd12.0/5.4.0/crt1.o",R_OK) ERR#2 'No such file or directory'
>  3138: access("/usr/lib/gcc/powerpc64-portbld-freebsd12.0/5.4.0/../../../../powerpc64-portbld-freebsd12.0/lib/crt1.o",R_OK) ERR#2 'No such file or directory'
>  3138: access("/usr/lib/gcc/powerpc64-portbld-freebsd12.0/5.4.0/crti.o",R_OK) ERR#2 'No such file or directory'
>  3138: access("/usr/lib/gcc/powerpc64-portbld-freebsd12.0/5.4.0/../../../../powerpc64-portbld-freebsd12.0/lib/powerpc64-portbld-freebsd12.0/5.4.0/crti.o",R_OK) ERR#2 'No such file or directory'
>  3138: access("/usr/lib/gcc/powerpc64-portbld-freebsd12.0/5.4.0/../../../../powerpc64-portbld-freebsd12.0/lib/crti.o",R_OK) ERR#2 'No such file or directory'
>  3138: access("/usr/lib/gcc/powerpc64-portbld-freebsd12.0/5.4.0/crtbegin.o",R_OK) ERR#2 'No such file or directory'
>  3138: access("/usr/lib/gcc/powerpc64-portbld-freebsd12.0/5.4.0/../../../../powerpc64-portbld-freebsd12.0/lib/powerpc64-portbld-freebsd12.0/5.4.0/crtbegin.o",R_OK) ERR#2 'No such file or directory'
>  3138: access("/usr/lib/gcc/powerpc64-portbld-freebsd12.0/5.4.0/../../../../powerpc64-portbld-freebsd12.0/lib/crtbegin.o",R_OK) ERR#2 'No such file or directory'
>  3138: access("/usr/lib/gcc/powerpc64-portbld-freebsd12.0/5.4.0/crtend.o",R_OK) ERR#2 'No such file or directory'
>  3138: access("/usr/lib/gcc/powerpc64-portbld-freebsd12.0/5.4.0/../../../../powerpc64-portbld-freebsd12.0/lib/powerpc64-portbld-freebsd12.0/5.4.0/crtend.o",R_OK) ERR#2 'No such file or directory'
>  3138: access("/usr/lib/gcc/powerpc64-portbld-freebsd12.0/5.4.0/../../../../powerpc64-portbld-freebsd12.0/lib/crtend.o",R_OK) ERR#2 'No such file or directory'
>  3138: access("/usr/lib/gcc/powerpc64-portbld-freebsd12.0/5.4.0/crtn.o",R_OK) ERR#2 'No such file or directory'
>  3138: access("/usr/lib/gcc/powerpc64-portbld-freebsd12.0/5.4.0/../../../../powerpc64-portbld-freebsd12.0/lib/powerpc64-portbld-freebsd12.0/5.4.0/crtn.o",R_OK) ERR#2 'No such file or directory'
>  3138: access("/usr/lib/gcc/powerpc64-portbld-freebsd12.0/5.4.0/../../../../powerpc64-portbld-freebsd12.0/lib/crtn.o",R_OK) ERR#2 'No such file or directory'
>  3142: open("crt1.o",O_RDONLY,0666)		 ERR#2 'No such file or directory'
>  3142: write(2,"crt1.o",6)			 = 6 (0x6)
>  3142: open("crti.o",O_RDONLY,0666)		 ERR#2 'No such file or directory'
>  3142: write(2,"crti.o",6)			 = 6 (0x6)
>  3142: open("crtbegin.o",O_RDONLY,0666)		 ERR#2 'No such file or directory'
>  3142: write(2,"crtbegin.o",10)			 = 10 (0xa)
>  3141: access("crt1.rpo",R_OK)			 ERR#2 'No such file or directory'
>  3141: access("crti.rpo",R_OK)			 ERR#2 'No such file or directory'
>  3141: access("crtbegin.rpo",R_OK)		 ERR#2 'No such file or directory'
>  3141: access("crtend.rpo",R_OK)		 ERR#2 'No such file or directory'
>  3141: access("crtn.rpo",R_OK)			 ERR#2 'No such file or directory'
> crt1.o 3141: write(2,"crt1.o",6)			 = 6 (0x6)
> crti.o 3141: write(2,"crti.o",6)			 = 6 (0x6)
> crtbegin.o 3141: write(2,"crtbegin.o",10)			 = 10 (0xa)


For reference:

> # ls -l /usr/lib/gcc/powerpc64-portbld-freebsd12.0/5.4.0/
> total 16
> drwxr-xr-x  2 root  wheel  1024 Nov  9 02:31 include
> drwxr-xr-x  5 root  wheel   512 Nov  9 02:31 include-fixed
> drwxr-xr-x  3 root  wheel   512 Nov  9 02:31 install-tools
> drwxr-xr-x  3 root  wheel   512 Nov  9 02:31 plugin


> # ls -l /usr/powerpc64-portbld-freebsd12.0/
> ls: /usr/powerpc64-portbld-freebsd12.0/: No such file or directory

(So there is no /usr/powerpc64-portbld-freebsd12.0/lib/ or /usr/powerpc64-portbld-freebsd12.0/lib/powerpc64-portbld-freebsd12.0/5.4.0/ to look in.)

Hacking in:

> # ls -dl /usr/powerpc64-portbld-freebsd12.0
> lrwxr-xr-x  1 root  wheel  4 Nov  9 06:19 /usr/powerpc64-portbld-freebsd12.0 -> /usr

results in cc main.c finally producing an a.out like it should.
Comment 1 Steve Wills freebsd_committer 2018-02-13 17:07:38 UTC
I think this is resolved by the changes in bug 224217. Please confirm.
Comment 2 Mark Millard 2018-02-17 06:07:05 UTC
(In reply to Steve Wills from comment #1)

This will have to wait for experiments on a powerpc64
after having installed what base/binutils and base/gcc
built, probably needing to uninstall the likes of
devel/binutils and devel/powerpc64-gcc first. For
example:

base/binutils vs. devel/powerpc64-binutils
vs.
base/gcc      vs. devel/powerpc64-gcc

3 of the 4 use powerpc64-unknown-freebsd12.0-
prefixes but devel/powerpc64-binutils uses
powerpc64-freebsd- prefixes. (Or did last I
built it on a powerpc64.)

There are the /usr/bin/ vs. /usr/local/bin/
sorts of path differences as well so the
matching names for devel/powerpc64-gcc and
base/gcc make for ties to path order.
Comment 3 Mark Millard 2018-05-27 02:43:52 UTC
(In reply to Mark Millard from comment #2)

I did not get to this before losing access to
the powerpc family members for what will likely
be weeks/months(?). Sorry. [My FreeBSD time has
been very limited in recent months compared
prior recent years.]
Comment 4 Mark Millard 2020-03-09 04:21:39 UTC
(In reply to Steve Wills from comment #1)

To test I used a chroot and I did "make package" for
base/gcc6 and then installed it (inside the chroot).
This was without involving base/binutils before or
after that. It did involve:

# make build-depends-list
/usr/ports/ports-mgmt/pkg
/usr/ports/devel/gmake
/usr/ports/print/texinfo

and what they indirectly require. (The run-depends-list
was empty.)

So, for example, the system linker is lld for this
powerpc64 context.

The result of attempting to compile/link main.c was:

# cc -std=c99 -pedantic main.c
ld: error: unable to find library -lgcc
ld: error: unable to find library -lgcc_s
ld: error: unable to find library -lc
ld: error: unable to find library -lgcc
ld: error: unable to find library -lgcc_s
collect2: error: ld returned 1 exit status

The linker ld (really lld) is found and used
but other things are not.

So:

# truss -a -f -o output cc -std=c99 -pedantic main.c
ld: error: unable to find library -lgcc
ld: error: unable to find library -lgcc_s
ld: error: unable to find library -lc
ld: error: unable to find library -lgcc
ld: error: unable to find library -lgcc_s
collect2: error: ld returned 1 exit status

And using libgcc_s as an example:

# grep libgcc_s output | more
96678: open("/lib/libgcc_s.so.1",O_RDONLY|O_CLOEXEC|O_VERIFY,02005070032) = 3 (0x3)
96679: open("/lib/libgcc_s.so.1",O_RDONLY|O_CLOEXEC|O_VERIFY,02114270032) = 3 (0x3)
96681: open("/lib/libgcc_s.so.1",O_RDONLY|O_CLOEXEC|O_VERIFY,02003670032) = 3 (0x3)
96682: open("/lib/libgcc_s.so.1",O_RDONLY|O_CLOEXEC|O_VERIFY,02171470032) = 3 (0x3)
96682: access("/usr/lib/gcc/powerpc64-unknown-freebsd13.0/6.5.0/libgcc_s.so",F_OK) ERR#2 'No such file or directory'
96682: access("/usr/lib/gcc/powerpc64-unknown-freebsd13.0/6.5.0/libgcc_s.a",F_OK) ERR#2 'No such file or directory'
96682: access("/usr/lib/gcc/powerpc64-unknown-freebsd13.0/6.5.0/libgcc_s.so",F_OK) ERR#2 'No such file or directory'
96682: access("/usr/lib/gcc/powerpc64-unknown-freebsd13.0/6.5.0/libgcc_s.a",F_OK) ERR#2 'No such file or directory'

It turns out that:

96679 is for:

"/usr/libexec/gcc/powerpc64-unknown-freebsd13.0/6.5.0/cc1", "-quiet", "main.c", "-quiet", "-dumpbase", "main.c", "-auxbase", "main", "-Wpedantic", "-std=c99", "-o", "/tmp//cczJu591.s"

96681 is for:

"/usr/libexec/gcc/powerpc64-unknown-freebsd13.0/6.5.0/collect2", "--sysroot=/", "--eh-frame-hdr", "-melf64ppc_fbsd", "-dynamic-linker", "/libexec/ld-elf.so.1", "/usr/lib/crt1.o", "/usr/lib/crti.o", "/usr/lib/crtbegin.o", "-L/usr/lib/gcc/powerpc64-unknown-freebsd13.0/6.5.0", "/tmp//ccabilZp.o", "-lgcc", "--as-needed", "-lgcc_s", "--no-as-needed", "-lc", "-lgcc", "--as-needed", "-lgcc_s", "--no-as-needed", "/usr/lib/crtend.o", "/usr/lib/crtn.o"

Note the -L/usr/lib/gcc/powerpc64-unknown-freebsd13.0/6.5.0
Note the lack of some form of -L/lib

96682 is for:

"/usr/bin/ld", "--sysroot=/", "--eh-frame-hdr", "-melf64ppc_fbsd", "-dynamic-linker", "/libexec/ld-elf.so.1", "/usr/lib/crt1.o", "/usr/lib/crti.o", "/usr/lib/crtbegin.o", "-L/usr/lib/gcc/powerpc64-unknown-freebsd13.0/6.5.0", "/tmp//ccabilZp.o", "-lgcc", "--as-needed", "-lgcc_s", "--no-as-needed", "-lc", "-lgcc", "--as-needed", "-lgcc_s", "--no-as-needed", "/usr/lib/crtend.o", "/usr/lib/crtn.o"

Note the -L/usr/lib/gcc/powerpc64-unknown-freebsd13.0/6.5.0
Note the lack of some form of -L/lib

Note that:

96682: open("/lib/libgcc_s.so.1",O_RDONLY|O_CLOEXEC|O_VERIFY,02171470032) = 3 (0x3)

is for lld itself being bound to the library, not for the linking
of main.

The linker (lld) is looking in the wrong places for
various libraries --but based on what it has been told
on its command line.

For reference:

# find /lib*/ /usr/lib*/ -name "libgcc_s*" -print | more
/lib/libgcc_s.so.1
/usr/lib/debug/lib/libgcc_s.so.1.debug
/usr/lib/debug/usr/lib32/libgcc_s.so.1.debug
/usr/lib/libgcc_s.so
/usr/lib32/libgcc_s.so.1
/usr/lib32/libgcc_s.so



Context notes:

The context is head -r538510 based, with ports based on
-r526539 .
Comment 5 Mark Millard 2020-03-09 04:42:10 UTC
(In reply to Mark Millard from comment #4)

Adding a side note:

With the clang conversion as it is, FreeBSD switched
from -msvr4-struct-return to -maix-struct-return for
powerpc64.

gcc by default is still -msvr4-struct-return for
powerpc64.

If ABI compatibility is the primary criteria,
it is not obvious to me which side changes but
one should. Without ABI compatibility, base/gcc*'s
may be irrelevant for powerpc64.

https://reviews.llvm.org/D73290 is a review for
changing the clang side (restoring the historical
FreeBSD ABI behavior on the specific issue). But
the review has had no activity after late 2020-Jan.

The change might make the claim "OpenPOWER ELF V2 ABI"
odd in that it does not match linux (but does match
embedded or whatever the terminology was). (The
OpenPower ABI is a case analysis, not uniform.)

(I tested and reported. But it would not be for me
to declare such is the FreeBSD direction. I am
actually still using the change in order to allow
safely mixing gcc and clang materials in non-kernel
areas.)
Comment 6 Mark Millard 2020-03-09 11:19:26 UTC
(In reply to Mark Millard from comment #5)

I forgot to mention needing to patch the pkg-plist
and its handling for powerpc64. See below. I
presumed that 64-bit would include 32-bit (lib32)
but FreeBSD can be built without lib32 support.

# svnlite diff /usr/ports/base/
Index: /usr/ports/base/binutils/Makefile
===================================================================
--- /usr/ports/base/binutils/Makefile	(revision 526539)
+++ /usr/ports/base/binutils/Makefile	(working copy)
@@ -86,11 +86,17 @@
 .else
 PLIST_SUB+=	MIPS="@comment "
 .endif
+.if ${ARCH} == "powerpc64"
+PLIST_SUB+=	POWERPC64=""
+PLIST_SUB+=	POWERPC=""
+.else
+PLIST_SUB+=	POWERPC64="@comment "
 .if ${ARCH:Mpowerpc*}
 PLIST_SUB+=	POWERPC=""
 .else
 PLIST_SUB+=	POWERPC="@comment "
 .endif
+.endif
 .if ${ARCH:Msparc*}
 PLIST_SUB+=	SPARC=""
 .else
Index: /usr/ports/base/binutils/pkg-plist
===================================================================
--- /usr/ports/base/binutils/pkg-plist	(revision 526539)
+++ /usr/ports/base/binutils/pkg-plist	(working copy)
@@ -494,32 +494,32 @@
 %%POWERPC%%%%BUTARGET%%/lib/ldscripts/elf32ppc.xsw
 %%POWERPC%%%%BUTARGET%%/lib/ldscripts/elf32ppc.xu
 %%POWERPC%%%%BUTARGET%%/lib/ldscripts/elf32ppc.xw
-%%POWERPC%%%%BUTARGET%%/lib/ldscripts/elf64ppc_fbsd.x
-%%POWERPC%%%%BUTARGET%%/lib/ldscripts/elf64ppc_fbsd.xbn
-%%POWERPC%%%%BUTARGET%%/lib/ldscripts/elf64ppc_fbsd.xc
-%%POWERPC%%%%BUTARGET%%/lib/ldscripts/elf64ppc_fbsd.xd
-%%POWERPC%%%%BUTARGET%%/lib/ldscripts/elf64ppc_fbsd.xdc
-%%POWERPC%%%%BUTARGET%%/lib/ldscripts/elf64ppc_fbsd.xdw
-%%POWERPC%%%%BUTARGET%%/lib/ldscripts/elf64ppc_fbsd.xn
-%%POWERPC%%%%BUTARGET%%/lib/ldscripts/elf64ppc_fbsd.xr
-%%POWERPC%%%%BUTARGET%%/lib/ldscripts/elf64ppc_fbsd.xs
-%%POWERPC%%%%BUTARGET%%/lib/ldscripts/elf64ppc_fbsd.xsc
-%%POWERPC%%%%BUTARGET%%/lib/ldscripts/elf64ppc_fbsd.xsw
-%%POWERPC%%%%BUTARGET%%/lib/ldscripts/elf64ppc_fbsd.xu
-%%POWERPC%%%%BUTARGET%%/lib/ldscripts/elf64ppc_fbsd.xw
-%%POWERPC%%%%BUTARGET%%/lib/ldscripts/elf64ppc.x
-%%POWERPC%%%%BUTARGET%%/lib/ldscripts/elf64ppc.xbn
-%%POWERPC%%%%BUTARGET%%/lib/ldscripts/elf64ppc.xc
-%%POWERPC%%%%BUTARGET%%/lib/ldscripts/elf64ppc.xd
-%%POWERPC%%%%BUTARGET%%/lib/ldscripts/elf64ppc.xdc
-%%POWERPC%%%%BUTARGET%%/lib/ldscripts/elf64ppc.xdw
-%%POWERPC%%%%BUTARGET%%/lib/ldscripts/elf64ppc.xn
-%%POWERPC%%%%BUTARGET%%/lib/ldscripts/elf64ppc.xr
-%%POWERPC%%%%BUTARGET%%/lib/ldscripts/elf64ppc.xs
-%%POWERPC%%%%BUTARGET%%/lib/ldscripts/elf64ppc.xsc
-%%POWERPC%%%%BUTARGET%%/lib/ldscripts/elf64ppc.xsw
-%%POWERPC%%%%BUTARGET%%/lib/ldscripts/elf64ppc.xu
-%%POWERPC%%%%BUTARGET%%/lib/ldscripts/elf64ppc.xw
+%%POWERPC64%%%%BUTARGET%%/lib/ldscripts/elf64ppc_fbsd.x
+%%POWERPC64%%%%BUTARGET%%/lib/ldscripts/elf64ppc_fbsd.xbn
+%%POWERPC64%%%%BUTARGET%%/lib/ldscripts/elf64ppc_fbsd.xc
+%%POWERPC64%%%%BUTARGET%%/lib/ldscripts/elf64ppc_fbsd.xd
+%%POWERPC64%%%%BUTARGET%%/lib/ldscripts/elf64ppc_fbsd.xdc
+%%POWERPC64%%%%BUTARGET%%/lib/ldscripts/elf64ppc_fbsd.xdw
+%%POWERPC64%%%%BUTARGET%%/lib/ldscripts/elf64ppc_fbsd.xn
+%%POWERPC64%%%%BUTARGET%%/lib/ldscripts/elf64ppc_fbsd.xr
+%%POWERPC64%%%%BUTARGET%%/lib/ldscripts/elf64ppc_fbsd.xs
+%%POWERPC64%%%%BUTARGET%%/lib/ldscripts/elf64ppc_fbsd.xsc
+%%POWERPC64%%%%BUTARGET%%/lib/ldscripts/elf64ppc_fbsd.xsw
+%%POWERPC64%%%%BUTARGET%%/lib/ldscripts/elf64ppc_fbsd.xu
+%%POWERPC64%%%%BUTARGET%%/lib/ldscripts/elf64ppc_fbsd.xw
+%%POWERPC64%%%%BUTARGET%%/lib/ldscripts/elf64ppc.x
+%%POWERPC64%%%%BUTARGET%%/lib/ldscripts/elf64ppc.xbn
+%%POWERPC64%%%%BUTARGET%%/lib/ldscripts/elf64ppc.xc
+%%POWERPC64%%%%BUTARGET%%/lib/ldscripts/elf64ppc.xd
+%%POWERPC64%%%%BUTARGET%%/lib/ldscripts/elf64ppc.xdc
+%%POWERPC64%%%%BUTARGET%%/lib/ldscripts/elf64ppc.xdw
+%%POWERPC64%%%%BUTARGET%%/lib/ldscripts/elf64ppc.xn
+%%POWERPC64%%%%BUTARGET%%/lib/ldscripts/elf64ppc.xr
+%%POWERPC64%%%%BUTARGET%%/lib/ldscripts/elf64ppc.xs
+%%POWERPC64%%%%BUTARGET%%/lib/ldscripts/elf64ppc.xsc
+%%POWERPC64%%%%BUTARGET%%/lib/ldscripts/elf64ppc.xsw
+%%POWERPC64%%%%BUTARGET%%/lib/ldscripts/elf64ppc.xu
+%%POWERPC64%%%%BUTARGET%%/lib/ldscripts/elf64ppc.xw
 %%SPARC%%%%BUTARGET%%/lib/ldscripts/elf32_sparc.x
 %%SPARC%%%%BUTARGET%%/lib/ldscripts/elf32_sparc.xbn
 %%SPARC%%%%BUTARGET%%/lib/ldscripts/elf32_sparc.xc