Skip to content

Commit 08f7f23

Browse files
committed
Revert "Print a warning for note segments and note sections in segments"
This reverts commit 5695096.
1 parent 17a3c77 commit 08f7f23

File tree

12 files changed

+64
-165
lines changed

12 files changed

+64
-165
lines changed

llvm/include/llvm/ObjCopy/ELF/ELFObjcopy.h

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,10 @@
99
#ifndef LLVM_OBJCOPY_ELF_ELFOBJCOPY_H
1010
#define LLVM_OBJCOPY_ELF_ELFOBJCOPY_H
1111

12-
#include "llvm/ADT/STLFunctionalExtras.h"
13-
1412
namespace llvm {
1513
class Error;
1614
class MemoryBuffer;
1715
class raw_ostream;
18-
class Twine;
1916

2017
namespace object {
2118
class ELFObjectFileBase;
@@ -28,29 +25,26 @@ struct ELFConfig;
2825
namespace elf {
2926
/// Apply the transformations described by \p Config and \p ELFConfig to
3027
/// \p In, which must represent an IHex file, and writes the result
31-
/// into \p Out. Warnings can be printed via \p WarningCallback.
28+
/// into \p Out.
3229
/// \returns any Error encountered whilst performing the operation.
3330
Error executeObjcopyOnIHex(const CommonConfig &Config,
3431
const ELFConfig &ELFConfig, MemoryBuffer &In,
35-
raw_ostream &Out,
36-
function_ref<void(const Twine &)> WarningCallback);
32+
raw_ostream &Out);
3733

3834
/// Apply the transformations described by \p Config and \p ELFConfig to
3935
/// \p In, which is treated as a raw binary input, and writes the result
40-
/// into \p Out. Warnings can be printed via \p WarningCallback.
36+
/// into \p Out.
4137
/// \returns any Error encountered whilst performing the operation.
42-
Error executeObjcopyOnRawBinary(
43-
const CommonConfig &Config, const ELFConfig &ELFConfig, MemoryBuffer &In,
44-
raw_ostream &Out, function_ref<void(const Twine &)> WarningCallback);
38+
Error executeObjcopyOnRawBinary(const CommonConfig &Config,
39+
const ELFConfig &ELFConfig, MemoryBuffer &In,
40+
raw_ostream &Out);
4541

4642
/// Apply the transformations described by \p Config and \p ELFConfig to
47-
/// \p In and writes the result into \p Out. Warnings can be printed via
48-
/// \p WarningCallback.
43+
/// \p In and writes the result into \p Out.
4944
/// \returns any Error encountered whilst performing the operation.
5045
Error executeObjcopyOnBinary(const CommonConfig &Config,
5146
const ELFConfig &ELFConfig,
52-
object::ELFObjectFileBase &In, raw_ostream &Out,
53-
function_ref<void(const Twine &)> WarningCallback);
47+
object::ELFObjectFileBase &In, raw_ostream &Out);
5448

5549
} // end namespace elf
5650
} // end namespace objcopy

llvm/include/llvm/ObjCopy/MachO/MachOObjcopy.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,9 @@
99
#ifndef LLVM_OBJCOPY_MACHO_MACHOOBJCOPY_H
1010
#define LLVM_OBJCOPY_MACHO_MACHOOBJCOPY_H
1111

12-
#include "llvm/ADT/STLFunctionalExtras.h"
13-
1412
namespace llvm {
1513
class Error;
1614
class raw_ostream;
17-
class Twine;
1815

1916
namespace object {
2017
class MachOObjectFile;
@@ -29,20 +26,17 @@ class MultiFormatConfig;
2926
namespace macho {
3027
/// Apply the transformations described by \p Config and \p MachOConfig to
3128
/// \p In and writes the result into \p Out.
32-
/// Warnings can be printed via \p WarningCallback.
3329
/// \returns any Error encountered whilst performing the operation.
3430
Error executeObjcopyOnBinary(const CommonConfig &Config,
3531
const MachOConfig &MachOConfig,
36-
object::MachOObjectFile &In, raw_ostream &Out,
37-
function_ref<void(const Twine &)> WarningCallback);
32+
object::MachOObjectFile &In, raw_ostream &Out);
3833

3934
/// Apply the transformations described by \p Config and \p MachOConfig to
4035
/// \p In and writes the result into \p Out.
41-
/// Warnings can be printed via \p WarningCallback.
4236
/// \returns any Error encountered whilst performing the operation.
4337
Error executeObjcopyOnMachOUniversalBinary(
4438
const MultiFormatConfig &Config, const object::MachOUniversalBinary &In,
45-
raw_ostream &Out, function_ref<void(const Twine &)> WarningCallback);
39+
raw_ostream &Out);
4640

4741
} // end namespace macho
4842
} // end namespace objcopy

