@@ -189,13 +189,10 @@ static Error dumpSectionToFile(StringRef SecName, StringRef Filename,
189189 StringRef InputFilename, Object &Obj) {
190190 for (auto &Sec : Obj.sections ()) {
191191 if (Sec.Name == SecName) {
192- if (Sec.Type == SHT_NOBITS) {
193- Error E =
194- createStringError (object_error::parse_failed,
195- " cannot dump section '%s': it has no contents" ,
196- SecName.str ().c_str ());
197- return createFileError (InputFilename, std::move (E));
198- }
192+ if (Sec.Type == SHT_NOBITS)
193+ return createFileError (InputFilename, object_error::parse_failed,
194+ " cannot dump section '%s': it has no contents" ,
195+ SecName.str ().c_str ());
199196 Expected<std::unique_ptr<FileOutputBuffer>> BufferOrErr =
200197 FileOutputBuffer::create (Filename, Sec.OriginalData .size ());
201198 if (!BufferOrErr)
@@ -208,10 +205,9 @@ static Error dumpSectionToFile(StringRef SecName, StringRef Filename,
208205 return Error::success ();
209206 }
210207 }
211- Error E = createStringError (object_error::parse_failed,
212- " section '%s' not found" , SecName.str ().c_str ());
213208
214- return createFileError (InputFilename, std::move (E));
209+ return createFileError (InputFilename, object_error::parse_failed,
210+ " section '%s' not found" , SecName.str ().c_str ());
215211}
216212
217213Error Object::compressOrDecompressSections (const CommonConfig &Config) {
@@ -832,37 +828,32 @@ static Error handleArgs(const CommonConfig &Config, const ELFConfig &ELFConfig,
832828 if (Config.ChangeSectionLMAValAll > 0 &&
833829 Seg.PAddr > std::numeric_limits<uint64_t >::max () -
834830 Config.ChangeSectionLMAValAll ) {
835- Error E = createStringError (
836- errc::invalid_argument,
831+ return createFileError (
832+ Config. InputFilename , errc::invalid_argument,
837833 " address 0x" + Twine::utohexstr (Seg.PAddr ) +
838834 " cannot be increased by 0x" +
839835 Twine::utohexstr (Config.ChangeSectionLMAValAll ) +
840836 " . The result would overflow" );
841- return createFileError (Config.InputFilename , std::move (E));
842837 } else if (Config.ChangeSectionLMAValAll < 0 &&
843838 Seg.PAddr < std::numeric_limits<uint64_t >::min () -
844839 Config.ChangeSectionLMAValAll ) {
845- Error E = createStringError (
846- errc::invalid_argument,
840+ return createFileError (
841+ Config. InputFilename , errc::invalid_argument,
847842 " address 0x" + Twine::utohexstr (Seg.PAddr ) +
848843 " cannot be decreased by 0x" +
849844 Twine::utohexstr (std::abs (Config.ChangeSectionLMAValAll )) +
850845 " . The result would underflow" );
851-
852- return createFileError (Config.InputFilename , std::move (E));
853846 }
854847 Seg.PAddr += Config.ChangeSectionLMAValAll ;
855848 }
856849 }
857850 }
858851
859852 if (!Config.ChangeSectionAddress .empty ()) {
860- if (Obj.Type != ELF::ET_REL) {
861- Error E = createStringError (
862- object_error::invalid_file_type,
853+ if (Obj.Type != ELF::ET_REL)
854+ return createFileError (
855+ Config. InputFilename , object_error::invalid_file_type,
863856 " cannot change section address in a non-relocatable file" );
864- return createFileError (Config.InputFilename , std::move (E));
865- }
866857 StringMap<AddressUpdate> SectionsToUpdateAddress;
867858 for (const SectionPatternAddressUpdate &PatternUpdate :
868859 make_range (Config.ChangeSectionAddress .rbegin (),
@@ -873,26 +864,22 @@ static Error handleArgs(const CommonConfig &Config, const ELFConfig &ELFConfig,
873864 .second ) {
874865 if (PatternUpdate.Update .Kind == AdjustKind::Subtract &&
875866 Sec.Addr < PatternUpdate.Update .Value ) {
876- Error E = createStringError (
877- errc::invalid_argument,
867+ return createFileError (
868+ Config. InputFilename , errc::invalid_argument,
878869 " address 0x" + Twine::utohexstr (Sec.Addr ) +
879870 " cannot be decreased by 0x" +
880871 Twine::utohexstr (PatternUpdate.Update .Value ) +
881872 " . The result would underflow" );
882-
883- return createFileError (Config.InputFilename , std::move (E));
884873 }
885874 if (PatternUpdate.Update .Kind == AdjustKind::Add &&
886875 Sec.Addr > std::numeric_limits<uint64_t >::max () -
887876 PatternUpdate.Update .Value ) {
888- Error E = createStringError (
889- errc::invalid_argument,
877+ return createFileError (
878+ Config. InputFilename , errc::invalid_argument,
890879 " address 0x" + Twine::utohexstr (Sec.Addr ) +
891880 " cannot be increased by 0x" +
892881 Twine::utohexstr (PatternUpdate.Update .Value ) +
893882 " . The result would overflow" );
894-
895- return createFileError (Config.InputFilename , std::move (E));
896883 }
897884
898885 switch (PatternUpdate.Update .Kind ) {
0 commit comments