On rpi400/AARCH64 it doesn't search for user defined libraries in the selected folders.

Bug #2035094 reported by Jakub Strzelecki
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
gcc-defaults (Ubuntu)
Expired
Undecided
Unassigned

Bug Description

$ neofetch
OS: Ubuntu MATE 22.04.3 LTS aarch64
Host: Raspberry Pi 400 Rev 1.0
Kernel: 5.15.0-1036-raspi

$ lsb_release -rd
Description: Ubuntu 22.04.3 LTS
Release: 22.04

$ apt-cache policy gcc
gcc:
  Installed: 4:11.2.0-1ubuntu1
  Candidate: 4:11.2.0-1ubuntu1
  Version table:
 *** 4:11.2.0-1ubuntu1 500
        500 http://ports.ubuntu.com jammy/main arm64 Packages
        100 /var/lib/dpkg/status

$ ls /usr/lib/aarch64-linux-gnu/libSDL2*
/usr/lib/aarch64-linux-gnu/libSDL2-2.0.so
/usr/lib/aarch64-linux-gnu/libSDL2-2.0.so.0
/usr/lib/aarch64-linux-gnu/libSDL2-2.0.so.0.18.2
/usr/lib/aarch64-linux-gnu/libSDL2.a
/usr/lib/aarch64-linux-gnu/libSDL2main.a
/usr/lib/aarch64-linux-gnu/libSDL2.so
/usr/lib/aarch64-linux-gnu/libSDL2_test.a

Expected:
$ gcc -O2 $(pkg-config --cflags --libs sdl2) program.c -o program && echo $?
0
$ gcc -O2 -c $(pkg-config --cflags --libs sdl2) program.c -o program.o && echo $?
0
$ gcc -O2 $(pkg-config --libs sdl2) program.o -o program && echo $?
0
$ ld.gold $(pkg-config --libs sdl2) program.o -o program && echo $?
0
$ ld.bfd $(pkg-config --libs sdl2) program.o -o program && echo $?
ld.bfd: warning: cannot find entry symbol _start; defaulting to 00000000004002e0
0
$ ld $(pkg-config --libs sdl2) program.o -o program && echo $?
ld.bfd: warning: cannot find entry symbol _start; defaulting to 00000000004002e0
0

What happened:
$ gcc -O2 $(pkg-config --cflags --libs sdl2) program.c -o program && echo $?
(...) ld exit 1
1
$ gcc -O2 -c $(pkg-config --cflags sdl2) program.c -o program.o && echo $?
0
$ gcc -O2 $(pkg-config --libs sdl2) program.o -o program && echo $?
(...) ld exit 1
1
$ gcc -O2 -L/usr/lib/aarch64-linux-gnu $(pkg-config --libs sdl2) program.o -o program && echo $?
(...) ld exit 1
1
$ strace gcc -O2 -L/usr/lib/aarch64-linux-gnu $(pkg-config --libs sdl2) program.o -o program && echo $?
(...) does an faccess to see if dir exists and can be acceessed, never tries to list a directory or ever access any form of libSDL2.0.so
$ clang -O2 $(pkg-config --libs --cflags sdl2) program.c -o program && echo $?
0
$ ld.gold $(pkg-config --libs sdl2) program.o -o program && echo $?
0
$ ld.bfd $(pkg-config --libs sdl2) program.o -o program && echo $?
ld.bfd: warning: cannot find entry symbol _start; defaulting to 00000000004002e0
0

This also fails with gcc-12, it might be affecting g++ and g++-12 package

ProblemType: Bug
DistroRelease: Ubuntu 22.04
Package: gcc 4:11.2.0-1ubuntu1
ProcVersionSignature: Ubuntu 5.15.0-1036.39-raspi 5.15.111
Uname: Linux 5.15.0-1036-raspi aarch64
ApportVersion: 2.20.11-0ubuntu82.5
Architecture: arm64
CasperMD5CheckResult: unknown
CurrentDesktop: MATE
Date: Mon Sep 11 13:50:14 2023
ImageMediaBuild: 20220703
SourcePackage: gcc-defaults
UpgradeStatus: No upgrade log present (probably fresh install)

Revision history for this message
Jakub Strzelecki (jakubby) wrote :
Revision history for this message
Jakub Strzelecki (jakubby) wrote :

System was upgraded btw, likely on rpi some logs are set to be cleared to save on sdcard wear

Revision history for this message
Jakub Strzelecki (jakubby) wrote :

$ sudo rm -rf /usr/bin/ld
$ sudo ln -s /usr/bin/aarch64-linux-gnu-ld.gold /usr/bin/ld
Fixes the issue on my system

Revision history for this message
Dave Jones (waveform) wrote :

Can you attach your program.c so I can attempt a reproduction here? Also, you mention the system was upgraded - can you recall which version you upgraded from? (I'll attempt reproduction on a fresh system, but if that fails, I can set up an upgraded variant to see if there's a significant difference).

Revision history for this message
Jakub Strzelecki (jakubby) wrote (last edit ):

Hey I more so meant apt update && apt **upgrade**.
Here you go this is the program.c, I was testing it in this very minimal reproduce-able form.
Gcc is unable to link when ld is a symbolic link to ld.bfd.
When it's linked to ld.gold and ld.mold it works, it also works with clang.
And ld.bfd is able to link on it's own.

Revision history for this message
Dave Jones (waveform) wrote :

This is a case of it mattering where the "-l" option is specified (and it's not -raspi or arm64 specific; you can reproduce the error on a PC too):

$ gcc -O2 $(pkg-config --cflags --libs sdl2) program.c -o program && echo $?
/usr/bin/ld: /tmp/cciGcVIh.o: in function `main':
program.c:(.text.startup+0xa): undefined reference to `SDL_Init'
collect2: error: ld returned 1 exit status

$ gcc -O2 program.c -o program $(pkg-config --cflags --libs sdl2) && echo $?
0

Why gold is less fussy than bfd about the ordering when invoked from gcc, I'm not sure, but I don't think it's a bug necessarily (the gcc man page is fairly explicit that the ordering of "-l" options matters, which is what pkg-config is producing here.

tags: removed: arm64 arm64-image raspi-image
Changed in gcc-defaults (Ubuntu):
status: New → Incomplete
Revision history for this message
Dave Jones (waveform) wrote :

I've set it the bug to incomplete for now in case there's any further information that could be provided on why the ordering being pertinent in bfd (but not gold) is a bug.

Revision history for this message
Launchpad Janitor (janitor) wrote :

[Expired for gcc-defaults (Ubuntu) because there has been no activity for 60 days.]

Changed in gcc-defaults (Ubuntu):
status: Incomplete → Expired
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.