Skip to content

Commit

Permalink
Revert "[llvm-objcopy] Add --compress-sections"
Browse files Browse the repository at this point in the history
This reverts commit 9e3b64b.

Reason: Broke the UBSan buildbot. See the comments in the pull request
(#85036) for more information.
  • Loading branch information
hctim committed Apr 5, 2024
1 parent 163301d commit be8bc3c
Show file tree
Hide file tree
Showing 9 changed files with 8 additions and 278 deletions.
8 changes: 0 additions & 8 deletions llvm/docs/CommandGuide/llvm-objcopy.rst
Expand Up @@ -309,14 +309,6 @@ them.
Compress DWARF debug sections in the output, using the specified format.
Supported formats are ``zlib`` and ``zstd``. Use ``zlib`` if ``<format>`` is omitted.

.. option:: --compress-sections <section>=<format>

Compress or decompress sections matched by ``<section>`` using the specified
format. Supported formats are ``zlib`` and ``zstd``. Specify ``none`` for
decompression. When a section is matched by multiple options, the last one
wins. A wildcard ``<section>`` starting with '!' is disallowed.
Sections within a segment cannot be (de)compressed.

.. option:: --decompress-debug-sections

Decompress any compressed DWARF debug sections in the output.
Expand Down
4 changes: 0 additions & 4 deletions llvm/docs/ReleaseNotes.rst
Expand Up @@ -182,10 +182,6 @@ Changes to the LLVM tools
for ELF input to skip the specified symbols when executing other options
that can change a symbol's name, binding or visibility.

* llvm-objcopy now supports ``--compress-sections`` to compress or decompress
arbitrary sections not within a segment.
(`#85036 <https://github.com/llvm/llvm-project/pull/85036>`_.)

* llvm-profgen now supports COFF+DWARF binaries. This enables Sample-based PGO
on Windows using Intel VTune's SEP. For details on usage, see the `end-user
documentation for SPGO
Expand Down
3 changes: 0 additions & 3 deletions llvm/include/llvm/ObjCopy/CommonConfig.h
Expand Up @@ -262,9 +262,6 @@ struct CommonConfig {
bool DecompressDebugSections = false;

DebugCompressionType CompressionType = DebugCompressionType::None;

SmallVector<std::pair<NameMatcher, llvm::DebugCompressionType>, 0>
compressSections;
};

} // namespace objcopy
Expand Down
34 changes: 8 additions & 26 deletions llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp
Expand Up @@ -215,41 +215,23 @@ static Error dumpSectionToFile(StringRef SecName, StringRef Filename,
}

