ld: Expand options for partial static linking

mshubbard@twc.com mshubbard@twc.com
Thu Apr 4 13:59:39 GMT 2024


Hi All,

I would like to propose a new command line option for the linkers to
add support for partial static linking.

Currently the default behavior is for the linker to search for dynamic
libraries (.so) and if they are not found, search again for a static
library (.a). The alternative is to force the linker to search only
for the static libraries.

In some cases, it is preferred to statically link an executable as
much as possible, but since not every vendor library is available as
static, some dynamic linking is necessary. In my case this would
improve my deployment of AppImages, where the application is
statically compiled and optimized as much as possible, and the dynamic
libraries that remain are included in the squashfs.

The usual suggested workaround is to employ -l: with a fully qualified
path, or to switch the command line between --Bstatic and --Bdynamic.
This forces applications of this type to hard code elements of their
build system into the linking commands of their makefiles. When the
build system updates, the makefiles are manually edited to keep up.

Additionally, many of the linker options have the ability to disable
the default behavior with "--no-", but in this case "--Bstatic" is not
really the negation of "--Bdynamic", and there is currently no way to
control the details of these features.

I have two proposed solutions:

A. The lowest impact version
Add a command line option along the lines of "--Bstatic-preferred"
that reverses the default searching behavior. It would search
libraries looking for ".a then .so" instead of the default ".so then
.a".

It solves my problem, and in combination with --Bstatic and --Bdynamic
it covers 3 of the 4 possible search types that could be conceived.

B. The logically consistent version:
Add four new options that clearly state the behavior. These would
cover all four combinations of the current dynamic and static search
behaviors. Two would be duplicates of existing flags.

* --Bstatic-only; same as --Bstatic; linker searches for .a only
* --Bdynamic-only; new behavior; linker searches for .so only
* --Bstatic-preferred; new behavior; linker searches for .a and falls
back to .so
* --Bdynamic-preferred; same as --Bdynamic; linker searches for .so
and falls back to .a; DEFAULT

There are certainly advantages and disadvantages to both. I look
forward to hearing your thoughts on this.

Thanks,
Mike Hubbard


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://sourceware.org/pipermail/binutils/attachments/20240404/755e2dbd/attachment.htm>


More information about the Binutils mailing list