@@ -671,11 +671,24 @@ RemoveNoteDetail::updateData(ArrayRef<uint8_t> OldData,
671671}
672672
673673static Error removeNote (Object &Obj, endianness Endianness,
674- ArrayRef<RemoveNoteInfo> NotesToRemove) {
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+ }
675683 for (auto &Sec : Obj.sections ()) {
676- // TODO: Support note sections in segments
677- if (Sec.Type != SHT_NOTE || Sec.ParentSegment || !Sec.hasContents ())
684+ if (Sec.Type != SHT_NOTE || !Sec.hasContents ())
678685 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+ }
679692 ArrayRef<uint8_t > OldData = Sec.getContents ();
680693 size_t Align = std::max<size_t >(4 , Sec.Align );
681694 // Note: notes for both 32-bit and 64-bit ELF files use 4-byte words in the
@@ -759,7 +772,8 @@ static Error verifyNoteSection(StringRef Name, endianness Endianness,
759772// depend a) on the order the options occur in or b) on some opaque priority
760773// system. The only priority is that keeps/copies overrule removes.
761774static Error handleArgs (const CommonConfig &Config, const ELFConfig &ELFConfig,
762- ElfType OutputElfType, Object &Obj) {
775+ ElfType OutputElfType, Object &Obj,
776+ function_ref<void (const Twine &)> WarningCallback) {
763777 if (Config.OutputArch ) {
764778 Obj.Machine = Config.OutputArch ->EMachine ;
765779 Obj.OSABI = Config.OutputArch ->OSABI ;
@@ -885,7 +899,8 @@ static Error handleArgs(const CommonConfig &Config, const ELFConfig &ELFConfig,
885899 : endianness::big;
886900
887901 if (!ELFConfig.NotesToRemove .empty ()) {
888- if (Error Err = removeNote (Obj, E, ELFConfig.NotesToRemove ))
902+ if (Error Err =
903+ removeNote (Obj, E, ELFConfig.NotesToRemove , WarningCallback))
889904 return Err;
890905 }
891906
@@ -1020,25 +1035,25 @@ static Error writeOutput(const CommonConfig &Config, Object &Obj,
10201035 return Writer->write ();
10211036}
10221037
1023- Error objcopy::elf::executeObjcopyOnIHex (const CommonConfig &Config,
1024- const ELFConfig &ELFConfig,
1025- MemoryBuffer &In, raw_ostream &Out ) {
1038+ Error objcopy::elf::executeObjcopyOnIHex (
1039+ const CommonConfig &Config, const ELFConfig &ELFConfig, MemoryBuffer &In ,
1040+ raw_ostream &Out, function_ref< void ( const Twine &)> WarningCallback ) {
10261041 IHexReader Reader (&In);
10271042 Expected<std::unique_ptr<Object>> Obj = Reader.create (true );
10281043 if (!Obj)
10291044 return Obj.takeError ();
10301045
10311046 const ElfType OutputElfType =
10321047 getOutputElfType (Config.OutputArch .value_or (MachineInfo ()));
1033- if (Error E = handleArgs (Config, ELFConfig, OutputElfType, **Obj))
1048+ if (Error E =
1049+ handleArgs (Config, ELFConfig, OutputElfType, **Obj, WarningCallback))
10341050 return E;
10351051 return writeOutput (Config, **Obj, Out, OutputElfType);
10361052}
10371053
1038- Error objcopy::elf::executeObjcopyOnRawBinary (const CommonConfig &Config,
1039- const ELFConfig &ELFConfig,
1040- MemoryBuffer &In,
1041- raw_ostream &Out) {
1054+ Error objcopy::elf::executeObjcopyOnRawBinary (
1055+ const CommonConfig &Config, const ELFConfig &ELFConfig, MemoryBuffer &In,
1056+ raw_ostream &Out, function_ref<void (const Twine &)> WarningCallback) {
10421057 BinaryReader Reader (&In, ELFConfig.NewSymbolVisibility );
10431058 Expected<std::unique_ptr<Object>> Obj = Reader.create (true );
10441059 if (!Obj)
@@ -1048,15 +1063,16 @@ Error objcopy::elf::executeObjcopyOnRawBinary(const CommonConfig &Config,
10481063 // (-B<arch>).
10491064 const ElfType OutputElfType =
10501065 getOutputElfType (Config.OutputArch .value_or (MachineInfo ()));
1051- if (Error E = handleArgs (Config, ELFConfig, OutputElfType, **Obj))
1066+ if (Error E =
1067+ handleArgs (Config, ELFConfig, OutputElfType, **Obj, WarningCallback))
10521068 return E;
10531069 return writeOutput (Config, **Obj, Out, OutputElfType);
10541070}
10551071
1056- Error objcopy::elf::executeObjcopyOnBinary (const CommonConfig &Config,
1057- const ELFConfig &ELFConfig,
1058- object::ELFObjectFileBase &In,
1059- raw_ostream &Out ) {
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 ) {
10601076 ELFReader Reader (&In, Config.ExtractPartition );
10611077 Expected<std::unique_ptr<Object>> Obj =
10621078 Reader.create (!Config.SymbolsToAdd .empty ());
@@ -1067,7 +1083,8 @@ Error objcopy::elf::executeObjcopyOnBinary(const CommonConfig &Config,
10671083 ? getOutputElfType (*Config.OutputArch )
10681084 : getOutputElfType (In);
10691085
1070- if (Error E = handleArgs (Config, ELFConfig, OutputElfType, **Obj))
1086+ if (Error E =
1087+ handleArgs (Config, ELFConfig, OutputElfType, **Obj, WarningCallback))
10711088 return createFileError (Config.InputFilename , std::move (E));
10721089
10731090 if (Error E = writeOutput (Config, **Obj, Out, OutputElfType))
0 commit comments