Skip to content

Commit

Permalink
First cut of decent aarch64 support.
Browse files Browse the repository at this point in the history
  • Loading branch information
corsix committed Jun 27, 2024
1 parent f2005b7 commit 918c681
Show file tree
Hide file tree
Showing 46 changed files with 7,769 additions and 27 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ $ ./polyfill-glibc --target-glibc=2.17 /path/to/my-program

If running it _isn't_ this simple, then open a GitHub issue describing why not, and we'll try to improve things.

Note that at present, the `--target-glibc` operation of polyfill-glibc is only implemented for x86_64. If other architectures are of interest to you, open a GitHub issue so that we can gauge demand.
Note that at present, the `--target-glibc` operation of polyfill-glibc is only implemented for x86_64 and aarch64. If other architectures are of interest to you, open a GitHub issue so that we can gauge demand.

If distributing shared libraries, polyfill-glibc can also be used to inspect dependencies (with the `--print-imports` and `--print-exports` operations), and to modify how shared libraries are loaded (with the `--set-rpath`, `--set-runpath`, and `--set-soname` operations). Consult [the documentation](docs/Command_line_options.md) for a full list of command line options.

Expand Down
52 changes: 49 additions & 3 deletions build.ninja
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,19 @@ rule run_polyfill_glibc_txt
rule run_polyfill_glibc
command = ./polyfill-glibc --output $out $in $link_opt

build polyfill-glibc: link build/main.o build/renamer.o build/polyfiller.o build/x86_64/polyfiller.o build/erw.o build/v2f.o build/tokenise.o build/sht.o build/uuht.o build/arena.o build/reloc_kind.o build/common.o
build polyfill-glibc: link build/main.o build/renamer.o build/polyfiller.o build/aarch64/polyfiller.o build/x86_64/polyfiller.o build/print_eh_frame.o build/erw.o build/v2f.o build/tokenise.o build/sht.o build/uuht.o build/arena.o build/reloc_kind.o build/common.o
default polyfill-glibc
build build/aarch64/polyfills.so: create_polyfill_so polyfill-glibc
arch = aarch64
target_glibc = 2.17
build build/aarch64/polyfiller.o: cc src/aarch64/polyfiller.c | build/aarch64/assembled_gen.h
build build/aarch64/assembled_gen.h: run build/aarch64/assembler src/aarch64/_init.s src/aarch64/atexit.s src/aarch64/c11_thread.s src/aarch64/fatal.s src/aarch64/glibc_2_18.s src/aarch64/glibc_2_25.s src/aarch64/glibc_2_26.s src/aarch64/glibc_2_30.s src/aarch64/glibc_2_31.s src/aarch64/glibc_2_34.s src/aarch64/glibc_2_36.s src/aarch64/stdbit.s src/aarch64/syscalls.s src/aarch64/syscalls_ac.s
build build/aarch64/assembler: link build/aarch64/assembler.o build/tokenise.o build/sht.o build/uuht.o build/common.o
build build/aarch64/assembler.o: cc src/aarch64/assembler.c | build/aarch64/assembler_gen.h
build build/aarch64/assembler_gen.h: run build/aarch64/build_assembler src/aarch64/insn_encoding.txt
build build/aarch64/build_assembler: link build/aarch64/build_assembler.o build/tokenise.o build/sht.o build/uuht.o
build build/aarch64/build_assembler.o: cc src/aarch64/build_assembler.c
build build/aarch64/renames.h: run build/parse_renames src/aarch64/renames.txt
build build/x86_64/polyfills.so: create_polyfill_so polyfill-glibc
arch = x86_64
target_glibc = 2.3.2
Expand All @@ -39,9 +50,10 @@ build build/x86_64/set_relative_interp: link build/x86_64/set_relative_interp.o
build build/x86_64/set_relative_interp.o: cc src/x86_64/set_relative_interp.c | build/x86_64/relative_interp_payload.h
build build/polyfiller.o: cc src/polyfiller.c
build build/main.o: cc src/main.c
build build/renamer.o: cc src/renamer.c | build/x86_64/renames.h
build build/renamer.o: cc src/renamer.c | build/aarch64/renames.h build/x86_64/renames.h
build build/parse_renames: link build/parse_renames.o build/tokenise.o build/sht.o build/common.o
build build/parse_renames.o: cc src/parse_renames.c
build build/print_eh_frame.o: cc src/print_eh_frame.c
build build/erw.o: cc src/erw.c
build build/v2f.o: cc src/v2f.c
build build/tokenise.o: cc src/tokenise.c
Expand All @@ -51,6 +63,35 @@ build build/arena.o: cc src/arena.c
build build/reloc_kind.o: cc src/reloc_kind.c
build build/common.o: cc src/common.c

