[all-commits] [llvm/llvm-project] 20de18: [llvm-objcopy] --only-keep-debug: place zero-size ...

Fangrui Song via All-commits all-commits at lists.llvm.org
Wed Nov 11 09:21:31 PST 2020


  Branch: refs/heads/master
  Home:   https://github.com/llvm/llvm-project
  Commit: 20de1822466e87c137b2369d8601b0f4c575981b
      https://github.com/llvm/llvm-project/commit/20de1822466e87c137b2369d8601b0f4c575981b
  Author: Fangrui Song <i at maskray.me>
  Date:   2020-11-11 (Wed, 11 Nov 2020)

  Changed paths:
    M llvm/test/tools/llvm-objcopy/ELF/only-keep-debug.test
    M llvm/tools/llvm-objcopy/ELF/Object.cpp

  Log Message:
  -----------
  [llvm-objcopy] --only-keep-debug: place zero-size segment according to its parent segment

Alternative to D74755. sectionWithinSegment() treats an empty section as having
a size of 1. Due to the rule, an empty .tdata will not be attributed to an
empty PT_TLS. (The empty p_align=64 PT_TLS is for Android Bionic's TCB
compatibility (ELF-TLS). See https://reviews.llvm.org/D62055#1507426)

Currently --only-keep-debug will not layout a segment with no section
(layoutSegmentsForOnlyKeepDebug()), thus p_offset of PT_TLS can go past the end
of the file. The strange p_offset can trigger validation errors for subsequent
tools, e.g. llvm-objcopy errors when reading back the separate debug file
(readProgramHeaders()).

This patch places such an empty segment according to its parent segment.  This
special cases works for the empty PT_TLS used in Android. For a non-empty
segment, it should have at least one non-empty section and will be handled by
the normal code. Note, p_memsz PT_LOAD is rejected by both Linux and FreeBSD.

Reviewed By: jhenderson

Differential Revision: https://reviews.llvm.org/D90897




More information about the All-commits mailing list