Skip to content

Commit 730d730

Browse files
authored
Merge pull request #1089 from pkgw/aarch64
Add aarch64-unknown-linux-musl as a cross-buildable architecture
2 parents 4b6c433 + a9e9b98 commit 730d730

3 files changed

Lines changed: 49 additions & 0 deletions

File tree

Cross.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
[target.aarch64-unknown-linux-musl]
2+
image = "tectonictypesetting/crossbuild:aarch64-unknown-linux-musl"
3+
14
[target.arm-unknown-linux-musleabihf]
25
image = "tectonictypesetting/crossbuild:arm-unknown-linux-musleabihf"
36

crates/engine_xetex/xetex/xetex-engine-interface.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,45 @@ tt_engine_xetex_main(
6868
ttbc_global_engine_exit();
6969
return rv;
7070
}
71+
72+
73+
/* "What is happening here?", you might ask. Good question!
74+
*
75+
* My first attempt (PKGW, 2023 Sep) to build a static version of Tectonic
76+
* for the aarch64 platform using Tectonic's cross-compilation framework
77+
* ran into the following error when trying to link the final executable:
78+
*
79+
* /home/rust/sysroot-aarch64/usr/lib/libc.a(sigsetjmp.lo): in function `sigsetjmp':
80+
* /home/buildozer/aports/main/musl/src/v1.2.3/src/signal/aarch64/sigsetjmp.s:7:(.text+0x0):
81+
* relocation truncated to fit: R_AARCH64_CONDBR19 against symbol `setjmp'
82+
* defined in .text section in /home/rust/sysroot-aarch64/usr/lib/libc.a(setjmp.lo)
83+
*
84+
* So, musl libc's implementation of sigsetjmp() invokes setjmp() in some
85+
* hand-written assembly. It appears that for whatever reason, when the linker
86+
* is trying to build the Tectonic executable on aarch64, it ends up wanting to
87+
* locate setjmp() and sigsetjmp() far away from each other in the final file,
88+
* and the particular branch instruction used in sigsetjmp() can only specify a
89+
* relatively small offset that cannot capture the location of setjmp(). The musl
90+
* developers tentatively agree that this seems to be a bug in musl's
91+
* implementation.
92+
*
93+
* I had the idea that maybe if I referenced both functions in my code, that
94+
* would encourage the linker to place them closer to each other. And, guess
95+
* what, it seems to work! Bananas!
96+
*
97+
* This hardly costs us anything so we don't bother to try to #ifdef it for the
98+
* specific circumstances given above, but Windows doesn't provide sigsetjmp.
99+
*/
100+
#ifndef _WIN32
101+
void __terrible_aarch64_musl_linker_hack_never_call_me(void);
102+
103+
void
104+
__terrible_aarch64_musl_linker_hack_never_call_me(void)
105+
{
106+
jmp_buf buf1;
107+
sigjmp_buf buf2;
108+
109+
setjmp(buf1);
110+
sigsetjmp(buf2, 0);
111+
}
112+
#endif

dist/azure-build-and-test.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,10 @@ parameters:
165165
- name: crossBuilds
166166
type: object
167167
default:
168+
- name: aarch64_unknown_linux_musl
169+
vars:
170+
TARGET: aarch64-unknown-linux-musl
171+
168172
- name: arm_unknown_linux_musleabihf
169173
vars:
170174
TARGET: arm-unknown-linux-musleabihf

0 commit comments

Comments
 (0)