summarylogtreecommitdiffstats
path: root/lto-fixup.patch
blob: 6185259baf65e4a95ce014683be263ff5ed6fcdc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
From 389a379a9d12b228da576a8bd2a23cce2f00a764 Mon Sep 17 00:00:00 2001
From: William Horvath <william@horvath.blog>
Date: Wed, 8 Jan 2025 23:17:40 -0800
Subject: [PATCH 1/4] ntdll: Mark call_init_thunk "used".

It's only referenced by inline asm, so this prevents the linker
from discarding the symbol if (e.g.) LTO is used.
---
 dlls/ntdll/unix/signal_arm.c    | 4 ++--
 dlls/ntdll/unix/signal_arm64.c  | 4 ++--
 dlls/ntdll/unix/signal_i386.c   | 4 ++--
 dlls/ntdll/unix/signal_x86_64.c | 4 ++--
 4 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/dlls/ntdll/unix/signal_arm.c b/dlls/ntdll/unix/signal_arm.c
index c9ae492597d..12389fa8f00 100644
--- a/dlls/ntdll/unix/signal_arm.c
+++ b/dlls/ntdll/unix/signal_arm.c
@@ -1121,8 +1121,8 @@ void signal_init_process(void)
 /***********************************************************************
  *           call_init_thunk
  */
