diff options
author | Evgeny Karpov <evgeny.karpov@microsoft.com> | 2024-08-14 17:56:38 +0200 |
---|---|---|
committer | Evgeny Karpov <eukarpov@gmail.com> | 2024-11-19 14:27:32 +0100 |
commit | 5181d982c34a38a552f6d4d19adb039171893ad7 (patch) | |
tree | 44af355d8731dfc98acaaa2ecffb2a3aafe4fa1e /gcc/config/freebsd-nthr.h | |
parent | 3f28c4f1df9f898f70acb244dc71f5b2cc57471b (diff) | |
download | gcc-5181d982c34a38a552f6d4d19adb039171893ad7.zip gcc-5181d982c34a38a552f6d4d19adb039171893ad7.tar.gz gcc-5181d982c34a38a552f6d4d19adb039171893ad7.tar.bz2 |
Support weak references
The patch adds support for weak references. The original MinGW
implementation targets ix86, which handles weak symbols differently
compared to AArch64. In AArch64, the weak symbols are replaced by
other symbols which reference the original weak symbols, and the
compiler does not track the original symbol names.
This patch resolves this and declares the original symbols.
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
This is the first commit in the third patch series with SMALL code
model fixes, optimization fixes, LTO, and minimal C++ enablement.
Prepared, refactored and validated by
Radek Barton <radek.barton@microsoft.com> and
Evgeny Karpov <evgeny.karpov@microsoft.com>
Contributor: Zac Walker <zacwalker@microsoft.com>
gcc/ChangeLog:
* config/aarch64/cygming.h (SUB_TARGET_RECORD_STUB): Request
declaration for weak symbols.
(PE_COFF_LEGITIMIZE_EXTERN_DECL): Legitimize external
declaration for weak symbols.
* config/i386/cygming.h (SUB_TARGET_RECORD_STUB): Update
declarations in ix86 with the same functionality.
(PE_COFF_LEGITIMIZE_EXTERN_DECL): Likewise.
* config/mingw/winnt-dll.cc (legitimize_pe_coff_symbol):
Support declaration for weak symbols if requested.
* config/mingw/winnt.cc (struct stub_list): Likewise.
(mingw_pe_record_stub): Likewise.
(mingw_pe_file_end): Likewise.
* config/mingw/winnt.h (mingw_pe_record_stub): Likewise.
Diffstat (limited to 'gcc/config/freebsd-nthr.h')
0 files changed, 0 insertions, 0 deletions