@@ -189,13 +189,10 @@ static Error dumpSectionToFile(StringRef SecName, StringRef Filename,
189
189
StringRef InputFilename, Object &Obj) {
190
190
for (auto &Sec : Obj.sections ()) {
191
191
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 ());
199
196
Expected<std::unique_ptr<FileOutputBuffer>> BufferOrErr =
200
197
FileOutputBuffer::create (Filename, Sec.OriginalData .size ());
201
198
if (!BufferOrErr)
@@ -208,10 +205,9 @@ static Error dumpSectionToFile(StringRef SecName, StringRef Filename,
208
205
return Error::success ();
209
206
}
210
207
}
211
- Error E = createStringError (object_error::parse_failed,
212
- " section '%s' not found" , SecName.str ().c_str ());
213
208
214
- return createFileError (InputFilename, std::move (E));
209
+ return createFileError (InputFilename, object_error::parse_failed,
210
+ " section '%s' not found" , SecName.str ().c_str ());
215
211
}
216
212
217
213
Error Object::compressOrDecompressSections (const CommonConfig &Config) {
@@ -832,37 +828,32 @@ static Error handleArgs(const CommonConfig &Config, const ELFConfig &ELFConfig,
832
828
if (Config.ChangeSectionLMAValAll > 0 &&
833
829
Seg.PAddr > std::numeric_limits<uint64_t >::max () -
834
830
Config.ChangeSectionLMAValAll ) {
835
- Error E = createStringError (
836
- errc::invalid_argument,
831
+ return createFileError (
832
+ Config. InputFilename , errc::invalid_argument,
837
833
" address 0x" + Twine::utohexstr (Seg.PAddr ) +
838
834
" cannot be increased by 0x" +
839
835
Twine::utohexstr (Config.ChangeSectionLMAValAll ) +
840
836
" . The result would overflow" );
841
- return createFileError (Config.InputFilename , std::move (E));
842
837
} else if (Config.ChangeSectionLMAValAll < 0 &&
843
838
Seg.PAddr < std::numeric_limits<uint64_t >::min () -
844
839
Config.ChangeSectionLMAValAll ) {
845
- Error E = createStringError (
846
- errc::invalid_argument,
840
+ return createFileError (
841
+ Config. InputFilename , errc::invalid_argument,
847
842
" address 0x" + Twine::utohexstr (Seg.PAddr ) +
848
843
" cannot be decreased by 0x" +
849
844
Twine::utohexstr (std::abs (Config.ChangeSectionLMAValAll )) +
850
845
" . The result would underflow" );
851
-
852
- return createFileError (Config.InputFilename , std::move (E));
853
846
}
854
847
Seg.PAddr += Config.ChangeSectionLMAValAll ;
855
848
}
856
849
}
857
850
}
858
851
859
852
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,
863
856
" cannot change section address in a non-relocatable file" );
864
- return createFileError (Config.InputFilename , std::move (E));
865
- }
866
857
StringMap<AddressUpdate> SectionsToUpdateAddress;
867
858
for (const SectionPatternAddressUpdate &PatternUpdate :
868
859
make_range (Config.ChangeSectionAddress .rbegin (),
@@ -873,26 +864,22 @@ static Error handleArgs(const CommonConfig &Config, const ELFConfig &ELFConfig,
873
864
.second ) {
874
865
if (PatternUpdate.Update .Kind == AdjustKind::Subtract &&
875
866
Sec.Addr < PatternUpdate.Update .Value ) {
876
- Error E = createStringError (
877
- errc::invalid_argument,
867
+ return createFileError (
868
+ Config. InputFilename , errc::invalid_argument,
878
869
" address 0x" + Twine::utohexstr (Sec.Addr ) +
879
870
" cannot be decreased by 0x" +
880
871
Twine::utohexstr (PatternUpdate.Update .Value ) +
881
872
" . The result would underflow" );
882
-
883
- return createFileError (Config.InputFilename , std::move (E));
884
873
}
885
874
if (PatternUpdate.Update .Kind == AdjustKind::Add &&
886
875
Sec.Addr > std::numeric_limits<uint64_t >::max () -
887
876
PatternUpdate.Update .Value ) {
888
- Error E = createStringError (
889
- errc::invalid_argument,
877
+ return createFileError (
878
+ Config. InputFilename , errc::invalid_argument,
890
879
" address 0x" + Twine::utohexstr (Sec.Addr ) +
891
880
" cannot be increased by 0x" +
892
881
Twine::utohexstr (PatternUpdate.Update .Value ) +
893
882
" . The result would overflow" );
894
-
895
- return createFileError (Config.InputFilename , std::move (E));
896
883
}
897
884
898
885
switch (PatternUpdate.Update .Kind ) {
0 commit comments