歡迎來到 https://hackmd.io/c/COSCUP2018 共筆
點擊本頁上方的 開始用 Markdown 一起寫筆記!
手機版請點選上方 按鈕展開議程列表。
可以自我編譯的編譯器代表在編譯自己的過程中
可以不需要借助其他的toolchain,
但要完成這樣的編譯器並不是一件容易的事情…
(尤其是只需要1500行)
AMaCC 辦到了
究竟AMaCC怎麼樣用不到1500 行辦到?
讓我們看下去…
由成功大學師生黃敬群(jserv)、陳建霖、梁穎睿等人開發的self-compiling的C語言編譯器
amacc.c
所編譯出來的執行檔可用來編譯 amacc.c
, 後者產生出來的執行檔一樣具備編譯 amacc.c
的能力dlsym(0, "open")
假如有一個語言X,
他的compiler不能編譯X語言, 那要怎麼驗證compiler?
但是語言X的第一個compiler產生之前,
要怎麼編譯出語言X的第一個compiler?
這個就是 bootstrapping problem
有三種方法:
qemu-arm -L /usr/arm-linux-gnueabihf ./amacc -s tests/hello.c
1: #include <stdio.h>
2:
3: int main()
4: {
5: printf("hello, world\n");
ENT 0
IMM -161644536
PSH
PRTF
ADJ 1
6: return 0;
IMM 0
LEV
7: }
LEV
$ arm-linux-gnueabihf-readelf -l ./elf/amacc
Elf file type is EXEC (Executable file)
Entry point 0xb73ab0b4
There are 4 program headers, starting at offset 52
Program Headers:
Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
LOAD 0x000000 0xb73ab000 0xb73ab000 0x125a0 0x125a0 R E 0x1000
LOAD 0x013008 0xb746d008 0xb746d008 0x00f36 0x00f36 RW 0x1000
INTERP 0x013cb8 0xb746dcb8 0xb746dcb8 0x00019 0x00019 R 0x1
[Requesting program interpreter: /lib/ld-linux-armhf.so.3]
DYNAMIC 0x013c48 0xb746dc48 0xb746dc48 0x00070 0x00070 RW 0x4
Section to Segment mapping:
Segment Sections...
00 .text .rel.plt .plt
01 .data .dynstr .dynsym .dynamic .interp .got
02 .interp
03 .dynamic
$ arm-linux-gnueabihf-readelf -s ./elf/amacc
Symbol table '.dynsym' contains 19 entries:
Num: Value Size Type Bind Vis Ndx Name
0: 00000000 0 NOTYPE LOCAL DEFAULT UND
1: 00000000 0 FUNC GLOBAL DEFAULT UND open
2: 00000000 0 FUNC GLOBAL DEFAULT UND read
3: 00000000 0 FUNC GLOBAL DEFAULT UND write
4: 00000000 0 FUNC GLOBAL DEFAULT UND close
5: 00000000 0 FUNC GLOBAL DEFAULT UND printf
6: 00000000 0 FUNC GLOBAL DEFAULT UND malloc
7: 00000000 0 FUNC GLOBAL DEFAULT UND free
8: 00000000 0 FUNC GLOBAL DEFAULT UND memset
9: 00000000 0 FUNC GLOBAL DEFAULT UND memcmp
10: 00000000 0 FUNC GLOBAL DEFAULT UND memcpy
11: 00000000 0 FUNC GLOBAL DEFAULT UND strcmp
12: 00000000 0 FUNC GLOBAL DEFAULT UND mmap
13: 00000000 0 FUNC GLOBAL DEFAULT UND dlsym
14: 00000000 0 FUNC GLOBAL DEFAULT UND bsearch
15: 00000000 0 FUNC GLOBAL DEFAULT UND strlen
16: 00000000 0 FUNC GLOBAL DEFAULT UND __clear_cache
17: 00000000 0 FUNC GLOBAL DEFAULT UND __libc_start_main
18: 00000000 0 FUNC GLOBAL DEFAULT UND exit
PT_LOAD
PT_INTERP
PT_DYNAMIC
((S + A) | T) – P |
S:function的位址 A:addend T: P:address of the place being relocated |
COSCUP2018
source
AMaCC
ARMv7-a
Encoding A1
ELF
arm
armv7-a
dynamic linker
or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Do you want to remove this version name and description?
Syncing