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

Re-enable more build warnings, fix related warnings #316 #403

Merged
merged 1 commit into from Feb 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions CMakeLists.txt
Expand Up @@ -6,14 +6,14 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)

add_compile_options("-std=c++14")
add_compile_options("-Wno-format-security")
#add_compile_options("-Wall")
add_compile_options("-Wall")
add_compile_options("-Wextra")
add_compile_options("-Wundef")
add_compile_options("-Wpointer-arith")
add_compile_options("-Wcast-align")
add_compile_options("-Wwrite-strings")
#add_compile_options("-Wcast-qual")
#add_compile_options("-Wswitch-default")
add_compile_options("-Wcast-qual")
add_compile_options("-Wswitch-default")
#add_compile_options("-Wswitch-enum")
#add_compile_options("-Wconversion")
add_compile_options("-Wunreachable-code")
Expand Down
2 changes: 1 addition & 1 deletion src/ast/ast.h
Expand Up @@ -180,8 +180,8 @@ class Unroll : public Statement {
public:
Unroll(long int var, StatementList *stmts) : var(var), stmts(stmts) {}

StatementList *stmts;
long int var = 0;
StatementList *stmts;

void accept(Visitor &v) override;
};
Expand Down
8 changes: 2 additions & 6 deletions src/ast/codegen_llvm.cpp
Expand Up @@ -112,8 +112,8 @@ void CodegenLLVM::visit(Builtin &builtin)
b_.CreateGetCurrentComm(buf, builtin.type.size);
expr_ = buf;
}
else if (!builtin.ident.compare(0, 3, "arg") && builtin.ident.size() == 4 &&
builtin.ident.at(3) >= '0' && builtin.ident.at(3) <= '9' ||
else if ((!builtin.ident.compare(0, 3, "arg") && builtin.ident.size() == 4 &&
builtin.ident.at(3) >= '0' && builtin.ident.at(3) <= '9') ||
builtin.ident == "retval" ||
builtin.ident == "func")
{
Expand Down Expand Up @@ -482,9 +482,7 @@ void CodegenLLVM::visit(Call &call)
* types and offsets of each of the arguments, and share that between BPF and
* user-space for printing.
*/
ArrayType *string_type = ArrayType::get(b_.getInt8Ty(), STRING_SIZE);
std::vector<llvm::Type *> elements = { b_.getInt64Ty() }; // printf ID
String &fmt = static_cast<String&>(*call.vargs->at(0));

auto &args = std::get<1>(bpftrace_.printf_args_.at(printf_id_));
for (Field &arg : args)
Expand Down Expand Up @@ -534,9 +532,7 @@ void CodegenLLVM::visit(Call &call)
* types and offsets of each of the arguments, and share that between BPF and
* user-space for printing.
*/
ArrayType *string_type = ArrayType::get(b_.getInt8Ty(), STRING_SIZE);
std::vector<llvm::Type *> elements = { b_.getInt64Ty() }; // system ID
String &fmt = static_cast<String&>(*call.vargs->at(0));

auto &args = std::get<1>(bpftrace_.system_args_.at(system_id_));
for (Field &arg : args)
Expand Down
9 changes: 4 additions & 5 deletions src/ast/irbuilderbpf.cpp
Expand Up @@ -142,7 +142,7 @@ CallInst *IRBuilderBPF::CreateBpfPseudoCall(Map &map)
return CreateBpfPseudoCall(mapfd);
}

CallInst *IRBuilderBPF::CreateGetJoinMap(Value *ctx)
CallInst *IRBuilderBPF::CreateGetJoinMap(Value *ctx __attribute__((unused)))
{
Value *map_ptr = CreateBpfPseudoCall(bpftrace_.join_map_->mapfd_);
AllocaInst *key = CreateAllocaBPF(getInt32Ty(), "key");
Expand Down Expand Up @@ -229,13 +229,12 @@ void IRBuilderBPF::CreateMapUpdateElem(Map &map, AllocaInst *key, Value *val)
Instruction::IntToPtr,
getInt64(BPF_FUNC_map_update_elem),
update_func_ptr_type);
CallInst *call = CreateCall(update_func, {map_ptr, key, val, flags}, "update_elem");
CreateCall(update_func, {map_ptr, key, val, flags}, "update_elem");
}

