[PATCH] D46417: wasm: Add a flag to control merging data segments
Nick Fitzgerald via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu May 3 19:17:58 PDT 2018
fitzgen added a comment.
I don't know how to write a test for `lld` -- would appreciate some guidance doing that!
I do have a little test case I have been using:
This is `a.c`:
char A_HELLO[] = "hello";
char A_GOODBYE[] = "goodbye";
char A_WHATEVER[] = "whatever";
int N_ITERATIONS = 42;
This is `b.c`:
// b.c
#define WASM_EXPORT __attribute__((visibility("default")))
extern char* A_HELLO;
extern char* A_GOODBYE;
extern char* A_WHATEVER;
extern int N_ITERATIONS;
extern void print(char*);
WASM_EXPORT
void printem() {
for (int i = 0; i < N_ITERATIONS; i++) {
print(A_HELLO);
print(A_GOODBYE);
print(A_WHATEVER);
}
}
To build and test:
~/llvm/obj/bin/clang --target=wasm32-unknown-unknown-wasm -c a.c
~/llvm/obj/bin/clang --target=wasm32-unknown-unknown-wasm -c b.c
~/llvm/obj/bin/wasm-ld --allow-undefined -o merged-data-segments.wasm a.o b.o
~/llvm/obj/bin/wasm-ld --allow-undefined --no-merge-data-segments -o no-merged-data-segments.wasm a.o b.o
wasm-objdump -x merged-data-segments.wasm
wasm-objdump -x no-merged-data-segments.wasm
This is the dump for `merged-data-segments.wasm`:
merged-data-segments.wasm: file format wasm 0x1
Section Details:
Type:
- type[0] () -> nil
- type[1] (i32) -> nil
Import:
- func[0] sig=0 <_start> <- env._start
- func[1] sig=1 <print> <- env.print
Function:
- func[2] sig=0 <__wasm_call_ctors>
- func[3] sig=0 <printem>
Table:
- table[0] type=anyfunc initial=1 max=1
Memory:
- memory[0] pages: initial=2
Global:
- global[0] i32 mutable=1 - init i32=66592
- global[1] i32 mutable=0 - init i32=66592
- global[2] i32 mutable=0 - init i32=1052
Export:
- memory[0] -> "memory"
- global[1] -> "__heap_base"
- global[2] -> "__data_end"
- func[3] <printem> -> "printem"
Data:
- segment[0] size=28 - init i32=1024
- 0000400: 6865 6c6c 6f00 676f 6f64 6279 6500 7768 hello.goodbye.wh
- 0000410: 6174 6576 6572 0000 2a00 0000 atever..*...
Custom:
- name: "name"
- func[0] _start
- func[1] print
- func[2] __wasm_call_ctors
- func[3] printem
And this is the dump for `no-merged-data-segments.wasm`:
no-merged-data-segments.wasm: file format wasm 0x1
Section Details:
Type:
- type[0] () -> nil
- type[1] (i32) -> nil
Import:
- func[0] sig=0 <_start> <- env._start
- func[1] sig=1 <print> <- env.print
Function:
- func[2] sig=0 <__wasm_call_ctors>
- func[3] sig=0 <printem>
Table:
- table[0] type=anyfunc initial=1 max=1
Memory:
- memory[0] pages: initial=2
Global:
- global[0] i32 mutable=1 - init i32=66592
- global[1] i32 mutable=0 - init i32=66592
- global[2] i32 mutable=0 - init i32=1052
Export:
- memory[0] -> "memory"
- global[1] -> "__heap_base"
- global[2] -> "__data_end"
- func[3] <printem> -> "printem"
Data:
- segment[0] size=6 - init i32=1024
- 0000400: 6865 6c6c 6f00 hello.
- segment[1] size=8 - init i32=1030
- 0000406: 676f 6f64 6279 6500 goodbye.
- segment[2] size=9 - init i32=1038
- 000040e: 7768 6174 6576 6572 00 whatever.
- segment[3] size=4 - init i32=1048
- 0000418: 2a00 0000 *...
Custom:
- name: "name"
- func[0] _start
- func[1] print
- func[2] __wasm_call_ctors
- func[3] printem
Repository:
rLLD LLVM Linker
https://reviews.llvm.org/D46417
More information about the llvm-commits
mailing list