Bug 1225824 - devel:gcc/binutils: Unable to build simple program without linking several additional libraries
Summary: devel:gcc/binutils: Unable to build simple program without linking several ad...
Status: NEW
Alias: None
Product: PUBLIC SUSE Linux Enterprise Desktop 15 SP5
Classification: openSUSE
Component: Other (show other bugs)
Version: unspecified
Hardware: x86-64 Other
: P5 - None : Normal
Target Milestone: ---
Assignee: Michael Matz
QA Contact: Frederic Crozat
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-06-03 11:06 UTC by Jan André Reuter
Modified: 2024-07-08 08:07 UTC (History)
1 user (show)

See Also:
Found By: ---
Services Priority:
Business Priority:
Blocker: ---
Marketing QA Status: ---
IT Deployment: ---


Attachments
Compiler output when trying to build the example code (75.53 KB, text/plain)
2024-06-03 11:06 UTC, Jan André Reuter
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jan André Reuter 2024-06-03 11:06:18 UTC
Created attachment 875270 [details]
Compiler output when trying to build the example code

The binutils-devel package provides additional headers and libraries so that projects can build applications with this package. In openSUSE Leap 15.5 however, the package seems to be somewhat broken for an expected compile workflow. It is expected that applications link all required dependencies themselves, which seems not intuitive and is handled differently in other Linux derivatives.

Here's an example code. Please note that this code will NOT run without crashing. It is just to demonstrate the issue during the link process:

-------
#define PACKAGE TEST
#define PACKAGE_VERSION 1.0

#include <bfd.h>

void check_bfd() {
    bfd_init();
    bfd_openr( "", "" );
    bfd_check_format( NULL, bfd_object);
    bfd_map_over_sections( NULL, NULL, NULL );
    bfd_close( NULL );
}

int main( void )
{
    check_bfd();
}
-------

Trying to build this code with the following command will fail with several unresolved dependencies. The full error message is attached, since its too long.

-------
$ gcc test.c -lbfd
Error message in attachement
-------

Going through the error message, it becomes clear that the dependencies are not resolved. This can be solved by manually adding them: 

-------
$ gcc test.c -lbfd -liberty -ldl -lsframe -lz
$ echo $?
0
-------

I only encountered this issue with OpenSUSE. Other distributions like Alma Linux, Fedora, Ubuntu and Arch Linux handle this differently and work fine when only linking via -lbfd.

An example:
-------
$ cat /etc/os-release | head -n 1
NAME="EndeavourOS"
$ gcc test.c -lbfd
$ echo $?
0
$ cat /usr/lib/libbfd.so
/* GNU ld script */

INPUT( /usr/lib/libbfd.a -lsframe -liberty -lz -lzstd -ldl )
-------

On Arch Linux, a new libbfd.so is manually created, which provides the linker flags.
A similar approach is used on Fedora: https://src.fedoraproject.org/rpms/binutils/blob/rawhide/f/binutils.spec#_1123

My suggestion would be to add a similar file to the binutils-devel package. This way, developers do not need to add several different flags for OpenSUSE only, which might also break their workflow. In my case, we only check for libbfd.so and do not try to add additional flags. If this does not work, we consider this libbfd installation broken.
Comment 1 Jan André Reuter 2024-07-08 08:07:17 UTC
To give a more specific case where we run into issues:

I've opened a pull request to update Score-P (a performance measurement infrastructure for HPC systems) in the OpenHPC repository from 7.1 to 8.4. In version 8.0, we added the requirement to `binutils-devel` in our package, as we use `addr2line` to get source line information. 

For the PR, I've added a patch for OpenSUSE only to allow building Score-P with the additional required flags. All other distributions I'm working with do not require this workaround.
However, this STILL causes issues, as the required flags change between `binutils-devel` versions.

With 2.39 (in Leap 15.5 OSS repositories), we require 
```
-lbfd -liberty -ldl -lz
```
With 2.41 (in Leap 15.6 OSS / SUSE Linux Enterprise 15 repositories), we require
```
-lbfd -liberty -ldl -lz -lsframe
```

This is horrible when trying to build an RPM package. 

More information can be found at the bottom of the PR: https://github.com/openhpc/ohpc/pull/1985