void IRBuilderBPF::CreateMapDeleteElem(Map &map, AllocaInst *key)
{
Value *map_ptr = CreateBpfPseudoCall(map);
Value *flags = getInt64(0);

// int map_delete_elem(&map, &key)
// Return: 0 on success or negative error
Expand All @@ -248,7 +247,7 @@ void IRBuilderBPF::CreateMapDeleteElem(Map &map, AllocaInst *key)
Instruction::IntToPtr,
getInt64(BPF_FUNC_map_delete_elem),
delete_func_ptr_type);
CallInst *call = CreateCall(delete_func, {map_ptr, key}, "delete_elem");
CreateCall(delete_func, {map_ptr, key}, "delete_elem");
}

void IRBuilderBPF::CreateProbeRead(AllocaInst *dst, size_t size, Value *src)
Expand All @@ -264,7 +263,7 @@ void IRBuilderBPF::CreateProbeRead(AllocaInst *dst, size_t size, Value *src)
Instruction::IntToPtr,
getInt64(BPF_FUNC_probe_read),
proberead_func_ptr_type);
CallInst *call = CreateCall(proberead_func, {dst, getInt64(size), src}, "probe_read");
CreateCall(proberead_func, {dst, getInt64(size), src}, "probe_read");
}

CallInst *IRBuilderBPF::CreateProbeReadStr(AllocaInst *dst, size_t size, Value *src)
Expand Down
2 changes: 1 addition & 1 deletion src/ast/semantic_analyser.cpp
Expand Up @@ -1044,7 +1044,7 @@ bool SemanticAnalyser::check_arg(const Call &call, Type type, int arg_num, bool
return true;
}

bool SemanticAnalyser::check_alpha_numeric(const Call &call, int arg_num)
bool SemanticAnalyser::check_alpha_numeric(const Call &call, int arg_num __attribute__((unused)))
{
if (!call.vargs)
return false;
Expand Down
12 changes: 8 additions & 4 deletions src/attached_probe.cpp
Expand Up @@ -281,6 +281,7 @@ static unsigned kernel_version(int attempt)
return 0;
return KERNEL_VERSION(x, y, z);
case 2:
{
// Try to get the definition of LINUX_VERSION_CODE at runtime.
std::ifstream linux_version_header{"/usr/include/linux/version.h"};
const std::string content{std::istreambuf_iterator<char>(linux_version_header),
Expand All @@ -292,6 +293,9 @@ static unsigned kernel_version(int attempt)
return static_cast<unsigned>(std::stoi(match[1]));

return 0;
}
default:
break;
}
std::cerr << "invalid kernel version" << std::endl;
abort();
Expand All @@ -308,7 +312,7 @@ void AttachedProbe::load_prog()
unsigned log_buf_size = sizeof (log_buf);

// Redirect stderr, so we don't get error messages from BCC
int old_stderr, new_stderr;
int old_stderr = -1, new_stderr;
fflush(stderr);
if (bt_debug != DebugLevel::kNone)
log_level = 15;
Expand All @@ -324,7 +328,7 @@ void AttachedProbe::load_prog()
log_level = 1;

// bpf_prog_load rejects colons in the probe name
strncpy(name, probe_.name.c_str(), STRING_SIZE);
strncpy(name, probe_.name.c_str(), STRING_SIZE - 1);
namep = name;
if (strrchr(name, ':') != NULL)
namep = strrchr(name, ':') + 1;
Expand Down Expand Up @@ -542,7 +546,7 @@ void AttachedProbe::attach_software()

uint64_t period = probe_.freq;
uint64_t defaultp = 1;
uint32_t type;
uint32_t type = 0;

// from linux/perf_event.h, with aliases from perf:
for (auto &probeListItem : SW_PROBE_LIST)
Expand Down Expand Up @@ -577,7 +581,7 @@ void AttachedProbe::attach_hardware()

uint64_t period = probe_.freq;
uint64_t defaultp = 1000000;
uint32_t type;
uint32_t type = 0;

// from linux/perf_event.h, with aliases from perf:
for (auto &probeListItem : HW_PROBE_LIST)
Expand Down
2 changes: 1 addition & 1 deletion src/bpforc.h
Expand Up @@ -89,7 +89,7 @@ class BpfOrc
BpfOrc(TargetMachine *TM_)
: TM(TM_),
Resolver(createLegacyLookupResolver(ES,
[](const std::string &Name) -> JITSymbol { return nullptr; },
[](const std::string &Name __attribute__((unused))) -> JITSymbol { return nullptr; },
[](Error Err) { cantFail(std::move(Err), "lookup failed"); })),
ObjectLayer(ES, [this](VModuleKey) { return RTDyldObjectLinkingLayer::Resources{std::make_shared<MemoryManager>(sections_), Resolver}; }),
CompileLayer(ObjectLayer, SimpleCompiler(*TM)) {}
Expand Down
18 changes: 9 additions & 9 deletions src/bpftrace.cpp
Expand Up @@ -192,7 +192,7 @@ int BPFtrace::num_probes() const
return special_probes_.size() + probes_.size();
}