build build/aarch64/test/arc4random.txt: run build/aarch64/test/arc4random build/aarch64/polyfills.so
build build/aarch64/test/arc4random: link build/aarch64/test/arc4random.o build/test/syscall_filter.o
link_opt = -ldl
build build/aarch64/test/arc4random.o: cc test/aarch64/arc4random.c

build build/aarch64/test/memfd_pread_pwrite.txt: run build/aarch64/test/memfd_pread_pwrite build/aarch64/polyfills.so
build build/aarch64/test/memfd_pread_pwrite: link build/aarch64/test/memfd_pread_pwrite.o build/test/syscall_filter.o
link_opt = -ldl
build build/aarch64/test/memfd_pread_pwrite.o: cc test/aarch64/memfd_pread_pwrite.c

build build/aarch64/test/nan.txt: run build/aarch64/test/nan build/aarch64/polyfills.so
build build/aarch64/test/nan: link build/aarch64/test/nan.o
link_opt = -ldl
build build/aarch64/test/nan.o: cc test/aarch64/nan.c

build build/aarch64/test/stdbit.txt: run build/aarch64/test/stdbit build/aarch64/polyfills.so
build build/aarch64/test/stdbit: link build/aarch64/test/stdbit.o
link_opt = -ldl
build build/aarch64/test/stdbit.o: cc test/aarch64/stdbit.c

build build/aarch64/test/totalorder.txt: run build/aarch64/test/totalorder build/aarch64/polyfills.so
build build/aarch64/test/totalorder: link build/aarch64/test/totalorder.o
link_opt = -ldl
build build/aarch64/test/totalorder.o: cc test/aarch64/totalorder.c

build build/aarch64/test/twalk_r.txt: run build/x86_64/test/twalk_r build/aarch64/polyfills.so

build test/aarch64: phony build/aarch64/test/arc4random.txt build/aarch64/test/memfd_pread_pwrite.txt build/aarch64/test/nan.txt build/aarch64/test/stdbit.txt build/aarch64/test/totalorder.txt build/aarch64/test/twalk_r.txt

build build/x86_64/test/arc4random.txt: run build/x86_64/test/arc4random build/x86_64/polyfills.so
build build/x86_64/test/arc4random: link build/x86_64/test/arc4random.o build/test/syscall_filter.o
link_opt = -ldl
Expand All @@ -61,6 +102,11 @@ build build/x86_64/test/glibc_2_38: link build/x86_64/test/glibc_2_38.o
link_opt = -ldl
build build/x86_64/test/glibc_2_38.o: cc test/x86_64/glibc_2_38.c

build build/x86_64/test/memfd_pread_pwrite.txt: run build/x86_64/test/memfd_pread_pwrite build/x86_64/polyfills.so
build build/x86_64/test/memfd_pread_pwrite: link build/x86_64/test/memfd_pread_pwrite.o build/test/syscall_filter.o
link_opt = -ldl
build build/x86_64/test/memfd_pread_pwrite.o: cc test/x86_64/memfd_pread_pwrite.c

build build/x86_64/test/nan.txt: run build/x86_64/test/nan build/x86_64/polyfills.so
build build/x86_64/test/nan: link build/x86_64/test/nan.o
link_opt = -ldl
Expand All @@ -86,7 +132,7 @@ build build/x86_64/test/twalk_r: link build/x86_64/test/twalk_r.o
link_opt = -ldl
build build/x86_64/test/twalk_r.o: cc test/x86_64/twalk_r.c

build test/x86_64: phony build/x86_64/test/arc4random.txt build/x86_64/test/glibc_2_38.txt build/x86_64/test/qsort_r.txt build/x86_64/test/stdbit.txt build/x86_64/test/totalorder.txt build/x86_64/test/twalk_r.txt
build test/x86_64: phony build/x86_64/test/arc4random.txt build/x86_64/test/glibc_2_38.txt build/x86_64/test/qsort_r.txt build/x86_64/test/memfd_pread_pwrite.txt build/x86_64/test/nan.txt build/x86_64/test/stdbit.txt build/x86_64/test/totalorder.txt build/x86_64/test/twalk_r.txt