-void call_init_thunk( LPTHREAD_START_ROUTINE entry, void *arg, BOOL suspend, TEB *teb,
-                      struct syscall_frame *frame, void *syscall_cfa )
+void __attribute__((used)) call_init_thunk( LPTHREAD_START_ROUTINE entry, void *arg, BOOL suspend, TEB *teb,
+                                            struct syscall_frame *frame, void *syscall_cfa )
 {
     struct arm_thread_data *thread_data = (struct arm_thread_data *)&teb->GdiTebBatch;
     CONTEXT *ctx, context = { CONTEXT_ALL };
diff --git a/dlls/ntdll/unix/signal_arm64.c b/dlls/ntdll/unix/signal_arm64.c
index 57d9c375076..6d3efaed31c 100644
--- a/dlls/ntdll/unix/signal_arm64.c
+++ b/dlls/ntdll/unix/signal_arm64.c
@@ -1447,8 +1447,8 @@ void syscall_dispatcher_return_slowpath(void)
 /***********************************************************************
  *           call_init_thunk
  */
-void call_init_thunk( LPTHREAD_START_ROUTINE entry, void *arg, BOOL suspend, TEB *teb,
-                      struct syscall_frame *frame, void *syscall_cfa )
+void __attribute__((used)) call_init_thunk( LPTHREAD_START_ROUTINE entry, void *arg, BOOL suspend, TEB *teb,
+                                            struct syscall_frame *frame, void *syscall_cfa )
 {
     struct arm64_thread_data *thread_data = (struct arm64_thread_data *)&teb->GdiTebBatch;
     CONTEXT *ctx, context = { CONTEXT_ALL };
diff --git a/dlls/ntdll/unix/signal_i386.c b/dlls/ntdll/unix/signal_i386.c
index 8ae7afc769e..058a6a50d0e 100644
--- a/dlls/ntdll/unix/signal_i386.c
+++ b/dlls/ntdll/unix/signal_i386.c
@@ -2496,8 +2496,8 @@ void signal_init_process(void)
 /***********************************************************************
  *           call_init_thunk
  */
-void call_init_thunk( LPTHREAD_START_ROUTINE entry, void *arg, BOOL suspend, TEB *teb,
-                      struct syscall_frame *frame, void *syscall_cfa )
+void __attribute__((used)) call_init_thunk( LPTHREAD_START_ROUTINE entry, void *arg, BOOL suspend, TEB *teb,
+                                            struct syscall_frame *frame, void *syscall_cfa )
 {
     struct x86_thread_data *thread_data = (struct x86_thread_data *)&teb->GdiTebBatch;
     CONTEXT *ctx, context = { CONTEXT_ALL };
diff --git a/dlls/ntdll/unix/signal_x86_64.c b/dlls/ntdll/unix/signal_x86_64.c
index caa85249896..0e293430879 100644
--- a/dlls/ntdll/unix/signal_x86_64.c
+++ b/dlls/ntdll/unix/signal_x86_64.c
@@ -2575,8 +2575,8 @@ void signal_init_process(void)
 /***********************************************************************
  *           call_init_thunk
  */
-void call_init_thunk( LPTHREAD_START_ROUTINE entry, void *arg, BOOL suspend, TEB *teb,
-                      struct syscall_frame *frame, void *syscall_cfa )
+void __attribute__((used)) call_init_thunk( LPTHREAD_START_ROUTINE entry, void *arg, BOOL suspend, TEB *teb,
+                                            struct syscall_frame *frame, void *syscall_cfa )
 {
     struct amd64_thread_data *thread_data = (struct amd64_thread_data *)&teb->GdiTebBatch;
     CONTEXT *ctx, context = { 0 };
-- 
2.47.1

From f654c112519fe0375c40df9442c2cbe9a3ec5240 Mon Sep 17 00:00:00 2001
From: William Horvath <william@horvath.blog>
Date: Wed, 8 Jan 2025 23:26:41 -0800
Subject: [PATCH 2/4] loader: Mark thread_ldt, thread_data, wld_start "used".

They're only referenced by inline asm, so this prevents the linker
from discarding the symbol if (e.g.) LTO is used.
---
 loader/preloader.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/loader/preloader.c b/loader/preloader.c
index d0551bae63a..3df0884d611 100644
--- a/loader/preloader.c
+++ b/loader/preloader.c
@@ -181,6 +181,7 @@ void __bb_init_func(void) { return; }
 
 static int thread_data[256];
 
+__attribute__((used))
 struct
 {
     /* this is the kernel modify_ldt struct */
@@ -333,7 +334,7 @@ static inline int wld_prctl( int code, long arg )
 
 #elif defined(__x86_64__)
 
-void *thread_data[256];
+void __attribute__((used)) *thread_data[256];
 
 /*
  * The _start function is the entry and exit point of this program
@@ -422,7 +423,7 @@ SYSCALL_NOERR( wld_getegid, 108 /* SYS_getegid */ );
 
 #elif defined(__aarch64__)
 
-void *thread_data[256];
+void __attribute__((used)) *thread_data[256];
 
 /*
  * The _start function is the entry and exit point of this program
@@ -529,7 +530,7 @@ SYSCALL_NOERR( wld_getegid, 177 /* SYS_getegid */ );
 
 #elif defined(__arm__)
 
-void *thread_data[256];
+void __attribute__((used)) *thread_data[256];
 
 /*
  * The _start function is the entry and exit point of this program
@@ -1395,7 +1396,7 @@ static void set_process_name( int argc, char *argv[] )
  *  Load the binary and then its ELF interpreter.
  *  Note, we assume that the binary is a dynamically linked ELF shared object.
  */
-void* wld_start( void **stack )
+void* __attribute__((used)) wld_start( void **stack )
 {
     long i, *pargc;
     char **argv, **p;
-- 
2.47.1

From e7a411e0739b101f737a31e3908691efa49c8874 Mon Sep 17 00:00:00 2001
From: William Horvath <william@horvath.blog>
Date: Thu, 14 Nov 2024 02:29:41 -0800
Subject: [PATCH 3/4] clang: add lto visibility fixup

---
 loader/preloader.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/loader/preloader.c b/loader/preloader.c
index 6dbd1cbd743..161f4348964 100644
--- a/loader/preloader.c
+++ b/loader/preloader.c
@@ -94,7 +94,9 @@
 #include "wine/asm.h"
 #include "main.h"
 
+#if !defined(__LLD_LTO__)
 #pragma GCC visibility push(hidden)
+#endif
 
 /* ELF definitions */
 #define ELF_PREFERRED_ADDRESS(loader, maplength, mapstartpref) (mapstartpref)
@@ -2817,6 +2819,8 @@ void* wld_start( void **stack )
     return (void *)ld_so_map.l_entry;
 }
 
+#if !defined(__LLD_LTO__)
 #pragma GCC visibility pop
+#endif
 
 #endif /* __linux__ */
-- 
2.47.0

From ba270452e93b535342cea706cbb904d6758919b6 Mon Sep 17 00:00:00 2001
From: Stelios Tsampas <loathingkernel@gmail.com>
Date: Thu, 21 Nov 2024 00:59:01 +0200
Subject: [PATCH 4/4] makedep: add per-source cflags and per-program ldflags
 variables

Co-authored-by: William Horvath <william@horvath.blog>
---
 tools/makedep.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/tools/makedep.c b/tools/makedep.c
index c1937363c39..2980c26d01a 100644
--- a/tools/makedep.c
+++ b/tools/makedep.c
@@ -470,6 +470,19 @@ static const char *get_base_name( const char *name )
     return base;
 }
 
+/*******************************************************************
+ *         replace_char
+ */
+char* replace_char(char* str, char find, char replace)
+{
+    char *current_pos;
+    current_pos = strchr(str, find);
+    while (current_pos) {
+        *current_pos = replace;
+        current_pos = strchr(current_pos + 1, find);
+    };
+    return str;
+}
 
 /*******************************************************************
  *         replace_filename
@@ -3199,6 +3212,7 @@ static void output_source_one_arch( struct makefile *make, struct incl_file *sou
                                     unsigned int arch )
 {
     const char *obj_name, *var_cc, *var_cflags;
+    char obj2[256] = {0};
     struct compile_command *cmd;
     struct strarray cflags = empty_strarray;
 
@@ -3271,6 +3285,11 @@ static void output_source_one_arch( struct makefile *make, struct incl_file *sou
     output_filenames( defines );
     output_filenames( cflags );
     output_filename( var_cflags );
+    strncpy( obj2, obj, sizeof( obj2 ) );
+    obj2[ sizeof( obj2 ) - 1] = '\0';
+    replace_char( obj2, '-', '_' );
+    replace_char( obj2, '.', '_' );
+    output_filename( arch_make_variable( strmake( "%s_CFLAGS", basename( obj2 ) ), arch ));
     output( "\n" );
 
     if (make->testdll && strendswith( source->name, ".c" ) &&
@@ -3708,6 +3727,7 @@ static void output_programs( struct makefile *make )
 {
     unsigned int i, j;
     unsigned int arch = 0;  /* programs are always native */
+    char program2[256] = {0};
 
     for (i = 0; i < make->programs.count; i++)
     {
@@ -3733,6 +3753,10 @@ static void output_programs( struct makefile *make )
         output_filenames_obj_dir( make, objs );
         output_filenames( all_libs );
         output_filename( "$(LDFLAGS)" );
+        strncpy( program2, program, sizeof( program2 ) );
+        program2[ sizeof( program2 ) - 1] = '\0';
+        replace_char( program2, '-', '_' );
+        output_filename( arch_make_variable( strmake( "%s_LDFLAGS", basename( program2 ) ), arch ));
         output( "\n" );
         strarray_add( &make->all_targets[arch], program );
 
-- 
2.47.0