llvm/include/llvm/ObjCopy/ObjCopy.h

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,10 @@
99
#ifndef LLVM_OBJCOPY_OBJCOPY_H
1010
#define LLVM_OBJCOPY_OBJCOPY_H
1111

12-
#include "llvm/ADT/STLFunctionalExtras.h"
1312
#include "llvm/Support/Error.h"
1413

1514
namespace llvm {
1615
class raw_ostream;
17-
class Twine;
1816

1917
namespace object {
2018
class Archive;
@@ -27,20 +25,16 @@ class MultiFormatConfig;
2725
/// Applies the transformations described by \p Config to
2826
/// each member in archive \p Ar.
2927
/// Writes a result in a file specified by \p Config.OutputFilename.
30-
/// Warnings can be printed via \p WarningCallback.
3128
/// \returns any Error encountered whilst performing the operation.
32-
Error executeObjcopyOnArchive(
33-
const MultiFormatConfig &Config, const object::Archive &Ar,
34-
function_ref<void(const Twine &)> WarningCallback);
29+
Error executeObjcopyOnArchive(const MultiFormatConfig &Config,
30+
const object::Archive &Ar);
3531

3632
/// Applies the transformations described by \p Config to \p In and writes
3733
/// the result into \p Out. This function does the dispatch based on the
3834
/// format of the input binary (COFF, ELF, MachO or wasm).
39-
/// Warnings can be printed via \p WarningCallback.
4035
/// \returns any Error encountered whilst performing the operation.
4136
Error executeObjcopyOnBinary(const MultiFormatConfig &Config,
42-
object::Binary &In, raw_ostream &Out,
43-
function_ref<void(const Twine &)> WarningCallback);
37+
object::Binary &In, raw_ostream &Out);
4438

4539
} // end namespace objcopy
4640
} // end namespace llvm

