-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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_parser: workaround for asm goto in Kernel 5+ headers #732
Conversation
I couldn't test it yet because I don't have a Kernel 5+ readily available now. @joestringer @olsajiri if you could try it that would be really helpful, since you both were suffering from this issue. |
Also, I'll need to update codegen and parser tests later. |
with the extra change below, your fix is working for me, I wonder we should put it to extra unsaved_files header,
|
It is already included (or at least should be, unless something changed recently). |
yes, but I think it needs to come before the #undef, so it cant get disabled |
I was looking at bcc's implementation. After looking at diff --git a/src/clang_parser.cpp b/src/clang_parser.cpp
index 509d014..9498a9c 100644
--- a/src/clang_parser.cpp
+++ b/src/clang_parser.cpp
@@ -294,10 +294,10 @@ bool ClangParser::parse(ast::Program *program, BPFtrace &bpftrace, std::vector<s
// able to parse our headers.
//
// From: https://github.com/iovisor/bcc/pull/2133/files
- input = "#ifdef asm_volatile_goto\n"
+ input = input + "#ifdef asm_volatile_goto\n"
"#undef asm_volatile_goto\n"
"#define asm_volatile_goto(x...) asm volatile(\"invalid use of asm_volatile_goto\")\n"
- "#endif\n\n" + input;
+ "#endif\n\n";
CXUnsavedFile unsaved_files[] =
{ This way we guarantee that nothing inside the program will override our definiton (and as a plus we don't need to change our tests :) ). |
that still fails for me with the same errors, |
7356596
to
1882b8b
Compare
@olsajiri thank you for sharing your fix. I made a few changes and updated the PR, should be working now. |
src/clang_parser.h
Outdated
@@ -3,6 +3,9 @@ | |||
#include <clang-c/Index.h> | |||
#include "bpftrace.h" | |||
|
|||
#define ASM_GOTO_WORKAROUND_H "asm_goto_workaround.h" | |||
#define ASM_GOTO_WORKAROUND_PATH "/bpftrace/include/" ASM_GOTO_WORKAROUND_H |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should normally wrap the contents of a #define
in brackets for preprocessor safety, but since ASM_GOTO_WORKAROUND_PATH
is only used once anyway we might as well just get rid of this define. That would match how the other builtin headers are done too.
src/clang_parser.cpp
Outdated
@@ -321,6 +321,11 @@ bool ClangParser::parse(ast::Program *program, BPFtrace &bpftrace, std::vector<s | |||
.Contents = stdint_h, | |||
.Length = stdint_h_len, | |||
}, | |||
{ | |||
.Filename = ASM_GOTO_WORKAROUND_PATH, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.Filename = ASM_GOTO_WORKAROUND_PATH, | |
.Filename = "/bpftrace/include/" ASM_GOTO_WORKAROUND_H, |
To try and clarify what I was talking about in the other comment
1882b8b
to
b19efcc
Compare
b19efcc
to
0dc72e0
Compare
Got around to testing this out, it works beautifully thanks folks! |
<linux/types.h> is included from clang_workarounds.h which contains a workaround for asm goto which is not supported by older Clang/LLVM versions. The problem is that types from <linux/types.h> conflict with types from <sys/types.h> which may cause type redefinitions in Clang parser. This particularly happens when BTF is not present b/c otherwise <linux/types.h> and clang_workarounds.h are not used. This commit drops the above include. This should be safe to do as the workaround will still work if <linux/types.h> is included *before* including clang_workarounds.h (see [1] for more details). [1] bpftrace#732
Fixes: #611