public inbox for bpf@vger.kernel.org
 help / color / mirror / Atom feed
* Support for gcc
@ 2022-12-20 11:45 SuHsueyu
  2022-12-20 17:27 ` sdf
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: SuHsueyu @ 2022-12-20 11:45 UTC (permalink / raw)
  To: bpf

Hello, I use gcc 12.1.0 to compile a source file:
t.c
struct t {
  int a:2;
  int b:3;
  int c:2;
} g;
with gcc -c -gbtf t.c
and try to use libbpf API btf__parse_split, bpf_object__open, and
bpf_object__open to parse and load into the kernel, but it failed with
"libbpf: elf: /path/to/t.o is not a valid eBPF object file".

Is it wrong for me to do so? Due to some constraint, I cannot use
clang but gcc. How to parse and load gcc compiled object file with
libbpf?

^ permalink raw reply	[flat|nested] 11+ messages in thread
* Re: Support for gcc
@ 2022-12-29 18:22 Marc Poulhiès
  0 siblings, 0 replies; 11+ messages in thread
From: Marc Poulhiès @ 2022-12-29 18:22 UTC (permalink / raw)
  To: jose.marchesi; +Cc: anolasc13, bpf


>> BTW, when I tried to use bpf-gcc in godbolt.org, I did not add any
>> additional compile options, and it reported an error:
>>
>> /opt/compiler-explorer/bpf/gcc-trunk-20221225/bpf-unknown-none/lib/gcc/bpf-unknown-none/13.0.0/../../../../bpf-unknown-none/bin/ld:
>> -pie not supported
>> collect2: error: ld returned 1 exit status
>> Compiler returned: 1
>
> Hmm, I just tried and it didn't add -pie to the command line options.  I
> think that somehow godbolt.org remembers and re-uses the settings used
> by the last user.  At least when it comes to select the cross compiler.
> Maybe it is the same with the compilation options...

Hi,

Happened to find this discussion and am taking the liberty to reply,
hope that's ok :)

Compiler-Explorer does not reuse anything from another user. It may
reuse something you've used in a previous session stored in your local
browser, but then this will show in the "Compiler Options...." text
field.

Here's my findings about this pie. By default, we only emit
assembly (so you won't see any ld error). But if you ask for linking to
a binary (Output >> Compile to binary), you will get this error:

https://godbolt.org/z/za3sbr5qn

Looks like our toolchain defaults to PIE. I'll look into that
(https://github.com/compiler-explorer/compiler-explorer/issues/4517).

You can use -fno-pie or uncheck "compile to binary" in the meantime.

Thanks,
Marc

PS: If you think you have a bug in compiler-explorer, click the "share"
menu (top right) and provide us with a link (short or full, both work,
but short will be easier to share in a mail).

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2022-12-29 18:39 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-12-20 11:45 Support for gcc SuHsueyu
2022-12-20 17:27 ` sdf
2022-12-21  0:34 ` Andrii Nakryiko
2022-12-21 11:03   ` SuHsueyu
2022-12-21 17:41     ` Alan Maguire
2022-12-21 18:26   ` Jose E. Marchesi
2022-12-21 18:22 ` Jose E. Marchesi
2022-12-21 18:30   ` Jose E. Marchesi
2022-12-25 15:24     ` SuHsueyu
2022-12-26  9:42       ` Jose E. Marchesi
  -- strict thread matches above, loose matches on Subject: below --
2022-12-29 18:22 Marc Poulhiès

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox