[all-commits] [llvm/llvm-project] 85f402: [COFF] Move section name encoding into BinaryFormat

Nicolas Miller via All-commits all-commits at lists.llvm.org
Mon Feb 21 03:51:39 PST 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 85f4023e731c0c42e45bf32bfcbf5f73c2013384
      https://github.com/llvm/llvm-project/commit/85f4023e731c0c42e45bf32bfcbf5f73c2013384
  Author: Nicolas Miller <nicolas.miller at codeplay.com>
  Date:   2022-02-21 (Mon, 21 Feb 2022)

  Changed paths:
    M llvm/include/llvm/BinaryFormat/COFF.h
    M llvm/lib/BinaryFormat/CMakeLists.txt
    A llvm/lib/BinaryFormat/COFF.cpp
    M llvm/lib/MC/WinCOFFObjectWriter.cpp

  Log Message:
  -----------
  [COFF] Move section name encoding into BinaryFormat

Large COFF section names are moved into the string table and the
section header field is the offset into the string table encoded in
ASCII for offset smaller than 7 digits and in base64 for larger
offsets.

The operation of taking the string table offsets is done in a few
places in the codebase, so it is helpful to move this operation into
`BinaryFormat` so that it can be shared everywhere it's done.

So this patch takes the implementation of this operation from
`llvm/lib/MC/WinCOFFObjectWriter.cpp` and moves it into `BinaryFormat`.

Reviewed By: jhenderson, rnk

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


  Commit: ddf528b7a092fd24647d7c6186ece7392c92de92
      https://github.com/llvm/llvm-project/commit/ddf528b7a092fd24647d7c6186ece7392c92de92
  Author: Nicolas Miller <nicolas.miller at codeplay.com>
  Date:   2022-02-21 (Mon, 21 Feb 2022)

  Changed paths:
    M llvm/lib/ObjCopy/COFF/Writer.cpp
    M llvm/lib/ObjCopy/COFF/Writer.h
    A llvm/test/tools/llvm-objcopy/COFF/section-name-encoding.s
    M llvm/tools/llvm-objcopy/CMakeLists.txt

  Log Message:
  -----------
  [llvm-objcopy][COFF] Fix section name encoding

The section name encoding for `llvm-objcopy` had two main issues, the
first is that the size used for the `snprintf` in the original code is
incorrect because `snprintf` adds a null byte, so this code was only
able to encode offsets of 6 digits - `/`, `\0` and 6 digits of the
offset - rather than the 7 digits it should support.

And the second part is that it didn't support the base64 encoding for
offsets larger than 7 digits.

This issue specifically showed up when using the `clang-offload-bundler`
with a binary containing a lot of symbols/sections, since it uses
`llvm-objcopy` to add the sections containing the offload code.

Reviewed By: jhenderson

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


Compare: https://github.com/llvm/llvm-project/compare/9453cda088c6...ddf528b7a092


More information about the All-commits mailing list