forked from iovisor/bcc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
clang: Add support to build eBPF for user specified ARCH
BCC at the moment builds eBPF only considering the local architecture instead of the one that the user's target kernel is running on. For cross-compiler environments, the ARCH environment variable is used to specify which ARCH to build the kernel for. In this patch we add support to read ARCH and if that's not set, then fallback to detecting based on local architecture. This patch borrows some code from a patch doing a similar thing for eBPF samples in the kenrel that I submitted recently [1] [1] https://patchwork.kernel.org/patch/9961801/ Signed-off-by: Joel Fernandes <[email protected]>
- Loading branch information
Joel Fernandes
committed
Feb 6, 2018
1 parent
11f3a27
commit 1086952
Showing
5 changed files
with
182 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Copyright (c) 2018 Google, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include <string.h> | ||
#include <stdlib.h> | ||
|
||
typedef enum { | ||
BCC_ARCH_PPC, | ||
BCC_ARCH_PPC_LE, | ||
BCC_ARCH_S390X, | ||
BCC_ARCH_ARM64, | ||
BCC_ARCH_X86 | ||
} bcc_arch_t; | ||
|
||
typedef void *(*arch_callback_t)(bcc_arch_t arch); | ||
|
||
static void *run_arch_callback(arch_callback_t fn) | ||
{ | ||
const char *archenv = getenv("ARCH"); | ||
|
||
/* If ARCH is not set, detect from local arch clang is running on */ | ||
if (!archenv) { | ||
#if defined(__powerpc64__) | ||
#if defined(_CALL_ELF) && _CALL_ELF == 2 | ||
return fn(BCC_ARCH_PPC_LE); | ||
#else | ||
return fn(BCC_ARCH_PPC); | ||
#endif | ||
#elif defined(__s390x__) | ||
return fn(BCC_ARCH_S390X); | ||
#elif defined(__aarch64__) | ||
return fn(BCC_ARCH_ARM64); | ||
#else | ||
return fn(BCC_ARCH_X86); | ||
#endif | ||
} | ||
|
||
/* Otherwise read it from ARCH */ | ||
if (!strcmp(archenv, "powerpc")) { | ||
#if defined(_CALL_ELF) && _CALL_ELF == 2 | ||
return fn(BCC_ARCH_PPC_LE); | ||
#else | ||
return fn(BCC_ARCH_PPC); | ||
#endif | ||
} else if (!strcmp(archenv, "s390x")) { | ||
return fn(BCC_ARCH_S390X); | ||
} else if (!strcmp(archenv, "arm64")) { | ||
return fn(BCC_ARCH_ARM64); | ||
} else { | ||
return fn(BCC_ARCH_X86); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters