Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Wed, 20 Apr 2022 15:30:17 +0800
From: "up" <>
To: "dalias" <>
Cc: "musl" <>
Subject: Re: How to support symbol versioning for musl?

Hi Rich,

Sorry to trouble you again about symbol versioning(regardless of rationality).
I've investigated the relevant code of dynamic linker and done some experiments, which raises the following questions,

1. clone the repo
2. use the musl-gcc wrapper to compile the code

1. I tried the command "readelf -sD", which output two identical symbol "func" in the symbol table of ".gnu.hash".

Symbol table of `.gnu.hash' for image:
Num&nbsp; Buc:&nbsp; Value&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Size&nbsp; &nbsp;Type&nbsp; &nbsp; Bind&nbsp; &nbsp; Vis&nbsp; &nbsp; &nbsp; Ndx&nbsp; Name
&nbsp;5&nbsp; &nbsp; 0:&nbsp; &nbsp;0000000000000000&nbsp; &nbsp;0&nbsp; &nbsp; &nbsp; OBJECT&nbsp; GLOBAL&nbsp; DEFAULT&nbsp; ABS&nbsp; NEW
&nbsp;6&nbsp; &nbsp; 2:&nbsp; &nbsp;0000000000001110&nbsp; &nbsp;23&nbsp; &nbsp; &nbsp;FUNC&nbsp; &nbsp; GLOBAL&nbsp; DEFAULT&nbsp; 12&nbsp; &nbsp;func
&nbsp;7&nbsp; &nbsp; 2:&nbsp; &nbsp;00000000000010f9&nbsp; &nbsp;23&nbsp; &nbsp; &nbsp;FUNC&nbsp; &nbsp; GLOBAL&nbsp; DEFAULT&nbsp; 12&nbsp; &nbsp;func
&nbsp;8&nbsp; &nbsp; 2:&nbsp; &nbsp;0000000000000000&nbsp; &nbsp;0&nbsp; &nbsp; &nbsp; OBJECT&nbsp; GLOBAL&nbsp; DEFAULT&nbsp; ABS&nbsp; OLD

the function gnu_lookup() of ldso/dynlink.c, uses the hashtab to find a symbol. It returns the first "func"(0000000000001110) that is the default symbol. Should I change the hashtab for saving complete symbol name? like func@@NEW and func@...?

2. I couldn't tell the meaning of "versym" in "struct dso". When "dso-&gt;versym[i] &gt; 0", its value is 3, not NEW or OLD. Neither is "dso-&gt;strings + dso-&gt;versym[i]".

3. It seems like that the function map_library() doesn't save information of the ".dynsym" table. I think I need to change the behavior to save all symbol versions, right?

Looking forward to your valuable advice. Thank you so much!

From:                                                                                                                        "musl"                                                                                    <;;
Date:&nbsp;Mon, Mar 28, 2022 11:37 PM
Subject:&nbsp;Re: [musl] How to support symbol versioning for musl?

On Mon, Mar 28, 2022 at 05:44:00PM +0800, up wrote:
&gt; Hi guys,
&gt; I've discussed this topic online(
&gt; I got the conclusion that musl does not support symbol versioning(or
&gt; musl supports only one symbol version, see at
&gt; Here is my plan,
&gt; 1. find out how musl is compatiable with glibc symbol versioning.
&gt; 2. modify musl dynamic linker to support more than two symbol versions.
&gt; But I get stuck in finding out the mechanism of dynamic linker.
&gt; Where should I start and how to procceed?
&gt; Hope you guys could give me some advice. Thank you so much!

This is a topic that's come up before. Symbol versioning was
intentionally not implemented to begin with because it's a really bad
tool for what it's intended for and we intended not to use it in musl
itself, but indeed still some things want to use it on their own, and
at one point there was some wacky use of symbol versioning in that looked like it was going to be a problem to handle
without supporting symbol versioning. So there has been talk on and
off about supporting it in the future, but I think it's still a topic
members of the community disagree over.

Implementation-wise, supporting versioning requires adding the logic
to symbol lookups. Right now they use the versym table only to
determine if the candidate symbol is default-version (that would be
used by ld), in order not to break linking with libraries that were
built with versioning. They don't have access to the version requested
by the reference to the symbol. So additional information would have
to be passed into the inner lookup loops, where it likely does have
nontrivial costs for symbol lookup performance.

Lines 244-330 of ldso/dynlink.c are the relevant location where this
would take place. Making it efficient might also require setting up
some additional data in advance; I'm not sure. It's been a long time
since I looked at what it might take to do this.

If actual symbol versioning isn't a hard requirement for what you're
doing, you might look at alternate ways of achieving what you want.
The core flaw of symbol versioning is that versions are bound at
link-time, but the actual version needed comes from what headers the
consumer of the library was built with at compile-time. A much simpler
and more-correct version of symbol versioning can therefore be
achieved just by using the preprocessor to remap identifiers in the
library's headers:

#define libfoo_funcbar libfoo_funcbar_v2

Content of type "text/html" skipped

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.