build build/test/getauxval.txt: run build/test/getauxval_pf build/test/getauxval_imp.txt build/test/getauxval_imp_pf.txt
build build/test/getauxval_imp_pf.txt: run_polyfill_glibc_txt build/test/getauxval_pf | polyfill-glibc
Expand Down
4 changes: 2 additions & 2 deletions docs/Command_line_options.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Flags that change the effect of other actions: `--output`, `--dry`, `--page-size

Takes as an argument a glibc version, for example `--target-glibc=2.17`. The action identifies all dependencies that the file has on glibc functions and variables newer than the specified version, and employs [various strategies](How_does_polyfill_glibc_work.md) to remove those dependencies.

Note that `--target-glibc` is currently only implemented for x86_64 files. If other architectures are of interest to you, open a GitHub issue so that we can gauge interest.
Note that `--target-glibc` is currently only implemented for x86_64 files and aarch64 files. If other architectures are of interest to you, open a GitHub issue so that we can gauge interest.

If there are any strong dependencies that `--target-glibc` cannot remove, then it'll fail and report the problematic dependencies, for example:

Expand Down Expand Up @@ -174,7 +174,7 @@ The `--polyfill-cfi` flag controls whether CFI is provided for statically linked

In some cases, `--target-glibc` and `--rename-dynamic-symbols` can cause additional executable code to be statically linked into the file. For some people, this can be undesirable, and so `--create-polyfill-so` and `--use-polyfill-so` are provided instead, with the effect of putting the additional executable code in a separate shared object and then dynamically linking against that shared object.

If the `--create-polyfill-so` flag is specified, then the behaviour of `--rename-dynamic-symbols` is modified: whenever `polyfill::NAME` is given as the new symbol name (regardless of whether the old symbol name is present), then `NAME@POLYFILL` is added as an _export_ to the file, with the statically linked code as the implementation of that export. The behaviour of `--target-glibc` is similarly modified: any statically linked code that _could_ be used to remove a problematic dependency (regardless of whether the problem is present) is added an _export_ to the file. The `--create-polyfill-so` flag is usually used in combination with the special input filename `empty:x86_64`, which denotes an empty ELF file. Accordingly, an invocation like the following can be used to create a shared object called `polyfills.so` with all the code required to polyfill back to glibc 2.3.2:
If the `--create-polyfill-so` flag is specified, then the behaviour of `--rename-dynamic-symbols` is modified: whenever `polyfill::NAME` is given as the new symbol name (regardless of whether the old symbol name is present), then `NAME@POLYFILL` is added as an _export_ to the file, with the statically linked code as the implementation of that export. The behaviour of `--target-glibc` is similarly modified: any statically linked code that _could_ be used to remove a problematic dependency (regardless of whether the problem is present) is added an _export_ to the file. The `--create-polyfill-so` flag is usually used in combination with the special input filename `empty:x86_64` or `empty:aarch64`, which denotes an empty ELF file. Accordingly, an invocation like the following can be used to create a shared object called `polyfills.so` with all the code required to polyfill back to glibc 2.3.2:
```
polyfill-glibc empty:x86_64 --add-hash --add-gnu-hash --create-polyfill-so --target-glibc=2.3.2 --output polyfills.so
```
Expand Down
2 changes: 1 addition & 1 deletion docs/Limitations.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Limitations of polyfill-glibc

Currently, the `--target-glibc` operation of polyfill-glibc is only implemented for x86_64. If other architectures are of interest to you, open a GitHub issue so that we can gauge interest. Note that lower level operations, for example `--set-rpath`, are implemented for all architectures.
Currently, the `--target-glibc` operation of polyfill-glibc is only implemented for x86_64 and aarch64. If other architectures are of interest to you, open a GitHub issue so that we can gauge interest. Note that lower level operations, for example `--set-rpath`, are implemented for all architectures.

Polyfills have not yet been written for every glibc function. If you're hitting such a case, open a GitHub issue so that we can gauge interest.

Expand Down
Loading

0 comments on commit 918c681

Please sign in to comment.