Skip to content

Commit c5ae159

Browse files
committed
fix issues with BFD arches (#7)
It came out that BFD architectures in `qemu/dis/bfd.h` folder is 9 years older, than architectures in the `bap-frames/libtrace`, and the latter is 14 years older than the latest BFD release. In fact, the BFD architectures are not stable, and numbers for them are allocated at each configuration and depends on the configuration options. The choice to rely on them was a bad decision. The better approach would be to use our own wired format for arches, specified in protobuf or something like this. But so far, we're relying on piqi, that doesn't have (a) normal enums with fixed values, (b) normal extension mechanism. So we will still rely on the old way of specifying architectures. Now we will use architectures from `frames/libtrace/` library, to ensure, that everyone has the same constants. To reduce confusion with BFD we've moved all definitions to the `frames` namespace (i.e., `s/bfd_/frames_`). This PR also fixes numerous issues with the build system: 1. protobuf now is built as a part of `all` target, no need to do `make -C protobuf` 2. protobuf will generate `librotoframes` library, instead of libtrace that nameclashed with at least two libraries: trace library from the qemu itself and libtrace from the bap-frames 3. configure script will properly expand paths 4. protobuf target will now depend on the `piqi` file in the frames library and if the latter is changed, the library will be regenerated and recompiled, as well as all dependencies.
1 parent 465ce68 commit c5ae159

File tree

11 files changed

+59
-50
lines changed

11 files changed

+59
-50
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,6 @@ cscope.*
117117
tags
118118
TAGS
119119
*~
120+
/protobuf/frame.piqi.pb-c.c
121+
/protobuf/frame.piqi.pb-c.h
122+
/protobuf/frame.piqi.proto

Makefile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ ifneq ($(wildcard config-host.mak),)
99
all:
1010
include config-host.mak
1111

12+
ifeq ($(HAS_TRACEWRAP),y)
13+
all: protoframes
14+
15+
protoframes:
16+
make -C protobuf
17+
endif
18+
19+
1220
# Check that we're not trying to do an out-of-tree build from
1321
# a tree that's been used for an in-tree build.
1422
ifneq ($(realpath $(SRC_PATH)),$(realpath .))
@@ -146,8 +154,13 @@ ifeq ($(CONFIG_SMARTCARD_NSS),y)
146154
include $(SRC_PATH)/libcacard/Makefile
147155
endif
148156

157+
158+
159+
149160
all: $(DOCS) $(TOOLS) $(HELPERS-y) recurse-all modules
150161

162+
163+
151164
vl.o: QEMU_CFLAGS+=$(GPROF_CFLAGS)
152165

153166
vl.o: QEMU_CFLAGS+=$(SDL_CFLAGS)

README.md

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,19 @@ project.
99

1010
# Installing released binaries
1111

12-
If you don't want to mess with the source and building, then you can just
13-
dowload a tarball with prebuilt binaries. Look at the latest release and
12+
If you don't want to mess with the source and building, then you can just
13+
dowload a tarball with prebuilt binaries. Look at the latest release and
1414
it might happen, that we have built binaries for your linux distribution,
1515
if it is not the case, then create an issue, and we will build it for you.
1616

17-
Let's pretend, that you're using Ubuntu Trusty, and install it. First
17+
Let's pretend, that you're using Ubuntu Trusty, and install it. First
1818
download it with your favorite downloader:
1919

2020
```
2121
wget https://github.com/BinaryAnalysisPlatform/qemu/releases/download/v2.0.0-tracewrap-alpha/qemu-tracewrap-ubuntu-14.04.4-LTS.tgz
2222
```
2323

24-
Install it in the specified prefix with a command like `tar -C <prefix> -xf qemu-tracewrap-ubuntu-14.04.4-LTS.tgz`, e.g.,
24+
Install it in the specified prefix with a command like `tar -C <prefix> -xf qemu-tracewrap-ubuntu-14.04.4-LTS.tgz`, e.g.,
2525
to install in your home directory:
2626
```
2727
tar -C $HOME -xf qemu-tracewrap-ubuntu-14.04.4-LTS.tgz
@@ -62,42 +62,36 @@ $ opam install piqi
6262

6363
## Building
6464

65-
Download [bap-traces](https://github.com/BinaryAnalysisPlatform/bap-traces) with
65+
Download [bap-frames](https://github.com/BinaryAnalysisPlatform/bap-frames) with
6666
following command
6767

6868
```bash
69-
$ git clone https://github.com/BinaryAnalysisPlatform/bap-traces.git
69+
$ git clone https://github.com/BinaryAnalysisPlatform/bap-frames.git
7070
```
7171

7272
Download qemu tracer with following command
7373

7474
```bash
75-
$ git clone [email protected]:BinaryAnalysisPlatform/qemu.git -b tracewrap
75+
$ git clone [email protected]:BinaryAnalysisPlatform/qemu.git
7676
```
7777

78-
Change folder to qemu and build tracer with command
78+
Change folder to qemu and build tracer:
7979
```bash
80-
$ ./configure --prefix=$HOME --with-tracewrap=`realpath ../bap-frames` \
81-
--extra-ldflags=-Lprotobuf --target-list="arm-linux-user i386-linux-user \
82-
x86_64-linux-user mips-linux-user"
83-
$ make -C protobuf
80+
$ cd qemu
81+
$ ./configure --prefix=$HOME --with-tracewrap=../bap-frames --target-list="`echo {arm,i386,x86_64,mips}-linux-user`"
8482
$ make
8583
$ make install
8684
```
8785

8886
# Usage
8987

90-
To run executable `exec` and to save the trace data to `exec.trace`, use
88+
To run executable `exec` compiled for `arch`, use `qemu-arch exec` command, e.g.,
89+
`qemu-x86_64 /bin/ls`. It will dump the trace into `ls.frames` file. You can configure
90+
the filename with `-tracefile` option, e.g., `qemu-arm -tracefile arm.ls.frames ls`
9191

92-
```bash
93-
$ qemu-arm -tracefile exec.trace exec # trace ARM target executable
94-
$ qemu-i386 -tracefile exec.trace exec # trace X86 target executable
95-
$ qemu-x86_64 -tracefile exec.trace exec # trace X86-64 target executable
96-
$ qemu-mips -tracefile exec.trace exec # trace MIPS target executable
97-
```
9892

9993
Hints: use option -L to set the elf interpreter prefix to 'path'. Use
100-
[fetchlibs.sh](https://raw.githubusercontent.com/BinaryAnalysisPlatform/bap-traces/master/test/fetchlibs.sh)
94+
[fetchlibs.sh](https://raw.githubusercontent.com/BinaryAnalysisPlatform/bap-frames/master/test/fetchlibs.sh)
10195
to download arm and x86 libraries.
10296

10397
# Notes

configure

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -749,13 +749,13 @@ for opt do
749749
;;
750750
--with-trace-file=*) trace_file="$optarg"
751751
;;
752-
--with-tracewrap=*)
752+
--with-tracewrap=*)
753753
tracewrap="yes"
754-
TRACEWRAP_DIR="$optarg"
755-
QEMU_INCLUDES="$QEMU_INCLUDES -I\$(SRC_PATH)/protobuf/ "
754+
TRACEWRAP_DIR="`realpath $optarg`"
755+
QEMU_INCLUDES="$QEMU_INCLUDES -I\$(SRC_PATH)/protobuf/ -I$TRACEWRAP_DIR/libtrace/src/"
756756
QEMU_CFLAGS="$QEMU_CFLAGS -L\$(SRC_PATH)/protobuf -DHAS_TRACEWRAP "
757-
LIBS="$LIBS -ltrace -lprotobuf-c "
758-
;;
757+
LIBS="$LIBS -lprotoframes -lprotobuf-c "
758+
;;
759759
--enable-gprof) gprof="yes"
760760
;;
761761
--enable-gcov) gcov="yes"
@@ -5227,4 +5227,3 @@ printf "exec" >>config.status
52275227
printf " '%s'" "$0" "$@" >>config.status
52285228
echo >>config.status
52295229
chmod +x config.status
5230-

linux-user/arm/trace_info.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#pragma once
2+
3+
#include "frame_arch.h"
4+
5+
const uint64_t frame_arch = frame_arch_arm;
6+
const uint64_t frame_mach = frame_mach_arm_unknown;

linux-user/i386/trace_info.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#pragma once
22

3-
#include "disas/bfd.h"
3+
#include "frame_arch.h"
44

5-
const uint64_t bfd_arch = bfd_arch_i386;
6-
const uint64_t bfd_machine = bfd_mach_i386_i386;
5+
const uint64_t frame_arch = frame_arch_i386;
6+
const uint64_t frame_mach = frame_mach_i386_i386;

linux-user/mips/trace_info.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#pragma once
22

3-
#include "disas/bfd.h"
3+
#include "frame_arch.h"
44

5-
const uint64_t bfd_arch = bfd_arch_mips;
6-
const uint64_t bfd_machine = 32 ; /* bfd_mach_mipsisa32 */
7-
/* our bfd.h is so outdated, that it doesn't include it.*/
5+
const uint64_t frame_arch = frame_arch_mips;
6+
const uint64_t frame_mach = frame_mach_mipsisa32 ;

linux-user/x86_64/trace_info.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#pragma once
22

3-
#include "disas/bfd.h"
3+
#include "frame_arch.h"
44

5-
const uint64_t bfd_arch = bfd_arch_i386;
6-
const uint64_t bfd_machine = bfd_mach_x86_64;
5+
const uint64_t frame_arch = frame_arch_i386;
6+
const uint64_t frame_mach = frame_mach_x86_64;

protobuf/Makefile

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ CC=gcc
44

55
FILENAME=frame.piqi
66
EXT=pb-c
7+
PROTOFILE=$(TRACEWRAP_DIR)/piqi/$(FILENAME)
78

8-
all: libtrace.a
9+
all: libprotoframes.a
910

10-
$(FILENAME).proto:
11-
piqi to-proto $(TRACEWRAP_DIR)/$(FILENAME) -o $(FILENAME).proto
11+
$(FILENAME).proto: $(PROTOFILE)
12+
piqi to-proto $(PROTOFILE) -o $(FILENAME).proto
1213

1314
$(FILENAME).$(EXT).c: $(FILENAME).proto
1415
protoc-c --c_out=. $(FILENAME).proto
@@ -18,8 +19,8 @@ $(FILENAME).$(EXT).c: $(FILENAME).proto
1819
$(FILENAME).$(EXT).o: $(FILENAME).$(EXT).c $(FILENAME).$(EXT).h
1920
$(CC) -fPIC -c -o $(FILENAME).$(EXT).o $(FILENAME).$(EXT).c
2021

21-
libtrace.a: $(FILENAME).$(EXT).o
22-
ar rcs libtrace.a $(FILENAME).$(EXT).o
22+
libprotoframes.a: $(FILENAME).$(EXT).o
23+
ar rcs libprotoframes.a $(FILENAME).$(EXT).o
2324

2425
clean:
25-
rm libtrace.a $(FILENAME).$(EXT).[hco]
26+
rm $(FILENAME).$(EXT).[hco] $(FILENAME).proto

target-arm/trace_info.h

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)