On the availability of "--exclude-libs" like functionality in ld64

23 views
Skip to first unread message

Francesco Pretto via Darwin-dev

unread,
Feb 21, 2022, 5:06:35 AM2/21/22
to darwi...@lists.apple.com
Hello,

I'm writing to darwin-dev since I was unable to find a more suitable
list discussing specific apple clang/ld64 topics, but please point me
out if this is not the right place for this topic and where I should
ask instead. When developing cross platform software and targeting
apple platforms, I noticed that the official apple linker (ld64)
apparently doesn't offer an equivalent functionality of the
"--exclude-libs" switch in gcc[1] and lld[2]. When creating a shared
library, the --exclude-libs switch allows to exclude exporting symbols
from a list of linked libraries, with the option to exclude all of
them with the "ALL" wildcard. This switch is very convenient when
building a complex project with a lot of static compiled 3rd party
dependencies. These dependencies may in fact contain a lot of
symbols intentionally marked with default visibility,
__attribute__((visibility("default"))), or the symbols are manually
exported through assembly code, even when the library is actually
compiled statically. In these cases, compiling the libraries enforcing
the -fvisibility=hidden compilation flag is not enough to prevent
these symbols from being exported when linking into the final
.so/.dylib, and patching source is necessary to avoid exporting
unnecessary symbols that can be erroneously bound by software in
the same process performing reckless dynamic symbols loading. The
--exclude-libs switch is very convenient as it basically allows to drop
all these symbols unconditionally from the linked libraries, not
requiring to patch 3rd party source.

Is the same functionality available in ld64 with a different
name/semantics? If not, do you plan to implement it in a future
release of ld64?

Kind regards,
Francesco

[1] https://sourceware.org/binutils/docs/ld/Options.html#index-_002d_002dexclude_002dlibs
[2] https://reviews.llvm.org/D34422
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (Darwi...@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/darwin-dev/darwin-dev-garchive-73044%40googlegroups.com

This email sent to darwin-dev-g...@googlegroups.com

Axel Lüttgens via Darwin-dev

unread,
Feb 21, 2022, 8:05:38 AM2/21/22
to dd
Hello Francesco,

Could option "-hidden-lx" of ld be of some help?

Axel

Francesco Pretto via Darwin-dev

unread,
Feb 21, 2022, 8:53:40 AM2/21/22
to Axel Lüttgens, dd
Dear Axel,

yes, definitely, ant it's recent enough since it looks like it was not
available in XCode11. It has a different semantics, since this mean
that one has to specify all the "hidden" libraries, and possibly the
"-hidden-lx" has to used instead of "-lx", for example "-hidden-lssl"
instead of "-lss"[1]. In a sense, the "--exclude-libs" semantics still
looks more appealing, since it doesn't require changes to an existing
build infrastructure (think of CMake/autotools controlled build), and
a different behavior can be enforced by patching linker flags (also
the wildcard "ALL" in --exclude-libs is useful). Will "-hidden-lx"
work also with multiple conflicting switches, like the last switch in
the command line wins (similarly to compilation flags)?

Cheers,
Francesco

[1] https://stackoverflow.com/a/70425525/213871

On Mon, 21 Feb 2022 at 14:05, Axel Lüttgens via Darwin-dev
<darwi...@lists.apple.com> wrote:
>
> Hello Francesco,
>
> Could option "-hidden-lx" of ld be of some help?
>
> Axel
>
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Darwin-dev mailing list (Darwi...@lists.apple.com)
> Help/Unsubscribe/Update your Subscription:

> https://lists.apple.com/mailman/options/darwin-dev/ceztko%40gmail.com
>
> This email sent to cez...@gmail.com

Reply all
Reply to author
Forward
0 new messages