void perf_event_printer(void *cb_cookie, void *data, int size)
void perf_event_printer(void *cb_cookie, void *data, int size __attribute__((unused)))
{
auto bpftrace = static_cast<BPFtrace*>(cb_cookie);
auto printf_id = *static_cast<uint64_t*>(data);
Expand Down Expand Up @@ -473,7 +473,7 @@ std::string BPFtrace::get_param(size_t i)
return "0";
}

void perf_event_lost(void *cb_cookie, uint64_t lost)
void perf_event_lost(void *cb_cookie __attribute__((unused)), uint64_t lost)
{
printf("Lost %lu events\n", lost);
}
Expand Down Expand Up @@ -1349,7 +1349,7 @@ uint64_t BPFtrace::reduce_value(const std::vector<uint8_t> &value, int ncpus)
uint64_t sum = 0;
for (int i=0; i<ncpus; i++)
{
sum += *(uint64_t*)(value.data() + i*sizeof(uint64_t*));
sum += *(const uint64_t*)(value.data() + i*sizeof(uint64_t*));
}
return sum;
}
Expand All @@ -1359,7 +1359,7 @@ uint64_t BPFtrace::max_value(const std::vector<uint8_t> &value, int ncpus)
uint64_t val, max = 0;
for (int i=0; i<ncpus; i++)
{
val = *(uint64_t*)(value.data() + i*sizeof(uint64_t*));
val = *(const uint64_t*)(value.data() + i*sizeof(uint64_t*));
if (val > max)
max = val;
}
Expand All @@ -1371,7 +1371,7 @@ int64_t BPFtrace::min_value(const std::vector<uint8_t> &value, int ncpus)
int64_t val, max = 0, retval;
for (int i=0; i<ncpus; i++)
{
val = *(int64_t*)(value.data() + i*sizeof(int64_t*));
val = *(const int64_t*)(value.data() + i*sizeof(int64_t*));
if (val > max)
max = val;
}
Expand Down Expand Up @@ -1673,14 +1673,14 @@ void BPFtrace::sort_by_key(std::vector<SizedType> key_args,
{
std::stable_sort(values_by_key.begin(), values_by_key.end(), [&](auto &a, auto &b)
{
return *(uint64_t*)(a.first.data() + arg_offset) < *(uint64_t*)(b.first.data() + arg_offset);
return *(const uint64_t*)(a.first.data() + arg_offset) < *(const uint64_t*)(b.first.data() + arg_offset);
});
}
else if (arg.size == 4)
{
std::stable_sort(values_by_key.begin(), values_by_key.end(), [&](auto &a, auto &b)
{
return *(uint32_t*)(a.first.data() + arg_offset) < *(uint32_t*)(b.first.data() + arg_offset);
return *(const uint32_t*)(a.first.data() + arg_offset) < *(const uint32_t*)(b.first.data() + arg_offset);
});
}
else
Expand All @@ -1694,8 +1694,8 @@ void BPFtrace::sort_by_key(std::vector<SizedType> key_args,
{
std::stable_sort(values_by_key.begin(), values_by_key.end(), [&](auto &a, auto &b)
{
return strncmp((char*)(a.first.data() + arg_offset),
(char*)(b.first.data() + arg_offset),
return strncmp((const char*)(a.first.data() + arg_offset),
(const char*)(b.first.data() + arg_offset),
STRING_SIZE) < 0;
});
}
Expand Down
2 changes: 2 additions & 0 deletions src/bpftrace.h
Expand Up @@ -41,6 +41,8 @@ inline DebugLevel operator++(DebugLevel& level, int)
// NOTE (mmarchini): should be handled by the caller
level = DebugLevel::kNone;
break;
default:
break;
}
return level;
}
Expand Down
6 changes: 4 additions & 2 deletions src/fake_map.cpp
Expand Up @@ -4,12 +4,14 @@ namespace bpftrace {

int FakeMap::next_mapfd_ = 1;

FakeMap::FakeMap(const std::string &name, const SizedType &type, const MapKey &key)
FakeMap::FakeMap(const std::string &name __attribute__((unused)),
const SizedType &type __attribute__((unused)),
const MapKey &key __attribute__((unused)))
{
mapfd_ = next_mapfd_++;
}

FakeMap::FakeMap(enum bpf_map_type map_type)
FakeMap::FakeMap(enum bpf_map_type map_type __attribute__((unused)))
{
mapfd_ = next_mapfd_++;
}
Expand Down
29 changes: 16 additions & 13 deletions src/mapkey.cpp
Expand Up @@ -62,33 +62,36 @@ std::string MapKey::argument_value(BPFtrace &bpftrace,
switch (arg.size)
{
case 1:
return std::to_string(*(int8_t*)data);
return std::to_string(*(const int8_t*)data);
case 2:
return std::to_string(*(int16_t*)data);
return std::to_string(*(const int16_t*)data);
case 4:
return std::to_string(*(int32_t*)data);
return std::to_string(*(const int32_t*)data);
case 8:
return std::to_string(*(int64_t*)data);
return std::to_string(*(const int64_t*)data);
default:
break;
}
break;
case Type::kstack:
return bpftrace.get_stack(*(uint64_t*)data, false, 4);
return bpftrace.get_stack(*(const uint64_t*)data, false, 4);
case Type::ustack:
return bpftrace.get_stack(*(uint64_t*)data, true, 4);
return bpftrace.get_stack(*(const uint64_t*)data, true, 4);
case Type::ksym:
return bpftrace.resolve_ksym(*(uint64_t*)data);
return bpftrace.resolve_ksym(*(const uint64_t*)data);
case Type::usym:
return bpftrace.resolve_usym(*(uint64_t*)data, *(uint64_t*)(arg_data + 8));
return bpftrace.resolve_usym(*(const uint64_t*)data, *(const uint64_t*)(arg_data + 8));
case Type::inet:
return bpftrace.resolve_inet(*(uint64_t*)data, *(uint64_t*)(arg_data + 8));
return bpftrace.resolve_inet(*(const uint64_t*)data, *(const uint64_t*)(arg_data + 8));
case Type::username:
return bpftrace.resolve_uid(*(uint64_t*)data);
return bpftrace.resolve_uid(*(const uint64_t*)data);
case Type::probe:
return bpftrace.probe_ids_[*(uint64_t*)data];
return bpftrace.probe_ids_[*(const uint64_t*)data];
case Type::string:
return std::string((char*)data);
return std::string((const char*)data);
default:
std::cerr << "invalid mapkey argument type" << std::endl;
}
std::cerr << "invalid mapkey argument type" << std::endl;
abort();
}

Expand Down
4 changes: 2 additions & 2 deletions src/utils.cpp
Expand Up @@ -34,8 +34,8 @@ namespace bpftrace {
bool has_wildcard(const std::string &str)
{
if (str.find("*") != std::string::npos ||
str.find("[") != std::string::npos &&
str.find("]") != std::string::npos)
(str.find("[") != std::string::npos &&
str.find("]") != std::string::npos))
return true;
else
return false;
Expand Down