mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-05-30 00:19:28 +00:00
Merge pull request #11287 from opensourcerouting/build-llvm-20220526
build: fix some corners for LLVM analysis tools
This commit is contained in:
commit
2ba7b5763a
@ -32,7 +32,12 @@ for clippy_file in clippy_scan:
|
|||||||
assert clippy_file.endswith(".c")
|
assert clippy_file.endswith(".c")
|
||||||
|
|
||||||
xref_targets = []
|
xref_targets = []
|
||||||
for varname in ["bin_PROGRAMS", "sbin_PROGRAMS", "lib_LTLIBRARIES", "module_LTLIBRARIES"]:
|
for varname in [
|
||||||
|
"bin_PROGRAMS",
|
||||||
|
"sbin_PROGRAMS",
|
||||||
|
"lib_LTLIBRARIES",
|
||||||
|
"module_LTLIBRARIES",
|
||||||
|
]:
|
||||||
xref_targets.extend(mv[varname].strip().split())
|
xref_targets.extend(mv[varname].strip().split())
|
||||||
|
|
||||||
# check for files using clippy but not listed in clippy_scan
|
# check for files using clippy but not listed in clippy_scan
|
||||||
@ -63,6 +68,9 @@ if args.dev_build:
|
|||||||
)
|
)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
# this additional-dependency rule is stuck onto all compile targets that
|
||||||
|
# compile a file which uses clippy-generated input, so it has a dependency to
|
||||||
|
# make that first.
|
||||||
clippydep = Template(
|
clippydep = Template(
|
||||||
"""
|
"""
|
||||||
${clippybase}.$$(OBJEXT): ${clippybase}_clippy.c
|
${clippybase}.$$(OBJEXT): ${clippybase}_clippy.c
|
||||||
@ -70,6 +78,8 @@ ${clippybase}.lo: ${clippybase}_clippy.c
|
|||||||
${clippybase}_clippy.c: $$(CLIPPY_DEPS)"""
|
${clippybase}_clippy.c: $$(CLIPPY_DEPS)"""
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# this one is used when one .c file is built multiple times with different
|
||||||
|
# CFLAGS
|
||||||
clippyauxdep = Template(
|
clippyauxdep = Template(
|
||||||
"""# clippy{
|
"""# clippy{
|
||||||
# auxiliary clippy target
|
# auxiliary clippy target
|
||||||
@ -88,6 +98,7 @@ while lines:
|
|||||||
if line.startswith(autoderp):
|
if line.startswith(autoderp):
|
||||||
line = line[len(autoderp) :]
|
line = line[len(autoderp) :]
|
||||||
|
|
||||||
|
# allow rerunning on already-clippified Makefile
|
||||||
if line == "# clippy{":
|
if line == "# clippy{":
|
||||||
while lines:
|
while lines:
|
||||||
line = lines.pop(0)
|
line = lines.pop(0)
|
||||||
@ -113,29 +124,53 @@ while lines:
|
|||||||
|
|
||||||
target, dep = m.group(1), m.group(2)
|
target, dep = m.group(1), m.group(2)
|
||||||
|
|
||||||
|
filename = os.path.basename(target)
|
||||||
|
if "-" in filename:
|
||||||
|
# dashes in output filename = building same .c with different CFLAGS
|
||||||
|
am_name, _ = filename.split("-", 1)
|
||||||
|
am_name = os.path.join(os.path.dirname(target), am_name)
|
||||||
|
am_name = am_name.replace("/", "_")
|
||||||
|
extraflags = " $(%s_CFLAGS)" % (am_name,)
|
||||||
|
else:
|
||||||
|
# this path isn't really triggered because automake is using a generic
|
||||||
|
# .c => .o rule unless CFLAGS are customized for a target
|
||||||
|
extraflags = ""
|
||||||
|
|
||||||
if target.endswith(".lo") or target.endswith(".o"):
|
if target.endswith(".lo") or target.endswith(".o"):
|
||||||
if not dep.endswith(".h"):
|
if not dep.endswith(".h"):
|
||||||
|
# LLVM bitcode targets for analysis tools
|
||||||
bcdeps.append("%s.bc: %s" % (target, target))
|
bcdeps.append("%s.bc: %s" % (target, target))
|
||||||
bcdeps.append("\t$(AM_V_LLVM_BC)$(COMPILE) -emit-llvm -c -o $@ %s" % (dep))
|
bcdeps.append(
|
||||||
|
"\t$(AM_V_LLVM_BC)$(COMPILE)%s -emit-llvm -c -o $@ %s"
|
||||||
|
% (extraflags, dep)
|
||||||
|
)
|
||||||
if m.group(2) in clippy_scan:
|
if m.group(2) in clippy_scan:
|
||||||
|
# again - this is only hit for targets with custom CFLAGS, because
|
||||||
|
# automake uses a generic .c -> .o rule for standard CFLAGS
|
||||||
out_lines.append(
|
out_lines.append(
|
||||||
clippyauxdep.substitute(target=m.group(1), clippybase=m.group(2)[:-2])
|
clippyauxdep.substitute(target=m.group(1), clippybase=m.group(2)[:-2])
|
||||||
)
|
)
|
||||||
|
|
||||||
out_lines.append(line)
|
out_lines.append(line)
|
||||||
|
|
||||||
|
# now, cover all the .c files that don't have special build rules
|
||||||
out_lines.append("# clippy{\n# main clippy targets")
|
out_lines.append("# clippy{\n# main clippy targets")
|
||||||
for clippy_file in clippy_scan:
|
for clippy_file in clippy_scan:
|
||||||
out_lines.append(clippydep.substitute(clippybase=clippy_file[:-2]))
|
out_lines.append(clippydep.substitute(clippybase=clippy_file[:-2]))
|
||||||
|
|
||||||
|
# combine daemon .xref files into frr.xref
|
||||||
out_lines.append("")
|
out_lines.append("")
|
||||||
out_lines.append("xrefs = %s" % (" ".join(["%s.xref" % target for target in xref_targets])))
|
out_lines.append(
|
||||||
|
"xrefs = %s" % (" ".join(["%s.xref" % target for target in xref_targets]))
|
||||||
|
)
|
||||||
out_lines.append("frr.xref: $(xrefs)")
|
out_lines.append("frr.xref: $(xrefs)")
|
||||||
out_lines.append("")
|
out_lines.append("")
|
||||||
|
|
||||||
#frr.xref: $(bin_PROGRAMS) $(sbin_PROGRAMS) $(lib_LTLIBRARIES) $(module_LTLIBRARIES)
|
# analog but slower way to get the same frr.xref
|
||||||
# $(AM_V_XRELFO) $(CLIPPY) $(top_srcdir)/python/xrelfo.py -o $@ $^
|
# frr.xref: $(bin_PROGRAMS) $(sbin_PROGRAMS) $(lib_LTLIBRARIES) $(module_LTLIBRARIES)
|
||||||
|
# $(AM_V_XRELFO) $(CLIPPY) $(top_srcdir)/python/xrelfo.py -o $@ $^
|
||||||
|
|
||||||
|
# LLVM bitcode link targets creating a .bc file for whole daemon or lib
|
||||||
out_lines.append("")
|
out_lines.append("")
|
||||||
out_lines.extend(bcdeps)
|
out_lines.extend(bcdeps)
|
||||||
out_lines.append("")
|
out_lines.append("")
|
||||||
|
@ -561,7 +561,6 @@ static void process_call(struct json_object *js_calls,
|
|||||||
unsigned n_args = LLVMGetNumArgOperands(instr);
|
unsigned n_args = LLVMGetNumArgOperands(instr);
|
||||||
|
|
||||||
bool is_external = LLVMIsDeclaration(called);
|
bool is_external = LLVMIsDeclaration(called);
|
||||||
enum called_fn called_type = FN_GENERIC;
|
|
||||||
|
|
||||||
js_call = json_object_new_object();
|
js_call = json_object_new_object();
|
||||||
json_object_array_add(js_calls, js_call);
|
json_object_array_add(js_calls, js_call);
|
||||||
@ -570,7 +569,6 @@ static void process_call(struct json_object *js_calls,
|
|||||||
json_object_new_boolean(is_external));
|
json_object_new_boolean(is_external));
|
||||||
|
|
||||||
if (!called_name || called_len == 0) {
|
if (!called_name || called_len == 0) {
|
||||||
called_type = FN_NONAME;
|
|
||||||
json_object_object_add(js_call, "type",
|
json_object_object_add(js_call, "type",
|
||||||
json_object_new_string("indirect"));
|
json_object_new_string("indirect"));
|
||||||
|
|
||||||
@ -653,8 +651,6 @@ static void process_call(struct json_object *js_calls,
|
|||||||
}
|
}
|
||||||
#ifdef FRR_SPECIFIC
|
#ifdef FRR_SPECIFIC
|
||||||
} else if (!strcmp(called_name, "_install_element")) {
|
} else if (!strcmp(called_name, "_install_element")) {
|
||||||
called_type = FN_INSTALL_ELEMENT;
|
|
||||||
|
|
||||||
LLVMValueRef param0 = LLVMGetOperand(instr, 0);
|
LLVMValueRef param0 = LLVMGetOperand(instr, 0);
|
||||||
if (!LLVMIsAConstantInt(param0))
|
if (!LLVMIsAConstantInt(param0))
|
||||||
goto out_nonconst;
|
goto out_nonconst;
|
||||||
@ -694,8 +690,6 @@ static void process_call(struct json_object *js_calls,
|
|||||||
json_object_new_string("install_element"));
|
json_object_new_string("install_element"));
|
||||||
return;
|
return;
|
||||||
} else if (is_thread_sched(called_name, called_len)) {
|
} else if (is_thread_sched(called_name, called_len)) {
|
||||||
called_type = FN_THREAD_ADD;
|
|
||||||
|
|
||||||
json_object_object_add(js_call, "type",
|
json_object_object_add(js_call, "type",
|
||||||
json_object_new_string("thread_sched"));
|
json_object_new_string("thread_sched"));
|
||||||
json_object_object_add(
|
json_object_object_add(
|
||||||
|
Loading…
Reference in New Issue
Block a user