Bug 24281 - Failed with “thin archive” if it contain subdir's object file
Summary: Failed with “thin archive” if it contain subdir's object file
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: binutils (show other bugs)
Version: 2.32
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-02-28 08:47 UTC by lol lol
Modified: 2019-03-04 13:57 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed: 2019-03-01 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description lol lol 2019-02-28 08:47:25 UTC
Please use following shell commands to reproduce the problem:

```
# create subdirectory
mkdir subdir

# create source files with dummy functions
echo 'void func1(){}' > file1.c
echo 'void func2(){}' > ./subdir/file2.c

# compiling sources into object files
gcc -c file1.c -o file1.o
gcc -c ./subdir/file2.c -o ./subdir/file2.o

# creating "thin archive" file from object files
ar crT out.a file1.o ./subdir/file2.o

# running objcopy, which leads to an error
objcopy out.a out_copy.a

```

As a result, following error occurs:

```
    objcopy:st0AENRL/subdir/file2.o: No such file or directory
```

Problem with objcopy occurs when "thin" archive is composed of object files from subdirectories.

P.S. Problem was also described on StackOverflow:
https://stackoverflow.com/questions/54907402/problem-while-using-objcopy-with-thin-archive-file
Comment 1 lol lol 2019-02-28 09:05:21 UTC
Bug was reproduced on versions 2.26 and 2.32.
Comment 2 Nick Clifton 2019-03-01 14:40:42 UTC
Hi lol lol,

  Hmm, you do realise that copying a thin library in this way is 
  essentially the same thing as just copying it normally, right ?

  The question is, what would you expect objcopy to do if you also
  had one or more of its transformation options enabled as well.  
  For example, what should this do:

    objcopy --strip-debug out.a out_copy.a

  Would you expect objcopy to create new versions of all of the
  object files linked to within out.a, with the debugging stripped
  from the new versions ?  If so, what names should be given to
  these new object files ?  Or how about:

    objcopy out.a subdir/copy.a

  Would you expect objcopy to leave the object files intact but to
  rename the links inside copy.a so that they are valid for the
  new location of the thin library ?

  It seems to me that the easiest thing to do would be to just
  reject attempts to objcopy thin archives.  But maybe this is
  too draconian.  Would you be happy if an in-place copy of a
  thin archive was allowed, but transformations, or relocations
  were refused ?

Cheers
  Nick
Comment 3 lol lol 2019-03-04 08:55:24 UTC
Hi Nick,


Q. Hmm, you do realise that copying a thin library in this way is 
   essentially the same thing as just copying it normally, right?
A. Yes. It was chosen for simplicity. Anyway, it shouldn't fail. Can you agree?


Q. The question is, what would you expect objcopy to do if you also
   had one or more of its transformation options enabled as well.  
   For example, what should this do:
     objcopy --strip-debug out.a out_copy.a
A. I expect similar behavior as for other "non-thin" object files.
   Why not to do "--strip-debug" for all included files recursively?
   It may be done in-place, or done with a copy.


Q. Would you expect objcopy to create new versions of all of the
   object files linked to within out.a, with the debugging stripped
   from the new versions ?  If so, what names should be given to
   these new object files ?  Or how about:
     objcopy out.a subdir/copy.a
   Would you expect objcopy to leave the object files intact but to
   rename the links inside copy.a so that they are valid for the
   new location of the thin library ?
A. In this case (case, when objcopy pretends to change object files), we may
   simply notify user, that object files will be rewritten and wait for the 
   confirmation.


Q. It seems to me that the easiest thing to do would be to just
   reject attempts to objcopy thin archives.  But maybe this is
   too draconian.  Would you be happy if an in-place copy of a
   thin archive was allowed, but transformations, or relocations
   were refused?
A. I think, it is not a bad idea to simply disallow objcopy for thin archives
   till the moment, when it will be supported (in alternative future).
   I think it is not of "draconian" attempt.
   This way, user of this magic tool will not be confused at all.


Thank you!

WBR,
lol lol
Comment 4 Sourceware Commits 2019-03-04 13:12:20 UTC
The master branch has been updated by Nick Clifton <nickc@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=f5f20315116c43110c058ec9d787e20f901309f2

commit f5f20315116c43110c058ec9d787e20f901309f2
Author: Nick Clifton <nickc@redhat.com>
Date:   Mon Mar 4 13:11:08 2019 +0000

    Stop objcopy from attempting to copy thin archives.
    
    	PR 24281
    	* objcopy.c (copy_archive): Do not copy thin  archives.
Comment 5 Nick Clifton 2019-03-04 13:57:09 UTC
Hi lol lol,

  Great - in which case I have applied a patch to stop objcopy from
  copying thin archives - for now...

Cheers
  Nick