In case of objdump errors with "symbol `.debug_info' required but not present" when running "objcopy -R .debug_info ./libsomething.a", it leaves temporary files in the folder. --- $ objcopy -R .debug_info ./libgfortran.a objcopy: ./stftlphn/unix.o: symbol `.debug_info' required but not present objcopy: ./stftlphn/unix.o: no symbols --- OBSERVED: ./stftlphn/unix.o exists. EXPECTED: no left-over temporary files. reading the source code reveals: 1. objcopy.c, in copy_archive() around L3765, bfd_close is called but errored. 2. bfd_nonfatal_message is called and status set to 1 3. L3778, 3779: the bfd_close branch is taken, leaving l->obfd as NULL. 4. in cleanup_and_exit, if l->obfd is NULL, rmdir is called (however l->name is a file, which leads to an ENOTDIR and the file is not removed)
the following patch fixes the issue, but I'm not sure what implication (or side-effect) it has. diff --git a/binutils/objcopy.c b/binutils/objcopy.c index b3c8d0f81ac8..c2f1b9421e4c 100644 --- a/binutils/objcopy.c +++ b/binutils/objcopy.c @@ -3766,7 +3766,7 @@ copy_archive (bfd *ibfd, bfd *obfd, const char *output_target, { bfd_nonfatal_message (output_name, NULL, NULL, NULL); /* Error in new object file. Don't change archive. */ - status = 1; + del = 1; } if (del)
Yes, that change looks good. I'll fix the rmdir problem too.
The master branch has been updated by Alan Modra <amodra@sourceware.org>: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=145c21056abeace6b3f6cafb65c29a7812036852 commit 145c21056abeace6b3f6cafb65c29a7812036852 Author: Alan Modra <amodra@gmail.com> Date: Tue Dec 26 16:20:34 2023 +1030 PR31191, objcopy leaves temporary files Fix the ENOTDIR rmdir too. PR 31191 * objcopy.c (copy_archive): Localise uses of "l". Remove const from name_list.name. Unlink output element on bfd_close error, and NULL list->name to indicate file is removed. Adjust cleanup to prevent rmdir on non-existent file.
Fix for 2.42