Error Object::compressOrDecompressSections(const CommonConfig &Config) {
// Build a list of sections we are going to replace.
// We can't call `addSection` while iterating over sections,
// Build a list of the debug sections we are going to replace.
// We can't call `AddSection` while iterating over sections,
// because it would mutate the sections array.
SmallVector<std::pair<SectionBase *, std::function<SectionBase *()>>, 0>
ToReplace;
for (SectionBase &Sec : sections()) {
std::optional<DebugCompressionType> CType;
for (auto &[Matcher, T] : Config.compressSections)
if (Matcher.matches(Sec.Name))
CType = T;
// Handle --compress-debug-sections and --decompress-debug-sections, which
// apply to non-ALLOC debug sections.
if (!(Sec.Flags & SHF_ALLOC) && StringRef(Sec.Name).starts_with(".debug")) {
if (Config.CompressionType != DebugCompressionType::None)
CType = Config.CompressionType;
else if (Config.DecompressDebugSections)
CType = DebugCompressionType::None;
}
if (!CType)
if ((Sec.Flags & SHF_ALLOC) || !StringRef(Sec.Name).starts_with(".debug"))
continue;

if (Sec.ParentSegment)
return createStringError(
errc::invalid_argument,
"section '" + Sec.Name +
"' within a segment cannot be (de)compressed");

if (auto *CS = dyn_cast<CompressedSection>(&Sec)) {
if (*CType == DebugCompressionType::None)
if (Config.DecompressDebugSections) {
ToReplace.emplace_back(
&Sec, [=] { return &addSection<DecompressedSection>(*CS); });
} else if (*CType != DebugCompressionType::None) {
ToReplace.emplace_back(&Sec, [=, S = &Sec] {
}
} else if (Config.CompressionType != DebugCompressionType::None) {
ToReplace.emplace_back(&Sec, [&, S = &Sec] {
return &addSection<CompressedSection>(
CompressedSection(*S, *CType, Is64Bits));
CompressedSection(*S, Config.CompressionType, Is64Bits));
});
}
}
Expand Down

This file was deleted.

128 changes: 0 additions & 128 deletions llvm/test/tools/llvm-objcopy/ELF/compress-sections.s

This file was deleted.

29 changes: 0 additions & 29 deletions llvm/test/tools/llvm-objcopy/ELF/decompress-sections.test
Expand Up @@ -4,42 +4,13 @@
# RUN: yaml2obj %s -o %t
# RUN: llvm-objcopy --decompress-debug-sections %t %t.de
# RUN: llvm-readelf -S %t.de | FileCheck %s
# RUN: llvm-objcopy --compress-sections '*nonalloc=none' --compress-sections .debugx=none %t %t.1.de
# RUN: cmp %t.de %t.1.de

# CHECK: Name Type Address Off Size ES Flg Lk Inf Al
# CHECK: .debug_alloc PROGBITS 0000000000000000 [[#%x,]] [[#%x,]] 00 AC 0 0 0
# CHECK-NEXT: .debug_nonalloc PROGBITS 0000000000000000 [[#%x,]] [[#%x,]] 00 0 0 1
# CHECK-NEXT: .debugx PROGBITS 0000000000000000 [[#%x,]] [[#%x,]] 00 0 0 1
# CHECK-NEXT: nodebug PROGBITS 0000000000000000 [[#%x,]] [[#%x,]] 00 C 0 0 0

# RUN: llvm-objcopy --compress-sections '.debug*=none' %t %t2.de
# RUN: llvm-readelf -S -x .debug_alloc -x .debug_nonalloc -x .debugx %t2.de | FileCheck %s --check-prefix=CHECK2

# CHECK2: Name Type Address Off Size ES Flg Lk Inf Al
# CHECK2: .debug_alloc PROGBITS 0000000000000000 [[#%x,]] [[#%x,]] 00 A 0 0 1
# CHECK2-NEXT: .debug_nonalloc PROGBITS 0000000000000000 [[#%x,]] [[#%x,]] 00 0 0 1
# CHECK2-NEXT: .debugx PROGBITS 0000000000000000 [[#%x,]] [[#%x,]] 00 0 0 1
# CHECK2-NEXT: nodebug PROGBITS 0000000000000000 [[#%x,]] [[#%x,]] 00 C 0 0 0

# CHECK2: Hex dump of section '.debug_alloc':
# CHECK2-NEXT: 0x00000000 2a000000 00000000 2a000000 00000000 *.......*.......
# CHECK2-NEXT: 0x00000010 2a000000 00000000 2a000000 00000000 *.......*.......
# CHECK2-NEXT: 0x00000020 2a000000 00000000 2a000000 00000000 *.......*.......
# CHECK2-NEXT: 0x00000030 2a000000 00000000 2a000000 00000000 *.......*.......
# CHECK2-EMPTY:
# CHECK2: Hex dump of section '.debug_nonalloc':
# CHECK2-NEXT: 0x00000000 2a000000 00000000 2a000000 00000000 *.......*.......
# CHECK2-NEXT: 0x00000010 2a000000 00000000 2a000000 00000000 *.......*.......
# CHECK2-NEXT: 0x00000020 2a000000 00000000 2a000000 00000000 *.......*.......
# CHECK2-NEXT: 0x00000030 2a000000 00000000 2a000000 00000000 *.......*.......
# CHECK2-EMPTY:
# CHECK2-NEXT: Hex dump of section '.debugx':
# CHECK2-NEXT: 0x00000000 2a000000 00000000 2a000000 00000000 *.......*.......
# CHECK2-NEXT: 0x00000010 2a000000 00000000 2a000000 00000000 *.......*.......
# CHECK2-NEXT: 0x00000020 2a000000 00000000 2a000000 00000000 *.......*.......
# CHECK2-NEXT: 0x00000030 2a000000 00000000 2a000000 00000000 *.......*.......

--- !ELF
FileHeader:
Class: ELFCLASS64
Expand Down
36 changes: 0 additions & 36 deletions llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
Expand Up @@ -736,42 +736,6 @@ objcopy::parseObjcopyOptions(ArrayRef<const char *> RawArgsArr,
return createStringError(errc::invalid_argument, Reason);
}

for (const auto *A : InputArgs.filtered(OBJCOPY_compress_sections)) {
SmallVector<StringRef, 0> Fields;
StringRef(A->getValue()).split(Fields, '=');
if (Fields.size() != 2 || Fields[1].empty()) {
return createStringError(
errc::invalid_argument,
A->getSpelling() +
": parse error, not 'section-glob=[none|zlib|zstd]'");
}

auto Type = StringSwitch<DebugCompressionType>(Fields[1])
.Case("zlib", DebugCompressionType::Zlib)
.Case("zstd", DebugCompressionType::Zstd)
.Default(DebugCompressionType::None);
if (Type == DebugCompressionType::None && Fields[1] != "none") {
return createStringError(
errc::invalid_argument,
"invalid or unsupported --compress-sections format: %s",
A->getValue());
}

auto &P = Config.compressSections.emplace_back();
P.second = Type;
auto Matcher =
NameOrPattern::create(Fields[0], SectionMatchStyle, ErrorCallback);
// =none allows overriding a previous =zlib or =zstd. Reject negative
// patterns, which would be confusing.
if (Matcher && !Matcher->isPositiveMatch()) {
return createStringError(
errc::invalid_argument,
"--compress-sections: negative pattern is unsupported");
}
if (Error E = P.first.addMatcher(std::move(Matcher)))
return std::move(E);
}

Config.AddGnuDebugLink = InputArgs.getLastArgValue(OBJCOPY_add_gnu_debuglink);
// The gnu_debuglink's target is expected to not change or else its CRC would
// become invalidated and get rejected. We can avoid recalculating the
Expand Down
6 changes: 0 additions & 6 deletions llvm/tools/llvm-objcopy/ObjcopyOpts.td
Expand Up @@ -35,12 +35,6 @@ def : Flag<["--"], "compress-debug-sections">, Alias<compress_debug_sections>,
AliasArgs<["zlib"]>;
def decompress_debug_sections : Flag<["--"], "decompress-debug-sections">,
HelpText<"Decompress DWARF debug sections">;
defm compress_sections
: Eq<"compress-sections",
"Compress or decompress sections using specified format. Supported "
"formats: zlib, zstd. Specify 'none' for decompression">,
MetaVarName<"<section-glob>=<format>">;

defm split_dwo
: Eq<"split-dwo", "Equivalent to --extract-dwo and <dwo-file> as the output file and no other options, "
"and then --strip-dwo on the input file">,
Expand Down

0 comments on commit be8bc3c

Please sign in to comment.