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

Add few clang compiler alias for BPF target #4543

Merged
merged 6 commits into from
Jan 7, 2023
Merged

Add few clang compiler alias for BPF target #4543

merged 6 commits into from
Jan 7, 2023

Conversation

dkm
Copy link
Member

@dkm dkm commented Jan 5, 2023

Add 3 latest clang version aliases to BPF target.

refs #4408

Signed-off-by: Marc Poulhiès dkm@kataplop.net

Add 3 latest clang version aliases to BPF target.

refs #4408

Signed-off-by: Marc Poulhiès <dkm@kataplop.net>
@borkmann
Copy link

borkmann commented Jan 5, 2023

Thanks so much! Not blocking for the PR of course, but could you also add clang trunk as well? That would be very useful too.

@dkm
Copy link
Member Author

dkm commented Jan 6, 2023

@borkmann we usually use binutils for objdump and demangler (c++filt). Is it a valid choice also for bpf?

@borkmann
Copy link

borkmann commented Jan 6, 2023

@borkmann we usually use binutils for objdump and demangler (c++filt). Is it a valid choice also for bpf?

For BPF, is it possible to use in all cases LLVM pendants?

cat foo.c 
int square(int num)
{
	return num * num;
}
clang -target bpf -c foo.c -o foo.o

Will give:

llvm-objdump --disassemble-symbols=square foo.o 

foo.o:	file format elf64-bpf

Disassembly of section .text:

0000000000000000 <square>:
       0:	63 1a fc ff 00 00 00 00	*(u32 *)(r10 - 4) = r1
       1:	61 a0 fc ff 00 00 00 00	r0 = *(u32 *)(r10 - 4)
       2:	2f 00 00 00 00 00 00 00	r0 *= r0
       3:	95 00 00 00 00 00 00 00	exit

That's the more commonly used disasm output in BPF community.

I know that the BPF gcc trunk uses their own asm syntax at the moment.

Each could use their own by default, but if it is possible, it would actually be really nice for users to pick a choice (LLVM BPF asm syntax vs gcc BPF asm syntax) when they compare gcc vs clang outputs so results are easier to read for each party and compare.

@dkm
Copy link
Member Author

dkm commented Jan 6, 2023

Ok thanks, I'll see what I can do. I don't think I've seen any usage of llvm-objdump yet, so not sure our post-processing will work, or even if we know how to call it.

edit: so we have some llvm-objdump around for mos and hip/rocm, so should be ok. User can't switch it dynamically, so I'll have clang compilers use llvm, and gcc use binutils.

@partouf
Copy link
Contributor

partouf commented Jan 6, 2023

Ok thanks, I'll see what I can do. I don't think I've seen any usage of llvm-objdump yet, so not sure our post-processing will work, or even if we know how to call it.

you'll need to also set objdumperType=llvm

Copy link
Member

@RubenRBS RubenRBS left a comment

Choose a reason for hiding this comment

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

+1 on this

@dkm
Copy link
Member Author

dkm commented Jan 7, 2023

Thank you all for reviewing/advising!

@dkm dkm merged commit 3a7c317 into main Jan 7, 2023
@dkm dkm deleted the dkm/bpf_clang branch January 7, 2023 13:19
@dkm
Copy link
Member Author

dkm commented Jan 7, 2023

Ok, so this is not working :(
The reason being that our "compile to binary" is really "link to binary" (another reason for me undusting #3232 ), and we use gcc as the linker drivers.

clang version 16.0.0 (https://github.com/llvm/llvm-project.git 8304f6de94872cdcaba63039a61b8860fe367620)
Target: bpf
Thread model: posix
InstalledDir: /opt/compiler-explorer/clang-trunk/bin
 "/opt/compiler-explorer/clang-trunk-20230107/bin/clang-16" -cc1 -triple bpf -emit-obj -mrelax-all -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name example.cpp -mrelocation-model static -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -mllvm -treat-scalable-fixed-error-as-warning -debug-info-kind=constructor -dwarf-version=5 -debugger-tuning=gdb -v -fcoverage-compilation-dir=/app -resource-dir /opt/compiler-explorer/clang-trunk-20230107/lib/clang/16 -fdeprecated-macro -fdebug-compilation-dir=/app -ferror-limit 19 -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -fcolor-diagnostics -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/example-87b770.o -x c++ <source>
clang -cc1 version 16.0.0 based upon LLVM 16.0.0git default target x86_64-unknown-linux-gnu
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include
 /opt/compiler-explorer/clang-trunk-20230107/lib/clang/16/include
 /usr/include
End of search list.
 "/usr/bin/gcc" -L. -o /app/output.s /tmp/example-87b770.o -Wl,-rpath,.
/usr/bin/ld: /tmp/example-87b770.o: Relocations in generic ELF (EM: 247)
/usr/bin/ld: /tmp/example-87b770.o: Relocations in generic ELF (EM: 247)
/usr/bin/ld: /tmp/example-87b770.o: Relocations in generic ELF (EM: 247)
/usr/bin/ld: /tmp/example-87b770.o: Relocations in generic ELF (EM: 247)
/usr/bin/ld: /tmp/example-87b770.o: Relocations in generic ELF (EM: 247)
/usr/bin/ld: /tmp/example-87b770.o: Relocations in generic ELF (EM: 247)
/usr/bin/ld: /tmp/example-87b770.o: error adding symbols: file in wrong format
collect2: error: ld returned 1 exit status
clang-16: error: linker (via gcc) command failed with exit code 1 (use -v to see invocation)
Compiler returned: 1

Possible solutions:

  • use bpf-gcc for linking. I still feel this is not what we want, but that's the easy fix
  • really only compile (no link) to binary (see PR above)
  • disable binary altogether.
    I'll try number 1 until 2 is implemented :)

borkmann added a commit to ebpf-io/ebpf.io-website that referenced this pull request Jan 9, 2023
Support for clang BPF got merged over the weekend:

  compiler-explorer/compiler-explorer#4543

Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
borkmann added a commit to ebpf-io/ebpf.io-website that referenced this pull request Jan 9, 2023
Support for clang BPF got merged over the weekend:

  compiler-explorer/compiler-explorer#4543

Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
mattgodbolt pushed a commit that referenced this pull request Jan 24, 2023
Add 3 latest clang version aliases + trunk to BPF target.
Use `llvm-objdump` for clang compilers and binutils' one for the GCC compiler (unfortunately, this can't be changed by the user in the UI).

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

Successfully merging this pull request may close these issues.

None yet

4 participants