On 9/6/22 2:15 PM, connor horman wrote:
> So, the use for this is for a compiler, which uses dynamic libraries at link* time to communicate metadata, such as type information of exports (so that it can be safely referred to w/o a separate
> export file). In my case, this is for an implementation of the language rust, and contains similar information to statically linked rlibs. As mentioned, the sections are a string table, used to
> reference various strings used in the manifest, such as crate name, item names and signatures, and the names used for the links key, and a hash table so make it more efficient to reference other
> sections by name from within the manifest, which is used in replacement to similar references that would be made to files within an archive.
> I don't necessarily want to put the data as part of the note, because the current design allows the compiler to find the root manifest section, validate the name and type, preinitialize the string and
> reference tables, then toss the entire contents of the note right through the same manifest parser that would be used for manifests present within an archive. It's not a huge problem to read two i32s
> *The sections are read not by the link editor used to link the dynamic library, but by the language frontend when it is told to find a particular crate, and it finds an ET_DYN elf file instead of a
> (possibly compressed) archive. A link editor is still used in most cases to construct the dynamic library though, and the sections are emitted in intermediate object files that are appended to the
> link line, along with <$rustlib>/misc/dylib_link.ld, which, among other things, instructs the link editor creating the .so to KEEP all of the relevant sections.
...
> I'd add that other than keep the section numbers within the section, which isn't ideal
> but is ok, I don't want to start hardcoding names, since this is part of a spec building
> upon ELF, Mach-O, and PE (and possibly others in the future) to allow implementations
> of rust that care to interoperate, and minimizing the amount that gets hardcoded
> is a nice goal, as it allows more implementation flexibility (some of which I might
> like to take advantage of).
Hi Connor,
Notes are particularly difficult here, because their contents
are arbitrary in gABI terms. Each note creator puts whatever
they want in their note, and the standard has nothing to say
about that. Your note needs a string table and a hash table,
but other notes may need other things, and so there's a conflict
over this finite and tiny resource. Even worse, a given note
section can contain multiple unrelated notes, each potentially
with their own requirements for what sh_link/sh_info should mean.
Hence, I really think that if you do use notes for this, that you're
going to need to embed the section indexes, or their names,
in the note data, rather than the section header.
Of course, that means that tools like strip (recall my old blog)
can't automatically fix things up if the object gets stripped, which
is a bummer. Embedding the section names instead of section indexes
ducks that, but I agree with you that it's not normally what one
wants to do.
Using dedicated ELF section types, rather than notes, can solve
much of this, but it brings its own problems. You need to make
those sections part of the gABI, which can be a tough sell, and which
probably ties your hands on future changes, which you undoubtedly
want to avoid. Similar for adding it to an OSABI, plus you then
create cross-ELF portability problems. The gABI has generic, OS,
and platform partitions, but no language partition.
Or, you can put all the stuff (strings and hash) in their own notes,
and identify them at read time by their note names. You touched on
that above, so I know this isn't what you want, but perhaps it's worth
a second look? The upside here is that you can put whatever you
want in notes --- no standard gets to tell you differently.
Yet another idea is to create a rust specific file that captures
this stuff in a format you control directly, outside of the
ELF. Of course, there are obvious negatives to that, but it does
give you lots of flexibility and portability to non-ELF systems.
Good luck!
- Ali