Skip to content
/ zig Public
forked from ziglang/zig

Commit d69a8d5

Browse files
committed
std.os.linux.pie: Remove .weak/.hidden usage in inline assembly.
This code is only compiled into the executable in PIE builds, so there really doesn't seem to be a compelling reason for `_DYNAMIC` to be accessed as a weak symbol. Small step towards ziglang#10761.
1 parent 1194393 commit d69a8d5

File tree

1 file changed

+0
-28
lines changed

1 file changed

+0
-28
lines changed

lib/std/os/linux/pie.zig

-28
Original file line numberDiff line numberDiff line change
@@ -42,29 +42,21 @@ const R_RELATIVE = switch (builtin.cpu.arch) {
4242
inline fn getDynamicSymbol() [*]elf.Dyn {
4343
return switch (builtin.cpu.arch) {
4444
.x86 => asm volatile (
45-
\\ .weak _DYNAMIC
46-
\\ .hidden _DYNAMIC
4745
\\ call 1f
4846
\\ 1: pop %[ret]
4947
\\ lea _DYNAMIC-1b(%[ret]), %[ret]
5048
: [ret] "=r" (-> [*]elf.Dyn),
5149
),
5250
.x86_64 => asm volatile (
53-
\\ .weak _DYNAMIC
54-
\\ .hidden _DYNAMIC
5551
\\ lea _DYNAMIC(%%rip), %[ret]
5652
: [ret] "=r" (-> [*]elf.Dyn),
5753
),
5854
.arc => asm volatile (
59-
\\ .weak _DYNAMIC
60-
\\ .hidden _DYNAMIC
6155
\\ add %[ret], pcl, _DYNAMIC@pcl
6256
: [ret] "=r" (-> [*]elf.Dyn),
6357
),
6458
// Work around the limited offset range of `ldr`
6559
.arm, .armeb, .thumb, .thumbeb => asm volatile (
66-
\\ .weak _DYNAMIC
67-
\\ .hidden _DYNAMIC
6860
\\ ldr %[ret], 1f
6961
\\ add %[ret], pc
7062
\\ b 2f
@@ -74,8 +66,6 @@ inline fn getDynamicSymbol() [*]elf.Dyn {
7466
),
7567
// A simple `adr` is not enough as it has a limited offset range
7668
.aarch64, .aarch64_be => asm volatile (
77-
\\ .weak _DYNAMIC
78-
\\ .hidden _DYNAMIC
7969
\\ adrp %[ret], _DYNAMIC
8070
\\ add %[ret], %[ret], #:lo12:_DYNAMIC
8171
: [ret] "=r" (-> [*]elf.Dyn),
@@ -88,8 +78,6 @@ inline fn getDynamicSymbol() [*]elf.Dyn {
8878
: [ret] "=r" (-> [*]elf.Dyn),
8979
),
9080
.hexagon => asm volatile (
91-
\\ .weak _DYNAMIC
92-
\\ .hidden _DYNAMIC
9381
\\ jump 1f
9482
\\ .word _DYNAMIC - .
9583
\\ 1:
@@ -102,23 +90,17 @@ inline fn getDynamicSymbol() [*]elf.Dyn {
10290
: "r1"
10391
),
10492
.loongarch32, .loongarch64 => asm volatile (
105-
\\ .weak _DYNAMIC
106-
\\ .hidden _DYNAMIC
10793
\\ la.local %[ret], _DYNAMIC
10894
: [ret] "=r" (-> [*]elf.Dyn),
10995
),
11096
// Note that the - 8 is needed because pc in the second lea instruction points into the
11197
// middle of that instruction. (The first lea is 6 bytes, the second is 4 bytes.)
11298
.m68k => asm volatile (
113-
\\ .weak _DYNAMIC
114-
\\ .hidden _DYNAMIC
11599
\\ lea _DYNAMIC - . - 8, %[ret]
116100
\\ lea (%[ret], %%pc), %[ret]
117101
: [ret] "=r" (-> [*]elf.Dyn),
118102
),
119103
.mips, .mipsel => asm volatile (
120-
\\ .weak _DYNAMIC
121-
\\ .hidden _DYNAMIC
122104
\\ bal 1f
123105
\\ .gpword _DYNAMIC
124106
\\ 1:
@@ -129,8 +111,6 @@ inline fn getDynamicSymbol() [*]elf.Dyn {
129111
: "lr"
130112
),
131113
.mips64, .mips64el => asm volatile (
132-
\\ .weak _DYNAMIC
133-
\\ .hidden _DYNAMIC
134114
\\ .balign 8
135115
\\ bal 1f
136116
\\ .gpdword _DYNAMIC
@@ -142,8 +122,6 @@ inline fn getDynamicSymbol() [*]elf.Dyn {
142122
: "lr"
143123
),
144124
.powerpc, .powerpcle => asm volatile (
145-
\\ .weak _DYNAMIC
146-
\\ .hidden _DYNAMIC
147125
\\ bl 1f
148126
\\ .long _DYNAMIC - .
149127
\\ 1:
@@ -155,8 +133,6 @@ inline fn getDynamicSymbol() [*]elf.Dyn {
155133
: "lr", "r4"
156134
),
157135
.powerpc64, .powerpc64le => asm volatile (
158-
\\ .weak _DYNAMIC
159-
\\ .hidden _DYNAMIC
160136
\\ bl 1f
161137
\\ .quad _DYNAMIC - .
162138
\\ 1:
@@ -168,14 +144,10 @@ inline fn getDynamicSymbol() [*]elf.Dyn {
168144
: "lr", "r4"
169145
),
170146
.riscv32, .riscv64 => asm volatile (
171-
\\ .weak _DYNAMIC
172-
\\ .hidden _DYNAMIC
173147
\\ lla %[ret], _DYNAMIC
174148
: [ret] "=r" (-> [*]elf.Dyn),
175149
),
176150
.s390x => asm volatile (
177-
\\ .weak _DYNAMIC
178-
\\ .hidden _DYNAMIC
179151
\\ larl %[ret], 1f
180152
\\ ag %[ret], 0(%[ret])
181153
\\ b 2f

0 commit comments

Comments
 (0)