Skip to content

cli: Fix parsing of --export flags #28

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

Merged
merged 6 commits into from
Dec 26, 2022
Merged

Conversation

vadorovsky
Copy link
Member

@vadorovsky vadorovsky commented Dec 23, 2022

Those flags, even when passed multiple times, are always prepend with
--export when they come from rustc. Delimiter can be used, but we
shouldn't include any positional arguments after the flag as a part of
that flag. Therefore, we use the combination of
use_value_delimiter = true and num_args = 1 options to ensure that.

That bug can be reproduced by running bpf-linker together with rustc
after rust-lang/rust@7f06d51
which passes the following sequence of arguments to the linker:

[...]
--export
connect
--export
some_dep
/tmp/rusdep
/tmp/rustcwUehHK/symbols.o
/tmp/bin.bin.3b77bbea-cgu.0.rcgu.o
-L
/tmp
-L
/home/vadorovsky/repos/bpf-linker/target/debug/deps
[...]

/tmp/rustdep, symbols.o and *.rcgu.o are inputs, but
bpf-linker was parsing them as symbols to export. Therefore, symbols.o
and *.rcgu.o were not linked, bpf-linker was ending up just linking
dependencies / external crates together and not including the main
program.

Fixes: #27
Signed-off-by: Michal Rostecki [email protected]

@vadorovsky vadorovsky force-pushed the fix-tests branch 13 times, most recently from aed121b to f3ced12 Compare December 23, 2022 12:42
Using nightly for running clippy often causes warnings which are about
non-stabilized features. Since we support building bpf-linker with
stable, let's use it for clippy as well.

Signed-off-by: Michal Rostecki <[email protected]>
All assembly tests depend on FileCheck, which has to be installed
through the llvm-tools package.

Signed-off-by: Michal Rostecki <[email protected]>
Signed-off-by: Michal Rostecki <[email protected]>
@vadorovsky vadorovsky force-pushed the fix-tests branch 2 times, most recently from efd305a to e5b949a Compare December 23, 2022 14:15
Copy link
Collaborator

@alessandrod alessandrod left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks again for doing this. Looks good, see nits.

@@ -75,6 +75,15 @@ jobs:
sudo apt-get update
sudo apt-get install llvm-${{ matrix.llvm }}-dev libclang-${{ matrix.llvm }}-dev

- name: Install LLVM tools
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does the rustup component llvm-tools-preview not include filecheck?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems like no

$ docker run --rm -it rust:1.66 bash
root@629bf09695e7:/# rustup component add llvm-tools-preview
info: downloading component 'llvm-tools-preview'
info: installing component 'llvm-tools-preview'
 32.9 MiB /  32.9 MiB (100 %)  22.3 MiB/s in  1s ETA:  0s
root@629bf09695e7:/# FileCheck
bash: FileCheck: command not found
root@629bf09695e7:/# find / -name "*FileCheck*"
root@629bf09695e7:/#

Those flags, even when passed multiple times, are always prepend with
`--export` when they come from rustc. Delimiter can be used, but we
shouldn't include any positional arguments after the flag as a part of
that flag. Therefore, we use the combination of
`use_value_delimiter = true` and `num_args = 1` options to ensure that.

That bug can be reproduced by running bpf-linker together with rustc
after rust-lang/rust@7f06d51
which passes the following sequence of arguments to the linker:

```
[...]
--export
connect
--export
some_dep
/tmp/rusdep
/tmp/rustcwUehHK/symbols.o
/tmp/bin.bin.3b77bbea-cgu.0.rcgu.o
-L
/tmp
-L
/home/vadorovsky/repos/bpf-linker/target/debug/deps
[...]
```

`/tmp/rustdep`, `symbols.o` and `*.rcgu.o` are inputs, but
bpf-linker was parsing them as symbols to export. Therefore, `symbols.o`
and `*.rcgu.o` were not linked, bpf-linker was ending up just linking
dependencies / external crates together and not including the main
program.

Fixes: aya-rs#27
Signed-off-by: Michal Rostecki <[email protected]>
@alessandrod alessandrod merged commit bb73c0b into aya-rs:main Dec 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Build is failing
2 participants