Skip to content

Commit

Permalink
arm64: define the KASAN_SHADOW_SCALE_SHIFT macro
Browse files Browse the repository at this point in the history
arm64 defines this macro from Makefile instead of defining it in a
header file as is the case for other architectures. Since we're not
running make, we need to define the macro manually via CFLAGS.

The value definition is taken from kernel's arch/arm64/Makefile and it
depends on the running kernel configuration.

This fixes the runqlat.bt tcpdrop.bt, and undump.bt tools on
aarch64+debug kernel which previously failed with:

    # /usr/share/bpftrace/tools/runqlat.bt
    [...]/source/arch/arm64/include/asm/memory.h:300:9: error: use of undeclared identifier 'KASAN_SHADOW_SCALE_SHIFT'
    [...]
  • Loading branch information
viktormalik committed Mar 30, 2023
1 parent dceda49 commit d865e96
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ and this project adheres to
- [#2521](https://github.com/iovisor/bpftrace/pull/2521)
- Respect BPFTRACE_STRLEN environment variable for all strings
- [#2545](https://github.com/iovisor/bpftrace/pull/2545)
- arm64: define the KASAN_SHADOW_SCALE_SHIFT macro
- [#2518](https://github.com/iovisor/bpftrace/pull/2518)
#### Docs
#### Tools

Expand Down
3 changes: 2 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,8 @@ static std::optional<struct timespec> get_boottime()
kobj = std::get<1>(kdirs);

if (ksrc != "")
extra_flags = get_kernel_cflags(utsname.machine, ksrc, kobj);
extra_flags = get_kernel_cflags(
utsname.machine, ksrc, kobj, bpftrace.kconfig);
}
extra_flags.push_back("-include");
extra_flags.push_back(CLANG_WORKAROUNDS_H);
Expand Down
23 changes: 18 additions & 5 deletions src/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,6 @@ KConfig::KConfig()
}
}


bool get_uint64_env_var(const std::string &str, uint64_t &dest)
{
if (const char* env_p = std::getenv(str.c_str()))
Expand Down Expand Up @@ -365,10 +364,10 @@ std::vector<int> get_possible_cpus()
return read_cpu_range("/sys/devices/system/cpu/possible");
}

std::vector<std::string> get_kernel_cflags(
const char* uname_machine,
const std::string& ksrc,
const std::string& kobj)
std::vector<std::string> get_kernel_cflags(const char *uname_machine,
const std::string &ksrc,
const std::string &kobj,
const KConfig &kconfig)
{
std::vector<std::string> cflags;
std::string arch = uname_machine;
Expand Down Expand Up @@ -434,6 +433,20 @@ std::vector<std::string> get_kernel_cflags(
cflags.push_back("-D__LINUX_ARM_ARCH__=7");
}

if (arch == "arm64")
{
// arm64 defines KASAN_SHADOW_SCALE_SHIFT in a Makefile instead of defining
// it in a header file. Since we're not executing make, we need to set the
// value manually (values are taken from arch/arm64/Makefile).
if (kconfig.has_value("CONFIG_KASAN", "y"))
{
if (kconfig.has_value("CONFIG_KASAN_SW_TAGS", "y"))
cflags.push_back("-DKASAN_SHADOW_SCALE_SHIFT=4");
else
cflags.push_back("-DKASAN_SHADOW_SCALE_SHIFT=3");
}
}

return cflags;
}

Expand Down
3 changes: 2 additions & 1 deletion src/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,8 @@ std::tuple<std::string, std::string> get_kernel_dirs(
bool unpack_kheaders);
std::vector<std::string> get_kernel_cflags(const char *uname_machine,
const std::string &ksrc,
const std::string &kobj);
const std::string &kobj,
const KConfig &kconfig);
std::string get_cgroup_path_in_hierarchy(uint64_t cgroupid,
std::string base_path);
std::vector<std::pair<std::string, std::string>> get_cgroup_hierarchy_roots();
Expand Down

0 comments on commit d865e96

Please sign in to comment.