@@ -15,7 +15,6 @@ class NativeLinker
15
15
{
16
16
static readonly List < string > standardArgs = new ( ) {
17
17
"--shared" ,
18
- "--allow-shlib-undefined" ,
19
18
// TODO: need to enable zstd in binutils build
20
19
// "--compress-debug-sections=zstd",
21
20
// TODO: test the commented-out flags
@@ -42,8 +41,12 @@ class NativeLinker
42
41
readonly CancellationToken ? cancellationToken ;
43
42
readonly Action ? cancelTask ;
44
43
45
- public bool StripDebugSymbols { get ; set ; }
46
- public bool SaveDebugSymbols { get ; set ; }
44
+ public bool StripDebugSymbols { get ; set ; } = true ;
45
+ public bool SaveDebugSymbols { get ; set ; } = true ;
46
+ public bool AllowUndefinedSymbols { get ; set ; } = false ;
47
+ public bool UseNdkLibraries { get ; set ; } = false ;
48
+ public string ? NdkRootPath { get ; set ; }
49
+ public string ? NdkApiLevel { get ; set ; }
47
50
48
51
public NativeLinker ( TaskLoggingHelper log , string abi , string soname , string binutilsDir , string intermediateDir ,
49
52
IEnumerable < ITaskItem > runtimePackLibDirs , CancellationToken ? cancellationToken = null , Action ? cancelTask = null )
@@ -96,6 +99,16 @@ public NativeLinker (TaskLoggingHelper log, string abi, string soname, string bi
96
99
public bool Link ( ITaskItem outputLibraryPath , List < ITaskItem > objectFiles , List < ITaskItem > archives , List < ITaskItem > libraries ,
97
100
List < ITaskItem > linkStartFiles , List < ITaskItem > linkEndFiles , ICollection < ITaskItem > ? exportDynamicSymbols = null )
98
101
{
102
+ if ( UseNdkLibraries ) {
103
+ if ( String . IsNullOrEmpty ( NdkRootPath ) ) {
104
+ throw new InvalidOperationException ( "Internal error: request to use NDK libraries, but NDK root not specified." ) ;
105
+ }
106
+
107
+ if ( String . IsNullOrEmpty ( NdkApiLevel ) ) {
108
+ throw new InvalidOperationException ( "Internal error: request to use NDK libraries, but NDK API level not specified." ) ;
109
+ }
110
+ }
111
+
99
112
log . LogDebugMessage ( $ "Linking: { outputLibraryPath } ") ;
100
113
EnsureCorrectAbi ( outputLibraryPath ) ;
101
114
EnsureCorrectAbi ( objectFiles ) ;
@@ -113,6 +126,17 @@ public bool Link (ITaskItem outputLibraryPath, List<ITaskItem> objectFiles, List
113
126
sw . WriteLine ( arg ) ;
114
127
}
115
128
129
+ if ( AllowUndefinedSymbols ) {
130
+ sw . WriteLine ( "--allow-shlib-undefined" ) ;
131
+ } else {
132
+ sw . WriteLine ( "--no-undefined" ) ;
133
+ }
134
+
135
+ // This MUST go before extra args, since the NDK library path must take precedence over the path in extra args set in the ctor
136
+ if ( UseNdkLibraries ) {
137
+ sw . WriteLine ( $ "-L { MonoAndroidHelper . QuoteFileNameArgument ( GetAbiNdkRootDir ( ) ) } ") ;
138
+ }
139
+
116
140
foreach ( string arg in extraArgs ) {
117
141
sw . WriteLine ( arg ) ;
118
142
}
@@ -160,8 +184,7 @@ public bool Link (ITaskItem outputLibraryPath, List<ITaskItem> objectFiles, List
160
184
return ret ;
161
185
}
162
186
163
- ret = ExtractDebugSymbols ( outputLibraryPath ) ;
164
- return ret ;
187
+ return ExtractDebugSymbols ( outputLibraryPath ) ;
165
188
166
189
void WriteFilesToResponseFile ( StreamWriter sw , List < ITaskItem > files )
167
190
{
@@ -202,6 +225,15 @@ bool ParseBooleanMetadata (ITaskItem item, string metadata)
202
225
}
203
226
}
204
227
228
+ string GetAbiNdkRootDir ( )
229
+ {
230
+ // Let it throw if invalid
231
+ int apiLevel = Int32 . Parse ( NdkApiLevel ) ;
232
+ NdkTools ndk = NdkTools . Create ( NdkRootPath , logErrors : true , log : log ) ;
233
+
234
+ return ndk . GetDirectoryPath ( NdkToolchainDir . PlatformLib , MonoAndroidHelper . AbiToTargetArch ( abi ) , apiLevel ) ;
235
+ }
236
+
205
237
void EnsureCorrectAbi ( ITaskItem item )
206
238
{
207
239
// The exception is just a precaution, since the items passed to us should have already been checked
@@ -243,6 +275,7 @@ bool ExtractDebugSymbols (ITaskItem outputSharedLibrary)
243
275
244
276
stdoutLines . Clear ( ) ;
245
277
stderrLines . Clear ( ) ;
278
+
246
279
args . Clear ( ) ;
247
280
args . Add ( "--strip-debug" ) ;
248
281
args . Add ( "--strip-unneeded" ) ;
0 commit comments