@@ -114,31 +114,36 @@ public bool Link (ITaskItem outputLibraryPath, List<ITaskItem> objectFiles, List
114
114
115
115
string libBaseName = Path . GetFileNameWithoutExtension ( outputLibraryPath . ItemSpec ) ;
116
116
string respFilePath = Path . Combine ( intermediateDir , $ "ld.{ libBaseName } .{ abi } .rsp") ;
117
- using ( var sw = new StreamWriter ( File . Open ( respFilePath , FileMode . Create , FileAccess . Write , FileShare . Read ) , new UTF8Encoding ( false ) ) ) {
118
- foreach ( string arg in standardArgs ) {
119
- sw . WriteLine ( arg ) ;
120
- }
117
+ using var sw = new StreamWriter ( File . Open ( respFilePath , FileMode . Create , FileAccess . Write , FileShare . Read ) , new UTF8Encoding ( false ) ) ;
118
+ foreach ( string arg in standardArgs ) {
119
+ sw . WriteLine ( arg ) ;
120
+ }
121
121
122
- foreach ( string arg in extraArgs ) {
123
- sw . WriteLine ( arg ) ;
124
- }
122
+ foreach ( string arg in extraArgs ) {
123
+ sw . WriteLine ( arg ) ;
124
+ }
125
125
126
- if ( StripDebugSymbols && ! SaveDebugSymbols ) {
127
- sw . WriteLine ( "-s" ) ;
128
- }
126
+ if ( StripDebugSymbols && ! SaveDebugSymbols ) {
127
+ sw . WriteLine ( "-s" ) ;
128
+ }
129
129
130
- WriteFilesToResponseFile ( sw , linkStartFiles ) ;
131
- WriteFilesToResponseFile ( sw , objectFiles ) ;
132
- WriteFilesToResponseFile ( sw , archives ) ;
130
+ var excludeExportsLibs = new List < string > ( ) ;
131
+ WriteFilesToResponseFile ( sw , linkStartFiles ) ;
132
+ WriteFilesToResponseFile ( sw , objectFiles ) ;
133
+ WriteFilesToResponseFile ( sw , archives ) ;
133
134
134
- foreach ( ITaskItem libItem in libraries ) {
135
- sw . WriteLine ( $ "-l{ libItem . ItemSpec } ") ;
136
- }
135
+ if ( excludeExportsLibs . Count > 0 ) {
136
+ string libs = String . Join ( "," , excludeExportsLibs ) ;
137
+ sw . WriteLine ( $ "--exclude-libs={ libs } ") ;
138
+ }
137
139
138
- WriteFilesToResponseFile ( sw , linkEndFiles ) ;
139
- sw . Flush ( ) ;
140
+ foreach ( ITaskItem libItem in libraries ) {
141
+ sw . WriteLine ( $ "-l { libItem . ItemSpec } " ) ;
140
142
}
141
143
144
+ WriteFilesToResponseFile ( sw , linkEndFiles ) ;
145
+ sw . Flush ( ) ;
146
+
142
147
var ldArgs = new List < string > {
143
148
$ "@{ respFilePath } ",
144
149
"-o" ,
@@ -163,6 +168,10 @@ void WriteFilesToResponseFile (StreamWriter sw, List<ITaskItem> files)
163
168
foreach ( ITaskItem file in files ) {
164
169
bool wholeArchive = IncludeWholeArchive ( file ) ;
165
170
171
+ if ( ExcludeFromExports ( file ) ) {
172
+ excludeExportsLibs . Add ( Path . GetFileName ( file . ItemSpec ) ) ;
173
+ }
174
+
166
175
if ( wholeArchive ) {
167
176
sw . Write ( "--whole-archive " ) ;
168
177
}
@@ -178,15 +187,18 @@ void WriteFilesToResponseFile (StreamWriter sw, List<ITaskItem> files)
178
187
}
179
188
}
180
189
181
- bool IncludeWholeArchive ( ITaskItem item )
190
+ bool IncludeWholeArchive ( ITaskItem item ) => ParseBooleanMetadata ( item , KnownMetadata . NativeLinkWholeArchive ) ;
191
+ bool ExcludeFromExports ( ITaskItem item ) => ParseBooleanMetadata ( item , KnownMetadata . NativeDontExportSymbols ) ;
192
+
193
+ bool ParseBooleanMetadata ( ITaskItem item , string metadata )
182
194
{
183
- string ? wholeArchive = item . GetMetadata ( KnownMetadata . LinkWholeArchive ) ;
184
- if ( String . IsNullOrEmpty ( wholeArchive ) ) {
195
+ string ? value = item . GetMetadata ( metadata ) ;
196
+ if ( String . IsNullOrEmpty ( value ) ) {
185
197
return false ;
186
198
}
187
199
188
200
// Purposefully not calling TryParse, let it throw and let us know if the value isn't a boolean.
189
- return Boolean . Parse ( wholeArchive ) ;
201
+ return Boolean . Parse ( value ) ;
190
202
}
191
203
}
192
204
0 commit comments