Skip to content

Commit 6c50124

Browse files
authored
removes section and other symbols in ELF (#1220)
* removes an extra llvm from opam's depext We already have llvm-9 installed so there is no reason to install the default llvm also. * enables options in configure-omake though careful many of the options will be just ignored, either by the script or by oasis/omake intergration. Use the new feature immediately in the build-and-test action to enable tests and specify the llvm version (which is for now ignored, but see the next commit). * pulls the llvm configuration from setup in omake This is much better than specifying them manually as we did before :) Also, switches back to the static linking with llvm when omake is used. * disables the emission of section, file, and other symbols for ELF The section symbols confuse our symbolization procedure so that at the end we get symbols named as `.text` instead of their real names. To prevent this, we are not emitting anymore relocation information about symbols that are sections, files, objects, and other non-functions. This commit fixes the nightly regression test. The underlying issue is triggered only on modern LLVM (e.g., it is not observable on LLVM 6 and before, but is definitely triggered on 9, not sure about the in between versions).
1 parent 23b3443 commit 6c50124

File tree

5 files changed

+47
-14
lines changed

5 files changed

+47
-14
lines changed

.github/workflows/build-and-test.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@ jobs:
3636
opam install omake
3737
3838
- name: Configure BAP
39-
run: opam exec -- ./configure-omake
39+
run: |
40+
opam exec -- ./configure-omake \
41+
--enable-tests \
42+
--with-llvm-version=9 \
43+
--with-llvm-config=llvm-config-9
4044
4145
- name: Build BAP
4246
run: opam exec -- make

configure-omake

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/sh
22

3-
rm -f _oasis
3+
rm -f _oasis setup.log.om setup.data _oasis_setup.om
44
mv oasis/benchmarks oasis/benchmarks.backup
55
mv oasis/piqi-printers oasis/piqi-printers.backup
66
mv oasis/common oasis/common.backup
@@ -17,10 +17,32 @@ sed -i 's/.*Build$.*//' _oasis
1717
sed -i 's/.*CCOpt:.*//' _oasis
1818
sed -i 's/.*CCLib:.*//' _oasis
1919

20+
FST=true
21+
22+
23+
for i in "$@"; do
24+
if $FST; then
25+
set --
26+
FST=false
27+
fi
28+
29+
case $i in
30+
--*=*)
31+
ARG=${i%%=*}
32+
VAL=${i##*=}
33+
set -- "$@" "$ARG" "$VAL"
34+
;;
35+
*)
36+
set -- "$@" "$i"
37+
;;
38+
esac
39+
done
40+
41+
2042
# call setup twice so that it can capture the AB deps
2143
for pass in `seq 2`; do
2244
oasis setup
2345
ocamlfind ocamlopt unix.cmxa setup.ml -o setup.exe
2446
rm setup.cmx setup.cmi setup.o
25-
./setup.exe -configure --prefix $(opam config var prefix) --enable-tests
47+
./setup.exe -configure --prefix $(opam config var prefix) "$@"
2648
done

lib/bap_llvm/OMakefile

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@
33
# for more documentation.
44

55
CFLAGS += -O2
6-
CXXFLAGS += -O2 -std=c++11 -fPIC -I$(ROOT)/lib/bap_disasm -I/usr/lib/llvm-6.0/include -std=c++0x -fuse-ld=gold -Wl,--no-keep-files-mapped -Wl,--no-map-whole-files -fPIC -fvisibility-inlines-hidden -Werror=date-time -std=c++11 -Wall -W -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wno-maybe-uninitialized -Wdelete-non-virtual-dtor -Wno-comment -ffunction-sections -fdata-sections -O2 -DNDEBUG -fno-exceptions -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
7-
8-
OCAMLMKLIBFLAGS += -L/usr/lib/llvm-6.0/lib -lLLVM-6.0 -dllpath /usr/lib/llvm-6.0/lib -lstdc++ -lz -lrt -ldl -ltinfo -lpthread -lm -lcurses
9-
6+
CXXFLAGS += -O2 -std=c++11 -fPIC -I$(ROOT)/lib/bap_disasm
7+
8+
# pull the llvm configuration
9+
CXXFLAGS += $(split $(oasis_llvm_cxxflags))
10+
OCAMLMKLIBFLAGS += \
11+
$(split $(oasis_llvm_libs)) \
12+
$(split $(oasis_llvm_ldflags)) \
13+
-lcurses -lstdc++
1014

1115
include _oasis_hier.om
1216

lib/bap_llvm/llvm_elf_loader.hpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -202,12 +202,16 @@ void emit_relocations(const ELFObjectFile<T> &obj, ogre_doc &s) {
202202
for (auto rel : sec.relocations()) {
203203
auto sym = rel.getSymbol();
204204
if (sym != prim::end_symbols(obj)) {
205-
uint64_t raddr = prim::relocation_offset(rel);
206-
if (auto addr = prim::symbol_address(*sym))
207-
if (*addr) s.entry("llvm:relocation") << raddr << *addr;
208-
if (auto name = prim::symbol_name(*sym))
209-
if (!name->empty())
210-
s.entry("llvm:name-reference") << raddr << *name;
205+
auto typ = prim::symbol_type(*sym);
206+
if (typ && (*typ == SymbolRef::ST_Function ||
207+
*typ == SymbolRef::ST_Unknown)) {
208+
uint64_t raddr = prim::relocation_offset(rel);
209+
if (auto addr = prim::symbol_address(*sym))
210+
if (*addr) s.entry("llvm:relocation") << raddr << *addr;
211+
if (auto name = prim::symbol_name(*sym))
212+
if (!name->empty())
213+
s.entry("llvm:name-reference") << raddr << *name;
214+
}
211215
}
212216
}
213217
}

opam/opam

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,6 @@ depexts: [
308308
"llvm-9-dev"
309309
"time"
310310
"clang"
311-
"llvm"
312311
"m4"
313312
"dejagnu"
314313
] {os-distribution = "ubuntu"}

0 commit comments

Comments
 (0)