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

clang-offload-bundler mixes symbols from different objects when unbundling an archive #83509

Closed
LU-JOHN opened this issue Mar 1, 2024 · 6 comments · Fixed by #84195
Closed
Assignees

Comments

@LU-JOHN
Copy link

LU-JOHN commented Mar 1, 2024

Change to clang/lib/Driver/OffloadBundler.cpp in commit #81700 causes clang-offload-bundler to join symbols from different objects when unbundling an archive:

Source file s.cpp:

void bazball() {
}

Source file t.cpp:

void foobar() {
}

Commands:

clang++ -c s.cpp -o s.o;
clang-offload-bundler -type=o -targets=host-x86_64-unknown-linux-gnu -input=s.o -output=s_bundled.o;
clang++ -c t.cpp -o t.o;
clang-offload-bundler -type=o -targets=host-x86_64-unknown-linux-gnu -input=t.o -output=t_bundled.o;
llvm-ar cr bundled.a s_bundled.o t_bundled.o
clang-offload-bundler -unbundle --targets=host-x86_64-unknown-linux-gnu -type=aoo -input=bundled.a -output=t_list.txt; nm `cat t_list.txt`

The output of the nm command without the change is:

bundled-742762.o:
0000000000000000 T _Z7bazballv
bundled-61506b.o:
0000000000000000 T _Z6foobarv

The output with the change is:

/tmp/bundled-e7ca35.o:s_bundled.o:
0000000000000000 T _Z7bazballvt_bundled.o:
0000000000000000 T _Z6foobarv

/tmp/bundled-5ea078.o:s_bundled.o:
0000000000000000 T _Z7bazballvt_bundled.o:
0000000000000000 T _Z6foobarv

@jsji
Copy link
Member

jsji commented Mar 1, 2024

FYI. @yxsamliu

@LU-JOHN
Copy link
Author

LU-JOHN commented Mar 1, 2024

Sorry, I need to analyze this issue more carefully. It depends on some non-community changes.

@LU-JOHN LU-JOHN closed this as completed Mar 1, 2024
@EugeneZelenko EugeneZelenko added the question A question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead! label Mar 1, 2024
@LU-JOHN LU-JOHN reopened this Mar 4, 2024
@yxsamliu yxsamliu self-assigned this Mar 4, 2024
@EugeneZelenko EugeneZelenko removed the question A question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead! label Mar 4, 2024
@LU-JOHN
Copy link
Author

LU-JOHN commented Mar 4, 2024

I have a concern about the code in commit #81700 at:

https://github.com/yxsamliu/llvm-project/blob/1e9c29c4794ed6d60cf54c902cd0f854afd1aace/clang/lib/Driver/OffloadBundler.cpp#L718

This code is used to get a processed bundle in an ObjectFileHandler by using objcopy to process BundlerConfig.InputFileNames.front(). My concern is how does this code guarantee that BundlerConfig.InputFileNames.front() is connected to this instance of ObjectFileHandler? This caused a problem for me when unbundling an archive with multiple object files. I hit this problem when using the command sequence in my earlier comment. I have not been able to convert the command sequence into one that works with community tools, but I believe it should be possible when processing a multi-object archive.

@yxsamliu
Copy link
Collaborator

yxsamliu commented Mar 4, 2024

Good catch. The code assumes unbundling a non-archive file which has only one input. That is why it breaks for archive.

@yxsamliu
Copy link
Collaborator

yxsamliu commented Mar 5, 2024

Are you using some downstream llvm branch? Clang-offload-bundler in the trunk does not accept -type=aoo and also does not allow extract bundle entry for --targets=host-x86_64-unknown-linux-gnu

clang-offload-bundler -unbundle --targets=host-x86_64-unknown-linux-gnu -type=a -input=bundled.a -output=t_list.txt
clang-offload-bundler: error: no compatible code object found for the target 'host-x86_64-unknown-linux-gnu-' in heterogeneous archive library: bundled.a

@LU-JOHN
Copy link
Author

LU-JOHN commented Mar 5, 2024

Yes, it is an INTEL customization. I was not able to figure out how to extract a multi-object archive with the official clang-offload-bundler. Is it possible?

yxsamliu added a commit to yxsamliu/llvm-project that referenced this issue Mar 6, 2024
When unbundling an archive, need to save the content of
each object file to a temporary file before passing
it to llvm-objcopy, instead of passing the original
input archive file to llvm-objcopy.

Also allows extracting host bundles for archives.

Fixes: llvm#83509
yxsamliu added a commit that referenced this issue Mar 7, 2024
When unbundling an archive, need to save the content of each object file
to a temporary file before passing it to llvm-objcopy, instead of
passing the original input archive file to llvm-objcopy.

Also allows extracting host bundles for archives.

Fixes: #83509
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants