@@ -186,27 +186,28 @@ static std::unique_ptr<Writer> createWriter(const CommonConfig &Config,
186186}
187187
188188static Error dumpSectionToFile (StringRef SecName, StringRef Filename,
189- Object &Obj) {
189+ StringRef InputFilename, Object &Obj) {
190190 for (auto &Sec : Obj.sections ()) {
191191 if (Sec.Name == SecName) {
192192 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 ());
196196 Expected<std::unique_ptr<FileOutputBuffer>> BufferOrErr =
197197 FileOutputBuffer::create (Filename, Sec.OriginalData .size ());
198198 if (!BufferOrErr)
199- return BufferOrErr.takeError ();
199+ return createFileError (Filename, BufferOrErr.takeError () );
200200 std::unique_ptr<FileOutputBuffer> Buf = std::move (*BufferOrErr);
201201 std::copy (Sec.OriginalData .begin (), Sec.OriginalData .end (),
202202 Buf->getBufferStart ());
203203 if (Error E = Buf->commit ())
204- return E ;
204+ return createFileError (Filename, std::move (E)) ;
205205 return Error::success ();
206206 }
207207 }
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 ());
210211}
211212
212213Error Object::compressOrDecompressSections (const CommonConfig &Config) {
@@ -798,7 +799,8 @@ static Error handleArgs(const CommonConfig &Config, const ELFConfig &ELFConfig,
798799 StringRef SectionName;
799800 StringRef FileName;
800801 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))
802804 return E;
803805 }
804806
@@ -807,10 +809,10 @@ static Error handleArgs(const CommonConfig &Config, const ELFConfig &ELFConfig,
807809 // us to avoid reporting the inappropriate errors about removing symbols
808810 // named in relocations.
809811 if (Error E = replaceAndRemoveSections (Config, ELFConfig, Obj))
810- return E ;
812+ return createFileError (Config. InputFilename , std::move (E)) ;
811813
812814 if (Error E = updateAndRemoveSymbols (Config, ELFConfig, Obj))
813- return E ;
815+ return createFileError (Config. InputFilename , std::move (E)) ;
814816
815817 if (!Config.SetSectionAlignment .empty ()) {
816818 for (SectionBase &Sec : Obj.sections ()) {
@@ -826,17 +828,17 @@ static Error handleArgs(const CommonConfig &Config, const ELFConfig &ELFConfig,
826828 if (Config.ChangeSectionLMAValAll > 0 &&
827829 Seg.PAddr > std::numeric_limits<uint64_t >::max () -
828830 Config.ChangeSectionLMAValAll ) {
829- return createStringError (
830- errc::invalid_argument,
831+ return createFileError (
832+ Config. InputFilename , errc::invalid_argument,
831833 " address 0x" + Twine::utohexstr (Seg.PAddr ) +
832834 " cannot be increased by 0x" +
833835 Twine::utohexstr (Config.ChangeSectionLMAValAll ) +
834836 " . The result would overflow" );
835837 } else if (Config.ChangeSectionLMAValAll < 0 &&
836838 Seg.PAddr < std::numeric_limits<uint64_t >::min () -
837839 Config.ChangeSectionLMAValAll ) {
838- return createStringError (
839- errc::invalid_argument,
840+ return createFileError (
841+ Config. InputFilename , errc::invalid_argument,
840842 " address 0x" + Twine::utohexstr (Seg.PAddr ) +
841843 " cannot be decreased by 0x" +
842844 Twine::utohexstr (std::abs (Config.ChangeSectionLMAValAll )) +
@@ -849,10 +851,9 @@ static Error handleArgs(const CommonConfig &Config, const ELFConfig &ELFConfig,
849851
850852 if (!Config.ChangeSectionAddress .empty ()) {
851853 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,
854856 " cannot change section address in a non-relocatable file" );
855-
856857 StringMap<AddressUpdate> SectionsToUpdateAddress;
857858 for (const SectionPatternAddressUpdate &PatternUpdate :
858859 make_range (Config.ChangeSectionAddress .rbegin (),
@@ -863,8 +864,8 @@ static Error handleArgs(const CommonConfig &Config, const ELFConfig &ELFConfig,
863864 .second ) {
864865 if (PatternUpdate.Update .Kind == AdjustKind::Subtract &&
865866 Sec.Addr < PatternUpdate.Update .Value ) {
866- return createStringError (
867- errc::invalid_argument,
867+ return createFileError (
868+ Config. InputFilename , errc::invalid_argument,
868869 " address 0x" + Twine::utohexstr (Sec.Addr ) +
869870 " cannot be decreased by 0x" +
870871 Twine::utohexstr (PatternUpdate.Update .Value ) +
@@ -873,8 +874,8 @@ static Error handleArgs(const CommonConfig &Config, const ELFConfig &ELFConfig,
873874 if (PatternUpdate.Update .Kind == AdjustKind::Add &&
874875 Sec.Addr > std::numeric_limits<uint64_t >::max () -
875876 PatternUpdate.Update .Value ) {
876- return createStringError (
877- errc::invalid_argument,
877+ return createFileError (
878+ Config. InputFilename , errc::invalid_argument,
878879 " address 0x" + Twine::utohexstr (Sec.Addr ) +
879880 " cannot be increased by 0x" +
880881 Twine::utohexstr (PatternUpdate.Update .Value ) +
@@ -909,7 +910,7 @@ static Error handleArgs(const CommonConfig &Config, const ELFConfig &ELFConfig,
909910 if (!ELFConfig.NotesToRemove .empty ()) {
910911 if (Error Err =
911912 removeNotes (Obj, E, ELFConfig.NotesToRemove , Config.ErrorCallback ))
912- return Err;
913+ return createFileError (Config. InputFilename , std::move ( Err)) ;
913914 }
914915
915916 for (const NewSectionInfo &AddedSection : Config.AddSection ) {
@@ -924,15 +925,15 @@ static Error handleArgs(const CommonConfig &Config, const ELFConfig &ELFConfig,
924925 return Error::success ();
925926 };
926927 if (Error E = handleUserSection (AddedSection, AddSection))
927- return E ;
928+ return createFileError (Config. InputFilename , std::move (E)) ;
928929 }
929930
930931 for (const NewSectionInfo &NewSection : Config.UpdateSection ) {
931932 auto UpdateSection = [&](StringRef Name, ArrayRef<uint8_t > Data) {
932933 return Obj.updateSection (Name, Data);
933934 };
934935 if (Error E = handleUserSection (NewSection, UpdateSection))
935- return E ;
936+ return createFileError (Config. InputFilename , std::move (E)) ;
936937 }
937938
938939 if (!Config.AddGnuDebugLink .empty ())
@@ -943,7 +944,7 @@ static Error handleArgs(const CommonConfig &Config, const ELFConfig &ELFConfig,
943944 // before adding new symbols.
944945 if (!Obj.SymbolTable && !Config.SymbolsToAdd .empty ())
945946 if (Error E = Obj.addNewSymbolTable ())
946- return E ;
947+ return createFileError (Config. InputFilename , std::move (E)) ;
947948
948949 for (const NewSymbolInfo &SI : Config.SymbolsToAdd )
949950 addSymbol (Obj, SI, ELFConfig.NewSymbolVisibility );
@@ -955,7 +956,7 @@ static Error handleArgs(const CommonConfig &Config, const ELFConfig &ELFConfig,
955956 if (Iter != Config.SetSectionFlags .end ()) {
956957 const SectionFlagsUpdate &SFU = Iter->second ;
957958 if (Error E = setSectionFlagsAndType (Sec, SFU.NewFlags , Obj.Machine ))
958- return E ;
959+ return createFileError (Config. InputFilename , std::move (E)) ;
959960 }
960961 auto It2 = Config.SetSectionType .find (Sec.Name );
961962 if (It2 != Config.SetSectionType .end ())
@@ -974,7 +975,7 @@ static Error handleArgs(const CommonConfig &Config, const ELFConfig &ELFConfig,
974975 Sec.Name = std::string (SR.NewName );
975976 if (SR.NewFlags ) {
976977 if (Error E = setSectionFlagsAndType (Sec, *SR.NewFlags , Obj.Machine ))
977- return E ;
978+ return createFileError (Config. InputFilename , std::move (E)) ;
978979 }
979980 RenamedSections.insert (&Sec);
980981 } else if (RelocSec && !(Sec.Flags & SHF_ALLOC))
@@ -1091,7 +1092,7 @@ Error objcopy::elf::executeObjcopyOnBinary(const CommonConfig &Config,
10911092 : getOutputElfType (In);
10921093
10931094 if (Error E = handleArgs (Config, ELFConfig, OutputElfType, **Obj))
1094- return createFileError (Config. InputFilename , std::move (E)) ;
1095+ return E ;
10951096
10961097 if (Error E = writeOutput (Config, **Obj, Out, OutputElfType))
10971098 return createFileError (Config.InputFilename , std::move (E));
0 commit comments