Skip to content

Conversation

@parth-07
Copy link
Contributor

@parth-07 parth-07 commented Oct 13, 2025

This commit adds initial support for building shared libraries with
symbol versioning information. Symbol versioning allows to add version
information to symbols. It is used to provide multiple definitions of
the same symbol for backward compatibility.

This commit adds the support such that the functionality can be enabled
conditionally at build time by specifying ELD_ENABLE_SYMBOL_VERSIONING
CMake option. This commit also updates the PR checkin builder to enable
symbol versioning functionality.

Symbol versioning is a target-independent feature but requires support
from compiler, linker and the loader. From the ELF perspective, symbol
versioning is implemented using 3 sections:
.gnu.version(SHT_GNU_versym), .gnu.version_d(SHT_GNU_verdef), and
.gnu.version_r(SHT_GNU_verneed). This commit only provides support for
.gnu.version and .gnu.version_d sections because only they are required
when building a shared library. .gnu.version_r is required when using a
shared library. Briefly, these sections can be descrbed as:

  • .gnu.version: An array of version IDs. i'th entry of this array stores
    the version ID of the i'th symbol in the dynamic symbol
    table.
  • .gnu.version_d: Stores the version definitions of the symbols that
    are defined by this module.
  • .gnu.version_r: Stores the version definitions of the undefined symbols that
    are used by this module.

To add the support for creating shared libraries with symbol versioning
information, this commit:

  • Adds support for creating symbol versioning sections .gnu.version and
    .gnu.version_d
  • Improve version script support to properly handle versioned
    nodes.
  • Add logic to properly assign output version IDs to symbols.
  • Update dynamic symbol table and .hash section to properly emit
    versioned symbols.
  • Emit symbol versioning sections and correctly fill symbol versioning
    information in the .dynamic section.

Additionally, this commit adds the trace flag --trace=symbol-versioning.

Resolves #646

@parth-07 parth-07 force-pushed the PrimitiveSymbolVersioningSharedLibs branch 2 times, most recently from 72be119 to 4117df0 Compare December 1, 2025 14:56
@parth-07 parth-07 changed the title Add initial support of creating shared libs with symbol versioning info Add initial support for creating shared library with symbol versioning Dec 1, 2025
@parth-07 parth-07 force-pushed the PrimitiveSymbolVersioningSharedLibs branch from 4117df0 to 3e04f3b Compare December 1, 2025 14:57
@parth-07 parth-07 marked this pull request as ready for review December 1, 2025 14:58
Copy link
Contributor

@quic-seaswara quic-seaswara left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to define the symbol override rules especially for weak and strong symbols that have versioning information.

Does this work with --gc-sections ?

Can you please add the tests applicable ?

Please use lld to build with versioned libraries generated by eld, and run it to make sure we have those cases handled.

@parth-07 parth-07 force-pushed the PrimitiveSymbolVersioningSharedLibs branch from 3e04f3b to 9c4a384 Compare December 5, 2025 09:40
@parth-07
Copy link
Contributor Author

parth-07 commented Dec 5, 2025

We need to define the symbol override rules especially for weak and strong symbols that have versioning information.

This PR does not add support for the case where the input files have versioned symbols. This PR only enables creating shared libraries with symbol versioning information. So, there is no symbol resolution change for this PR.

Does this work with --gc-sections ?

Yes, --gc-sections should work as before. This PR does not modify the garbage-collection stage. Garbage-collection and version scripts behave as before.

Please use lld to build with versioned libraries generated by eld, and run it to make sure we have those cases handled.

I have added build and run tests for symbol versioning in x86-64.

@parth-07 parth-07 force-pushed the PrimitiveSymbolVersioningSharedLibs branch 9 times, most recently from dd05a74 to 9beb3a7 Compare December 11, 2025 06:35
@parth-07 parth-07 force-pushed the PrimitiveSymbolVersioningSharedLibs branch 5 times, most recently from 10c24f3 to ea915f6 Compare December 16, 2025 05:37
@parth-07
Copy link
Contributor Author

Thank you @quic-seaswara, @quic-areg and @quic-akaryaki for the reviews. I have resolved / replied-to all the reviews. Can you please review again?

@partaror partaror force-pushed the PrimitiveSymbolVersioningSharedLibs branch 2 times, most recently from d9cf7fc to 1b27f1f Compare December 17, 2025 06:33
Copy link
Contributor

@quic-areg quic-areg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@parth-07 parth-07 force-pushed the PrimitiveSymbolVersioningSharedLibs branch from 1b27f1f to 645ea12 Compare December 21, 2025 15:06
@partaror partaror force-pushed the PrimitiveSymbolVersioningSharedLibs branch 2 times, most recently from 224d101 to 83a2eb5 Compare December 29, 2025 08:29
This commit adds initial support for building shared libraries with
symbol versioning information. Symbol versioning allows to add version
information to symbols. It is used to provide multiple definitions of
the same symbol for backward compatibility.

This commit adds the support such that the functionality can be enabled
conditionally at build time by specifying ELD_ENABLE_SYMBOL_VERSIONING
CMake option. This commit also updates the PR checkin builder to enable
symbol versioning functionality.

Symbol versioning is a target-independent feature but requires support
from compiler, linker and the loader. From the ELF perspective, symbol
versioning is implemented using 3 sections:
.gnu.version(SHT_GNU_versym), .gnu.version_d(SHT_GNU_verdef), and
.gnu.version_r(SHT_GNU_verneed). This commit only provides support for
.gnu.version and .gnu.version_d sections because only they are required
when building a shared library. .gnu.version_r is required when using a
shared library. Briefly, these sections can be descrbed as:

- .gnu.version: An array of version IDs. i'th entry of this array stores
                the version ID of the i'th symbol in the dynamic symbol
                table.
- .gnu.version_d: Stores the version definitions of the symbols that
                  are defined by this module.
- .gnu.version_r: Stores the version definitions of the undefined symbols that
                  are used by this module.

To add the support for creating shared libraries with symbol versioning
information, this commit:
- Adds support for creating symbol versioning sections .gnu.version and
  .gnu.version_d
- Improve version script support to properly handle versioned
  nodes.
- Add logic to properly assign output version IDs to symbols.
- Update dynamic symbol table and .hash section to properly emit
  versioned symbols.
- Emit symbol versioning sections and correctly fill symbol versioning
  information in the .dynamic section.

Additionally, this commit adds the trace flag --trace=symbol-versioning.

Resolves qualcomm#646

Signed-off-by: Parth Arora <[email protected]>
@parth-07 parth-07 force-pushed the PrimitiveSymbolVersioningSharedLibs branch from 83a2eb5 to 6a6f8b8 Compare December 30, 2025 18:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for building shared libraries with symbol versioning information

5 participants