You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Since the dynamic linking was introduced in the previous commit, this
commit updates the README to describe how to use dynamic linking mode
and provides basic usage examples for illustration.
Copy file name to clipboardExpand all lines: README.md
+39-3Lines changed: 39 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -74,10 +74,19 @@ To execute the snapshot test, install the packages below:
74
74
$ sudo apt-get install graphviz jq
75
75
```
76
76
77
+
Additionally, because `shecc` supports the dynamic linking mode for the Arm architecture,
78
+
it needs to install the ARM GNU toolchain to obtain the ELF interpreter and other dependencies:
79
+
```shell
80
+
$ sudo apt-get install gcc-arm-linux-gnueabihf
81
+
```
82
+
Another approach is to manually download and install the toolchain from [ARM Developer website](https://developer.arm.com/downloads/-/arm-gnu-toolchain-downloads).
83
+
84
+
Select "x86_64 Linux hosted cross toolchains" - "AArch32 GNU/Linux target with hard float (arm-none-linux-gnueabihf)" to download the toolchain.
85
+
77
86
## Build and Verify
78
87
79
88
Configure which backend you want, `shecc` supports ARMv7-A and RV32IM backend:
80
-
```
89
+
```shell
81
90
$ make config ARCH=arm
82
91
# Target machine code switch to Arm
83
92
@@ -86,13 +95,29 @@ $ make config ARCH=riscv
86
95
```
87
96
88
97
Run `make` and you should see this:
98
+
```shell
99
+
$ make
100
+
CC+LD out/inliner
101
+
GEN out/libc.inc
102
+
CC out/src/main.o
103
+
LD out/shecc
104
+
SHECC out/shecc-stage1.elf
105
+
SHECC out/shecc-stage2.elf
89
106
```
107
+
108
+
Run `make LINK_MODE=dynamic` to use the dynamic linking mode and generate the dynamically linked compiler:
109
+
```shell
110
+
# If using the dynamic linking mode, you should add 'LINK_MODE=dynamic' for each 'make' command.
111
+
$ make LINK_MODE=dynamic
90
112
CC+LD out/inliner
91
113
GEN out/libc.inc
92
114
CC out/src/main.o
93
115
LD out/shecc
94
116
SHECC out/shecc-stage1.elf
95
117
SHECC out/shecc-stage2.elf
118
+
119
+
$ file out/shecc-stage2.elf
120
+
out/shecc-stage2.elf: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-armhf.so.3, not stripped
96
121
```
97
122
98
123
For development builds with memory safety checks:
@@ -103,22 +128,32 @@ $ make check-sanitizer
103
128
104
129
File `out/shecc` is the first stage compiler. Its usage:
-`--dynlink` : Use dynamic linking (default: disabled)
114
140
115
-
Example:
141
+
Example 1: static linking mode
116
142
```shell
117
143
$ out/shecc -o fib tests/fib.c
118
144
$ chmod +x fib
119
145
$ qemu-arm fib
120
146
```
121
147
148
+
Example 2: dynamic linking mode
149
+
150
+
Notice that `/usr/arm-linux-gnueabihf` is the ELF interpreter prefix. Since the path may be different if you manually install the ARM GNU toolchain instead of using `apt-get`, you should set the prefix to the actual path.
151
+
```shell
152
+
$ out/shecc --dynlink -o fib tests/fib.c
153
+
$ chmod +x fib
154
+
$ qemu-arm -L /usr/arm-linux-gnueabihf fib
155
+
```
156
+
122
157
### IR Regression Tests
123
158
124
159
To ensure the consistency of frontend (lexer, parser) behavior when working on it, the snapshot test is introduced.
@@ -142,6 +177,7 @@ use `update-snapshot` / `check-snapshot` instead.
142
177
143
178
`shecc` comes with a comprehensive test suite (200+ test cases). To run the tests:
144
179
```shell
180
+
# Add 'LINK_MODE=dynamic' if using the dynamic linking mode.
145
181
$ make check # Run all tests (stage 0 and stage 2)
0 commit comments