Re: Linker scripts

Segher Boessenkool <[email protected]> Wed, 21 Jan 2026 09:22:21 -0600
Newsgroups gmane.comp.gcc.help
Message-ID <aXDvLRrW69VRiqKj@gate>
Hi!

On Sat, Jan 17, 2026 at 09:33:11AM +0000, Jonathan Wakely via Gcc-help wrote:
> On Sat, 17 Jan 2026 at 00:41, Gordon Messmer via Gcc-help <
> [email protected]> wrote:
> > VERS_1.2 {
> >   foo2;
> > } VERS_1.1;
> 
> Conceptually, it means that all symbols from VERS_1.1 are inherited by
> VERS_1.2, so that both sets of symbols are exported. This means that a
> library using VERS_1.2 should be backwards compatible, and usable by an
> application that needs VERS_1.1.
> 
> I'm less sure what this means practically, in terms of the actual binaries,
> and how it differs from just exporting both VERS_1.1 and VERS_1.2 with no
> inheritance from one to the other.

It is the same thing, that seems to be exactly how it is implemented :-)

> I think it affects which symbol gets
> bound to by default when linking to a library that exports both foo@VERS_1.2
> and foo@VERS_1.1.

Yup, VERS_1.2 is looked at first, so it is chosen.

> If VERS_1.2 depends on VERS_1.1 then the symbol from the newer version will
> be the default, recorded as foo@@VERS_1.2 and that will be used when
> linking to the library. If there's no dependency between the versions, I
> think you would get an error when linking to the library, unless references
> to foo were disambiguated at the assembly level by referencing foo@VERS_1.2
> explicitly.
> 
> I don't know if there are more effects, or if it's just a way for the
> linker to know which symbol is "newest" in a chain of dependent symbols, so
> that it can use @@ instead of @ for specifying the default version to use
> when linking to the library.

ldlex.l and ldgram.y are an acquired taste, they have all kinds of
special complexities that could have been avoided.  I don't know if I
should praise this or condemn it :-)


Segher