@@ -186,27 +186,28 @@ static std::unique_ptr<Writer> createWriter(const CommonConfig &Config,
186
186
}
187
187
188
188
static Error dumpSectionToFile (StringRef SecName, StringRef Filename,
189
- Object &Obj) {
189
+ StringRef InputFilename, Object &Obj) {
190
190
for (auto &Sec : Obj.sections ()) {
191
191
if (Sec.Name == SecName) {
192
192
if (Sec.Type == SHT_NOBITS)
193
- return createStringError ( object_error::parse_failed,
194
- " cannot dump section '%s': it has no contents" ,
195
- SecName.str ().c_str ());
193
+ return createFileError (InputFilename, object_error::parse_failed,
194
+ " cannot dump section '%s': it has no contents" ,
195
+ SecName.str ().c_str ());
196
196
Expected<std::unique_ptr<FileOutputBuffer>> BufferOrErr =
197
197
FileOutputBuffer::create (Filename, Sec.OriginalData .size ());
198
198
if (!BufferOrErr)
199
- return BufferOrErr.takeError ();
199
+ return createFileError (Filename, BufferOrErr.takeError () );
200
200
std::unique_ptr<FileOutputBuffer> Buf = std::move (*BufferOrErr);
201
201
std::copy (Sec.OriginalData .begin (), Sec.OriginalData .end (),
202
202
Buf->getBufferStart ());
203
203
if (Error E = Buf->commit ())
204
- return E ;
204
+ return createFileError (Filename, std::move (E)) ;
205
205
return Error::success ();
206
206
}
207
207
}
208
- return createStringError (object_error::parse_failed, " section '%s' not found" ,
209
- SecName.str ().c_str ());
208
+
209
+ return createFileError (InputFilename, object_error::parse_failed,
210
+ " section '%s' not found" , SecName.str ().c_str ());
210
211
}
211
212
212
213
Error Object::compressOrDecompressSections (const CommonConfig &Config) {
@@ -798,7 +799,8 @@ static Error handleArgs(const CommonConfig &Config, const ELFConfig &ELFConfig,
798
799
StringRef SectionName;
799
800
StringRef FileName;
800
801
std::tie (SectionName, FileName) = Flag.split (' =' );
801
- if (Error E = dumpSectionToFile (SectionName, FileName, Obj))
802
+ if (Error E =
803
+ dumpSectionToFile (SectionName, FileName, Config.InputFilename , Obj))
802
804
return E;
803
805
}
804
806
@@ -807,10 +809,10 @@ static Error handleArgs(const CommonConfig &Config, const ELFConfig &ELFConfig,
807
809
// us to avoid reporting the inappropriate errors about removing symbols
808
810
// named in relocations.
809
811
if (Error E = replaceAndRemoveSections (Config, ELFConfig, Obj))
810
- return E ;
812
+ return createFileError (Config. InputFilename , std::move (E)) ;
811
813
812
814
if (Error E = updateAndRemoveSymbols (Config, ELFConfig, Obj))
813
- return E ;
815
+ return createFileError (Config. InputFilename , std::move (E)) ;
814
816
815
817
if (!Config.SetSectionAlignment .empty ()) {
816
818
for (SectionBase &Sec : Obj.sections ()) {
@@ -826,17 +828,17 @@ static Error handleArgs(const CommonConfig &Config, const ELFConfig &ELFConfig,
826
828
if (Config.ChangeSectionLMAValAll > 0 &&
827
829
Seg.PAddr > std::numeric_limits<uint64_t >::max () -
828
830
Config.ChangeSectionLMAValAll ) {
829
- return createStringError (
830
- errc::invalid_argument,
831
+ return createFileError (
832
+ Config. InputFilename , errc::invalid_argument,
831
833
" address 0x" + Twine::utohexstr (Seg.PAddr ) +
832
834
" cannot be increased by 0x" +
833
835
Twine::utohexstr (Config.ChangeSectionLMAValAll ) +
834
836
" . The result would overflow" );
835
837
} else if (Config.ChangeSectionLMAValAll < 0 &&
836
838
Seg.PAddr < std::numeric_limits<uint64_t >::min () -
837
839
Config.ChangeSectionLMAValAll ) {
838
- return createStringError (
839
- errc::invalid_argument,
840
+ return createFileError (
841
+ Config. InputFilename , errc::invalid_argument,
840
842
" address 0x" + Twine::utohexstr (Seg.PAddr ) +
841
843
" cannot be decreased by 0x" +
842
844
Twine::utohexstr (std::abs (Config.ChangeSectionLMAValAll )) +
@@ -849,10 +851,9 @@ static Error handleArgs(const CommonConfig &Config, const ELFConfig &ELFConfig,
849
851
850
852
if (!Config.ChangeSectionAddress .empty ()) {
851
853
if (Obj.Type != ELF::ET_REL)
852
- return createStringError (
853
- object_error::invalid_file_type,
854
+ return createFileError (
855
+ Config. InputFilename , object_error::invalid_file_type,
854
856
" cannot change section address in a non-relocatable file" );
855
-
856
857
StringMap<AddressUpdate> SectionsToUpdateAddress;
857
858
for (const SectionPatternAddressUpdate &PatternUpdate :
858
859
make_range (Config.ChangeSectionAddress .rbegin (),
@@ -863,8 +864,8 @@ static Error handleArgs(const CommonConfig &Config, const ELFConfig &ELFConfig,
863
864
.second ) {
864
865
if (PatternUpdate.Update .Kind == AdjustKind::Subtract &&
865
866
Sec.Addr < PatternUpdate.Update .Value ) {
866
- return createStringError (
867
- errc::invalid_argument,
867
+ return createFileError (
868
+ Config. InputFilename , errc::invalid_argument,
868
869
" address 0x" + Twine::utohexstr (Sec.Addr ) +
869
870
" cannot be decreased by 0x" +
870
871
Twine::utohexstr (PatternUpdate.Update .Value ) +
@@ -873,8 +874,8 @@ static Error handleArgs(const CommonConfig &Config, const ELFConfig &ELFConfig,
873
874
if (PatternUpdate.Update .Kind == AdjustKind::Add &&
874
875
Sec.Addr > std::numeric_limits<uint64_t >::max () -
875
876
PatternUpdate.Update .Value ) {
876
- return createStringError (
877
- errc::invalid_argument,
877
+ return createFileError (
878
+ Config. InputFilename , errc::invalid_argument,
878
879
" address 0x" + Twine::utohexstr (Sec.Addr ) +
879
880
" cannot be increased by 0x" +
880
881
Twine::utohexstr (PatternUpdate.Update .Value ) +
@@ -909,7 +910,7 @@ static Error handleArgs(const CommonConfig &Config, const ELFConfig &ELFConfig,
909
910
if (!ELFConfig.NotesToRemove .empty ()) {
910
911
if (Error Err =
911
912
removeNotes (Obj, E, ELFConfig.NotesToRemove , Config.ErrorCallback ))
912
- return Err;
913
+ return createFileError (Config. InputFilename , std::move ( Err)) ;
913
914
}
914
915
915
916
for (const NewSectionInfo &AddedSection : Config.AddSection ) {
@@ -924,15 +925,15 @@ static Error handleArgs(const CommonConfig &Config, const ELFConfig &ELFConfig,
924
925
return Error::success ();
925
926
};
926
927
if (Error E = handleUserSection (AddedSection, AddSection))
927
- return E ;
928
+ return createFileError (Config. InputFilename , std::move (E)) ;
928
929
}
929
930
930
931
for (const NewSectionInfo &NewSection : Config.UpdateSection ) {
931
932
auto UpdateSection = [&](StringRef Name, ArrayRef<uint8_t > Data) {
932
933
return Obj.updateSection (Name, Data);
933
934
};
934
935
if (Error E = handleUserSection (NewSection, UpdateSection))
935
- return E ;
936
+ return createFileError (Config. InputFilename , std::move (E)) ;
936
937
}
937
938
938
939
if (!Config.AddGnuDebugLink .empty ())
@@ -943,7 +944,7 @@ static Error handleArgs(const CommonConfig &Config, const ELFConfig &ELFConfig,
943
944
// before adding new symbols.
944
945
if (!Obj.SymbolTable && !Config.SymbolsToAdd .empty ())
945
946
if (Error E = Obj.addNewSymbolTable ())
946
- return E ;
947
+ return createFileError (Config. InputFilename , std::move (E)) ;
947
948
948
949
for (const NewSymbolInfo &SI : Config.SymbolsToAdd )
949
950
addSymbol (Obj, SI, ELFConfig.NewSymbolVisibility );
@@ -955,7 +956,7 @@ static Error handleArgs(const CommonConfig &Config, const ELFConfig &ELFConfig,
955
956
if (Iter != Config.SetSectionFlags .end ()) {
956
957
const SectionFlagsUpdate &SFU = Iter->second ;
957
958
if (Error E = setSectionFlagsAndType (Sec, SFU.NewFlags , Obj.Machine ))
958
- return E ;
959
+ return createFileError (Config. InputFilename , std::move (E)) ;
959
960
}
960
961
auto It2 = Config.SetSectionType .find (Sec.Name );
961
962
if (It2 != Config.SetSectionType .end ())
@@ -974,7 +975,7 @@ static Error handleArgs(const CommonConfig &Config, const ELFConfig &ELFConfig,
974
975
Sec.Name = std::string (SR.NewName );
975
976
if (SR.NewFlags ) {
976
977
if (Error E = setSectionFlagsAndType (Sec, *SR.NewFlags , Obj.Machine ))
977
- return E ;
978
+ return createFileError (Config. InputFilename , std::move (E)) ;
978
979
}
979
980
RenamedSections.insert (&Sec);
980
981
} else if (RelocSec && !(Sec.Flags & SHF_ALLOC))
@@ -1091,7 +1092,7 @@ Error objcopy::elf::executeObjcopyOnBinary(const CommonConfig &Config,
1091
1092
: getOutputElfType (In);
1092
1093
1093
1094
if (Error E = handleArgs (Config, ELFConfig, OutputElfType, **Obj))
1094
- return createFileError (Config. InputFilename , std::move (E)) ;
1095
+ return E ;
1095
1096
1096
1097
if (Error E = writeOutput (Config, **Obj, Out, OutputElfType))
1097
1098
return createFileError (Config.InputFilename , std::move (E));
0 commit comments