Page MenuHomePhabricator

[lld][ELF] Provide optional hidden symbol for build ID
Needs ReviewPublic

Authored by phosek on Mar 20 2020, 12:26 AM.

Details

Reviewers
ruiu
espindola
Summary

This change introduces a new optional hidden symbol build_id which
points at the the .note.gnu.build-id section (if enabled). This is
useful in instrumentation runtimes such as profile where we want to
merge profiles produced by the same module: build ID can be used to
uniquely identify modules but there's no easy way to access it at
runtime from the module itself. The
build_id symbol allows this.

Diff Detail

Event Timeline

phosek created this revision.Mar 20 2020, 12:26 AM

I think we should be a bit more careful proposing a new reserved symbol (symbol assignment even in the absence of a SECTIONS command) and think whether it will be useful after 5 years.

In FreeBSD, their linker script defines:

.note.gnu.build-id : {
  PROVIDE (__build_id_start = .);
  *(.note.gnu.build-id)
  PROVIDE (__build_id_end = .);
}

We need __build_id_end because the size of .build-id can evolve. While I think sha1 is good enough for many use cases, I can imagine someone may want more bits.

OK, I can imagine there are use cases that an external linker script is not desired. There is another perfect alternative: parse PT_NOTE and extract NT_GNU_BUILD_ID.

lld/test/ELF/build-id.s
8

Don't repeat lld command.

9

llvm-objdump -h output does not match GNU objdump. This has been a headache for many projects. llvm-readelf -S -s is usually a bette replacement.

I think if you provide symbols for the section bounds, they should be __start_note_gnu_build_id and __stop_note_gnu_build_id. But that doesn't seem enough of an improvement over parsing phdrs from __ehdr_start to merit the feature IMHO. Consumers still have to parse (or worse yet, assume) the note headers. What would make things trivial for consumers is a pair of symbols giving exactly the bounds of the *payload*, i.e. just the build ID itself (and presenting its variable size in a simple manner).

grimar added a subscriber: grimar.Mar 23 2020, 12:51 AM