llvm/lib/ObjCopy/Archive.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ namespace objcopy {
2020
using namespace llvm::object;
2121

2222
Expected<std::vector<NewArchiveMember>>
23-
createNewArchiveMembers(const MultiFormatConfig &Config, const Archive &Ar,
24-
function_ref<void(const Twine &)> WarningCallback) {
23+
createNewArchiveMembers(const MultiFormatConfig &Config, const Archive &Ar) {
2524
std::vector<NewArchiveMember> NewArchiveMembers;
2625
Error Err = Error::success();
2726
for (const Archive::Child &Child : Ar.children(Err)) {
@@ -37,8 +36,7 @@ createNewArchiveMembers(const MultiFormatConfig &Config, const Archive &Ar,
3736
SmallVector<char, 0> Buffer;
3837
raw_svector_ostream MemStream(Buffer);
3938

40-
if (Error E = executeObjcopyOnBinary(Config, *ChildOrErr->get(), MemStream,
41-
WarningCallback))
39+
if (Error E = executeObjcopyOnBinary(Config, *ChildOrErr->get(), MemStream))
4240
return std::move(E);
4341

4442
Expected<NewArchiveMember> Member = NewArchiveMember::getOldMember(
@@ -96,11 +94,10 @@ static Error deepWriteArchive(StringRef ArcName,
9694
return Error::success();
9795
}
9896

99-
Error executeObjcopyOnArchive(
100-
const MultiFormatConfig &Config, const object::Archive &Ar,
101-
function_ref<void(const Twine &)> WarningCallback) {
97+
Error executeObjcopyOnArchive(const MultiFormatConfig &Config,
98+
const object::Archive &Ar) {
10299
Expected<std::vector<NewArchiveMember>> NewArchiveMembersOrErr =
103-
createNewArchiveMembers(Config, Ar, WarningCallback);
100+
createNewArchiveMembers(Config, Ar);
104101
if (!NewArchiveMembersOrErr)
105102
return NewArchiveMembersOrErr.takeError();
106103
const CommonConfig &CommonConfig = Config.getCommonConfig();

llvm/lib/ObjCopy/Archive.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,10 @@ class MultiFormatConfig;
2020

2121
/// Applies the transformations described by \p Config to
2222
/// each member in archive \p Ar.
23-
/// Warnings can be printed via \p WarningCallback.
2423
/// \returns Vector of transformed archive members.
2524
Expected<std::vector<NewArchiveMember>>
2625
createNewArchiveMembers(const MultiFormatConfig &Config,
27-
const object::Archive &Ar,
28-
function_ref<void(const Twine &)> WarningCallback);
26+
const object::Archive &Ar);
2927

3028
} // end namespace objcopy
3129
} // end namespace llvm

llvm/lib/ObjCopy/ELF/ELFObjcopy.cpp

Lines changed: 19 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -671,24 +671,11 @@ RemoveNoteDetail::updateData(ArrayRef<uint8_t> OldData,
671671
}
672672

673673
static Error removeNote(Object &Obj, endianness Endianness,
674-
ArrayRef<RemoveNoteInfo> NotesToRemove,
675-
function_ref<void(const Twine &)> WarningCallback) {
676-
// TODO: Support note segments.
677-
for (Segment &Seg : Obj.segments()) {
678-
if (Seg.Type == PT_NOTE) {
679-
WarningCallback("note segments are not supported");
680-
break;
681-
}
682-
}
674+
ArrayRef<RemoveNoteInfo> NotesToRemove) {
683675
for (auto &Sec : Obj.sections()) {
684-
if (Sec.Type != SHT_NOTE || !Sec.hasContents())
676+
// TODO: Support note sections in segments
677+
if (Sec.Type != SHT_NOTE || Sec.ParentSegment || !Sec.hasContents())
685678
continue;
686-
// TODO: Support note sections in segments.
687-
if (Sec.ParentSegment) {
688-
WarningCallback("cannot remove note(s) from " + Sec.Name +
689-
": sections in segments are not supported");
690-
continue;
691-
}
692679
ArrayRef<uint8_t> OldData = Sec.getContents();
693680
size_t Align = std::max<size_t>(4, Sec.Align);
694681
// Note: notes for both 32-bit and 64-bit ELF files use 4-byte words in the
@@ -772,8 +759,7 @@ static Error verifyNoteSection(StringRef Name, endianness Endianness,
772759
// depend a) on the order the options occur in or b) on some opaque priority
773760
// system. The only priority is that keeps/copies overrule removes.
774761
static Error handleArgs(const CommonConfig &Config, const ELFConfig &ELFConfig,
775-
ElfType OutputElfType, Object &Obj,
776-
function_ref<void(const Twine &)> WarningCallback) {
762+
ElfType OutputElfType, Object &Obj) {
777763
if (Config.OutputArch) {
778764
Obj.Machine = Config.OutputArch->EMachine;
779765
Obj.OSABI = Config.OutputArch->OSABI;
@@ -899,8 +885,7 @@ static Error handleArgs(const CommonConfig &Config, const ELFConfig &ELFConfig,
899885
: endianness::big;
900886

901887
if (!ELFConfig.NotesToRemove.empty()) {
902-
if (Error Err =
903-
removeNote(Obj, E, ELFConfig.NotesToRemove, WarningCallback))
888+
if (Error Err = removeNote(Obj, E, ELFConfig.NotesToRemove))
904889
return Err;
905890
}
906891

@@ -1035,25 +1020,25 @@ static Error writeOutput(const CommonConfig &Config, Object &Obj,
10351020
return Writer->write();
10361021
}
10371022

1038-
Error objcopy::elf::executeObjcopyOnIHex(
1039-
const CommonConfig &Config, const ELFConfig &ELFConfig, MemoryBuffer &In,
1040-
raw_ostream &Out, function_ref<void(const Twine &)> WarningCallback) {
1023+
Error objcopy::elf::executeObjcopyOnIHex(const CommonConfig &Config,
1024+
const ELFConfig &ELFConfig,
1025+
MemoryBuffer &In, raw_ostream &Out) {
10411026
IHexReader Reader(&In);
10421027
Expected<std::unique_ptr<Object>> Obj = Reader.create(true);
10431028
if (!Obj)
10441029
return Obj.takeError();
10451030

10461031
const ElfType OutputElfType =
10471032
getOutputElfType(Config.OutputArch.value_or(MachineInfo()));
1048-
if (Error E =
1049-
handleArgs(Config, ELFConfig, OutputElfType, **Obj, WarningCallback))
1033+
if (Error E = handleArgs(Config, ELFConfig, OutputElfType, **Obj))
10501034
return E;
10511035
return writeOutput(Config, **Obj, Out, OutputElfType);
10521036
}
10531037

1054-
Error objcopy::elf::executeObjcopyOnRawBinary(
1055-
const CommonConfig &Config, const ELFConfig &ELFConfig, MemoryBuffer &In,
1056-
raw_ostream &Out, function_ref<void(const Twine &)> WarningCallback) {
1038+
Error objcopy::elf::executeObjcopyOnRawBinary(const CommonConfig &Config,
1039+
const ELFConfig &ELFConfig,
1040+
MemoryBuffer &In,
1041+
raw_ostream &Out) {
10571042
BinaryReader Reader(&In, ELFConfig.NewSymbolVisibility);
10581043
Expected<std::unique_ptr<Object>> Obj = Reader.create(true);
10591044
if (!Obj)
@@ -1063,16 +1048,15 @@ Error objcopy::elf::executeObjcopyOnRawBinary(
10631048
// (-B<arch>).
10641049
const ElfType OutputElfType =
10651050
getOutputElfType(Config.OutputArch.value_or(MachineInfo()));
1066-
if (Error E =
1067-
handleArgs(Config, ELFConfig, OutputElfType, **Obj, WarningCallback))
1051+
if (Error E = handleArgs(Config, ELFConfig, OutputElfType, **Obj))
10681052
return E;
10691053
return writeOutput(Config, **Obj, Out, OutputElfType);
10701054
}
10711055

1072-
Error objcopy::elf::executeObjcopyOnBinary(
1073-
const CommonConfig &Config, const ELFConfig &ELFConfig,
1074-
object::ELFObjectFileBase &In, raw_ostream &Out,
1075-
function_ref<void(const Twine &)> WarningCallback) {
1056+
Error objcopy::elf::executeObjcopyOnBinary(const CommonConfig &Config,
1057+
const ELFConfig &ELFConfig,
1058+
object::ELFObjectFileBase &In,
1059+
raw_ostream &Out) {
10761060
ELFReader Reader(&In, Config.ExtractPartition);
10771061
Expected<std::unique_ptr<Object>> Obj =
10781062
Reader.create(!Config.SymbolsToAdd.empty());
@@ -1083,8 +1067,7 @@ Error objcopy::elf::executeObjcopyOnBinary(
10831067
? getOutputElfType(*Config.OutputArch)
10841068
: getOutputElfType(In);
10851069

1086-
if (Error E =
1087-
handleArgs(Config, ELFConfig, OutputElfType, **Obj, WarningCallback))
1070+
if (Error E = handleArgs(Config, ELFConfig, OutputElfType, **Obj))
10881071
return createFileError(Config.InputFilename, std::move(E));
10891072

10901073
if (Error E = writeOutput(Config, **Obj, Out, OutputElfType))

llvm/lib/ObjCopy/MachO/MachOObjcopy.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -445,10 +445,10 @@ static Error handleArgs(const CommonConfig &Config,
445445
return Error::success();
446446
}
447447

448-
Error objcopy::macho::executeObjcopyOnBinary(
449-
const CommonConfig &Config, const MachOConfig &MachOConfig,
450-
object::MachOObjectFile &In, raw_ostream &Out,
451-
function_ref<void(const Twine &)> WarningCallback) {
448+
Error objcopy::macho::executeObjcopyOnBinary(const CommonConfig &Config,
449+
const MachOConfig &MachOConfig,
450+
object::MachOObjectFile &In,
451+
raw_ostream &Out) {
452452
MachOReader Reader(In);
453453
Expected<std::unique_ptr<Object>> O = Reader.create();
454454
if (!O)
@@ -484,14 +484,14 @@ Error objcopy::macho::executeObjcopyOnBinary(
484484

485485
Error objcopy::macho::executeObjcopyOnMachOUniversalBinary(
486486
const MultiFormatConfig &Config, const MachOUniversalBinary &In,
487-
raw_ostream &Out, function_ref<void(const Twine &)> WarningCallback) {
487+
raw_ostream &Out) {
488488
SmallVector<OwningBinary<Binary>, 2> Binaries;
489489
SmallVector<Slice, 2> Slices;
490490
for (const auto &O : In.objects()) {
491491
Expected<std::unique_ptr<Archive>> ArOrErr = O.getAsArchive();
492492
if (ArOrErr) {
493493
Expected<std::vector<NewArchiveMember>> NewArchiveMembersOrErr =
494-
createNewArchiveMembers(Config, **ArOrErr, WarningCallback);
494+
createNewArchiveMembers(Config, **ArOrErr);
495495
if (!NewArchiveMembersOrErr)
496496
return NewArchiveMembersOrErr.takeError();
497497
auto Kind = (*ArOrErr)->kind();
@@ -542,9 +542,8 @@ Error objcopy::macho::executeObjcopyOnMachOUniversalBinary(
542542
if (!MachO)
543543
return MachO.takeError();
544544

545-
if (Error E =
546-
executeObjcopyOnBinary(Config.getCommonConfig(), *MachO, **ObjOrErr,
547-
MemStream, WarningCallback))
545+
if (Error E = executeObjcopyOnBinary(Config.getCommonConfig(), *MachO,
546+
**ObjOrErr, MemStream))
548547
return E;
549548

550549
auto MB = std::make_unique<SmallVectorMemoryBuffer>(

llvm/lib/ObjCopy/ObjCopy.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,15 @@ using namespace llvm::object;
3333

3434
/// The function executeObjcopyOnBinary does the dispatch based on the format
3535
/// of the input binary (ELF, MachO or COFF).
36-
Error executeObjcopyOnBinary(
37-
const MultiFormatConfig &Config, object::Binary &In, raw_ostream &Out,
38-
function_ref<void(const Twine &)> WarningCallback) {
36+
Error executeObjcopyOnBinary(const MultiFormatConfig &Config,
37+
object::Binary &In, raw_ostream &Out) {
3938
if (auto *ELFBinary = dyn_cast<object::ELFObjectFileBase>(&In)) {
4039
Expected<const ELFConfig &> ELFConfig = Config.getELFConfig();
4140
if (!ELFConfig)
4241
return ELFConfig.takeError();
4342

4443
return elf::executeObjcopyOnBinary(Config.getCommonConfig(), *ELFConfig,
45-
*ELFBinary, Out, WarningCallback);
44+
*ELFBinary, Out);
4645
}
4746
if (auto *COFFBinary = dyn_cast<object::COFFObjectFile>(&In)) {
4847
Expected<const COFFConfig &> COFFConfig = Config.getCOFFConfig();
@@ -58,12 +57,12 @@ Error executeObjcopyOnBinary(
5857
return MachOConfig.takeError();
5958

6059
return macho::executeObjcopyOnBinary(Config.getCommonConfig(), *MachOConfig,
61-
*MachOBinary, Out, WarningCallback);
60+
*MachOBinary, Out);
6261
}
6362
if (auto *MachOUniversalBinary =
6463
dyn_cast<object::MachOUniversalBinary>(&In)) {
6564
return macho::executeObjcopyOnMachOUniversalBinary(
66-
Config, *MachOUniversalBinary, Out, WarningCallback);
65+
Config, *MachOUniversalBinary, Out);
6766
}
6867
if (auto *WasmBinary = dyn_cast<object::WasmObjectFile>(&In)) {
6968
Expected<const WasmConfig &> WasmConfig = Config.getWasmConfig();

0 commit comments

Comments
 (0)