This is an archive of the discontinued LLVM Phabricator instance.

[llvm-objcopy] - Remove an excessive zlib::isAvailable() check and dead code.
ClosedPublic

Authored by grimar on Mar 6 2019, 3:53 AM.

Details

Summary

There are 2 places where llvm-objcopy creates CompressedSection:

  1. For --compress-debug-sections. It might create the compressed section from

regular here:
https://github.com/llvm-mirror/llvm/blob/master/tools/llvm-objcopy/ELF/ELFObjcopy.cpp#L486

  1. All initially compressed sections are created as CompressedSection during reading the sections

from an object:
https://github.com/llvm-mirror/llvm/blob/master/tools/llvm-objcopy/ELF/Object.cpp#L1118
Those have DebugCompressionType::None type and a different constructor.

Case 1 has the following code in its constructor:

if (!zlib::isAvailable()) {
  CompressionType = DebugCompressionType::None;
  return;
}

(https://github.com/llvm-mirror/llvm/blob/master/tools/llvm-objcopy/ELF/Object.cpp#L267)

We can never reach that code with because would report an error much earlier:
https://github.com/llvm-mirror/llvm/blob/master/tools/llvm-objcopy/CopyConfig.cpp#L480

So the code I am removing is dead. Landing this will address the issue mentioned in https://bugs.llvm.org/show_bug.cgi?id=40886.

Diff Detail

Repository
rL LLVM

Event Timeline

grimar created this revision.Mar 6 2019, 3:53 AM
jhenderson added inline comments.Mar 6 2019, 4:33 AM
tools/llvm-objcopy/ELF/Object.cpp
265 ↗(On Diff #189479)

Maybe you should have an assertion here so that we don't try to create CompressedSection if there is no zlib?

grimar marked an inline comment as done.Mar 6 2019, 4:45 AM
grimar added inline comments.
tools/llvm-objcopy/ELF/Object.cpp
265 ↗(On Diff #189479)

FTR: we still want to create it for the case 2 from the description, but it uses a different constructor.
I'll update the patch with an assert here.

jhenderson accepted this revision.Mar 6 2019, 4:51 AM

LGTM, even without the assertion.

tools/llvm-objcopy/ELF/Object.cpp
265 ↗(On Diff #189479)

Right, yes, but as I just realised in D59017, no need for the assertion as zlib::compress already does it.

This revision is now accepted and ready to land.Mar 6 2019, 4:51 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptMar 6 2019, 6:09 AM