Monday, September 2, 2024 Richard Sandiford <richard.sandif...@arm.com> wrote:
> On patch 1, do you have a reference for how AArch64 and x86 handle weak > references for MinGW? The code looks good, but I didn't really follow > why it was doing what it was doing. Monday, September 2, 2024 Martin Storsjö <mar...@martin.st> >> The patch adds support for weak references. The original MinGW >> implementation targets ix86, which handles weak symbols differently >> compared to AArch64. > > Please clarify this statement. Here is an explanation of why this change is needed and what the difference is between x86_64-w64-mingw32 and aarch64-w64-mingw32. The way x86_64 calls a weak function: call weak_fn2 GCC emits the call and creates the required definitions at the end of the assembly: .weak weak_fn2 .def weak_fn2; .scl 2; .type 32; .endef This is different from aarch64: weak_fn2 will be legitimized and replaced by .refptr.weak_fn2, and there will be no other references to weak_fn2 in the code. adrp x0, .refptr.weak_fn2 add x0, x0, :lo12:.refptr.weak_fn2 ldr x0, [x0] blr x0 GCC does not emit the required definitions at the end of the assembly, and weak_fn2 is tracked only by the mingw stub sybmol. Without the change, the stub definition will emit: .section .rdata$.refptr.weak_fn2, "dr" .globl .refptr.weak_fn2 .linkonce discard .refptr.weak_fn2: .quad weak_fn2 which is not enough. This fix will emit the required definitions: .weak weak_fn2 .def weak_fn2; .scl 2; .type 32; .endef .section .rdata$.refptr.weak_fn2, "dr" .globl .refptr.weak_fn2 .linkonce discard .refptr.weak_fn2: .quad weak_fn2 Regards, Evgeny