datadog-ci icon indicating copy to clipboard operation
datadog-ci copied to clipboard

Add elf symbols upload command

Open nsavoire opened this issue 1 year ago • 1 comments

What and why?

This adds elf-symbols upload command that scans input location for any elf files, extracts debug information from them and uploads it to Datadog intake with proper information. Elf debug information will be used by profiling backend to symbolize native profiles.

How?

This command is intended to run only on Linux. It accepts either a single file or a directory as input. If input is a directory, it is walked recursively, looking for all files that have ELF magic number.

Only elf files that match the following conditions are considered:

  • x86_64 or aarch64 architecture
  • ELF type EXEC or DYN (executables or shared libraries)
  • have a .debug_info section or .symtab section (symbol table)
  • have a GNU build id or a Go build id (if no build id is found, we could compute a hash of file or of the .text section, but discussions on what would be the right approach are still on-going)

I could not find a JS library for ELF parsing, therefore these informations are extracted using a combination of some ad-hoc parsing of the ELF file header and shelling out to readelf program and parsing its output. This is not ideal since it requires having readelf available and if readelf output changes in some way, it could break, but it can be improved later on if needed.

Once the ELF file list with the associated metadata is build, we check for duplicate build ids since we don't want to upload debug information associated to the same build id multiple times. To deduplicate build ids, we prefer files having debug infos over files that don't, and files that have symbol tables over those that don't, otherwise we keep the first occurence.

Finally for each ELF file, debug info is extracted in a temporary directory with objcopy --only-keep-debug command, we also remove .gdb_index section ( --remove-section=.gdb_index) since it can be quite big and is not useful for symbolization and compress debug sections (--compress-debug-sections) to reduce file size (not sure if this step is useful), and then debug info file is uploaded to Datadog.

Once a file is determined to be an ELF file, most failures later on in the process result in warnings, except when input is a single file where any failure is considered an error.

TODO Add tests

Review checklist

  • [ ] Feature or bugfix MUST have appropriate tests (unit, integration)

nsavoire avatar Apr 04 '24 14:04 nsavoire

Datadog Report

Branch report: nsavoire/PROF-9486-elf_symbols_upload Commit report: c6da32e Test service: datadog-ci-tests

:white_check_mark: 0 Failed, 8240 Passed, 0 Skipped, 5m 33.84s Wall Time