langlauf.io
langlauf.io

Reputation: 3211

ELF executables: required version information for imported symbols

I was hoping that every dynamically linked ELF binary has

  1. a .gnu.version_r section (or another section tagged DT_VERNEED), and that
  2. this section contains a required version for every symbol imported from a dynamically linked shared object.

Yet, there seem to be cases possible in which the compiler/linker adds an DT_NEEDED entry (i.e. embedds the name of the required shared object) without any required version information.

The closest statements I could find were in the Linux Standard Base Core Specification 3.1

All ELF objects may provide or depend on versioned symbols

and, a bit more precise, in http://www.akkadia.org/drepper/symbol-versioning:

The implementation allows every DSO to either use versions for their symbols or not. Depending on whether the DSO an object is linked against had symbols or not, the reference to the DSO requires symbols or not.

If I understand it correctly, this says that it is possible to create shared objects without version information for an exposed symbol. And thus, there can be references to these symbols without required version information.

Is my interpretation correct?

These cases should be rare though, since, why would the compiler/linker not include any version information?

Upvotes: 0

Views: 602

Answers (1)

Employed Russian
Employed Russian

Reputation: 213799

If I understand it correctly, this says that it is possible to create shared objects without version information for an exposed symbol.

Correct. Shared libraries predate introduction of versioned symbols by about 10 years. Versioned symbols are a GNU/GLIBC extension.

And thus, there can be references to these symbols without required version information.

The version information is optional.

These cases should be rare though, since, why would the compiler/linker not include any version information?

Au contraire. The compiler/linker do not include version information unless a programmer tells them to, and that is not very common outside of GLIBC.

Upvotes: 1

Related Questions