Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Archives can contain multiple version of the same file #310

Open
hiker opened this issue Jun 13, 2024 · 2 comments
Open

Archives can contain multiple version of the same file #310

hiker opened this issue Jun 13, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@hiker
Copy link
Collaborator

hiker commented Jun 13, 2024

If you build a .a file, then modify one source file and rebuild, the .a will contain both versions of the compiled files, e.g.:

$ ar t ./most.a 
Constants.2de2473b7.o
...
InputOutput.3d229c877.o
InputOutput.37f15353a.o

When using this .a for linking, the oldest version of the .o is found and used in linking, meaning the changes to the source file are not used when creating the binaries. The problem goes away if no archive is created, and the binary is instead directly created from the .o files.

Potential solution:

  1. We add a flag to insert new members for existing members. I didn't try if this fixes the problem! And it might be slow??
  2. We query an existing .a to see if the same .o file is already in with a different hash, and remove it. Again, slow :(
  3. We copy all .o files with hash in the name to the corresponding hash-less name (e.g. InputOutput.37f15353a.o becomes InputOutput.o) and add them to the archive. That should fix the problem, but might be slow with large repositories (and is not nice for inode count :) ).
@hiker hiker added the bug Something isn't working label Jun 13, 2024
@hiker
Copy link
Collaborator Author

hiker commented Jun 13, 2024

Using -b requires to specify archive member before which all new members are inserted, so that also requires a query of an existing archive. I also have some inconsistent results when trying, potentially caused because the member specified before which the new members should be added, is also part of the new members (e.g. in the example above, when using ar -crb Constants.2de2473b7.o most.a InputOutput.33333,o Constants.2de2473b7.o ... - the Constants...o file is specified as 'relpos', but also added. I could not consistently avoid the problem of the linker picking the wrong version of a .o

@hiker
Copy link
Collaborator Author

hiker commented Jun 14, 2024

After some rest, I think the best option might be that the archive step just deletes an existing archive. I don't think this will be much (if at all) slower, since adding members to an existing archive might be expensive(??)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant