You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Some additional description of the various formats and when/how they can be used.
Co-authored-by: Sven Boemer <[email protected]>
Commit migrated from dotnet/linker@7b82b56
Copy file name to clipboardExpand all lines: src/tools/illink/docs/data-formats.md
+64-13Lines changed: 64 additions & 13 deletions
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,21 @@ IL linker uses several data formats to control or influence the linking process.
4
4
5
5
## Descriptor Format
6
6
7
-
The `fullname` attribute specifies the fullname of the type in the format specified by ECMA-335. This is in certain cases not the same as the one reported by Type.FullName for example for nested types.
7
+
Descriptors are used to direct the linker to always keep some items in the assembly, regardless of if the linker can find any references to them.
8
+
9
+
Descriptor XML can be embedded in an assembly. In that case it must be stored as an embedded resource with logical name `ILLink.Descriptors.xml`. To achieve this when building an assembly use this in the project file to include the XML:
Embedded descriptors only take effect if the containing assembly is included in the linker output, so if something from that assembly is marked to be kept.
20
+
21
+
Descriptor XML can also be passed to the linker on the command via the [`-x` parameter](illink-options.md#linking-from-an-xml-descriptor).
8
22
9
23
### XML Examples
10
24
@@ -166,6 +180,24 @@ The `required` attribute specifies that if the type is not marked, during the ma
166
180
167
181
## Substitution Format
168
182
183
+
Substitutions direct the linker to replace specific method's body with either a throw or return constant statements.
184
+
185
+
Substitutions have effect only on assemblies which are linked with assembly action `link`, any other assembly will not be affected. That said it is possible to have a `copy` assembly with the substitution on a method in it, and then a separate `link` assembly which calls such method. The `link` assembly will see the constant value of the method after the substitution and potentially remove unused branches and such.
186
+
187
+
Substitutions XML can be embedded in an assembly by including it as an embedded resource with logical name `ILLink.Substitutions.xml`. To include an XML file in an assembly this way, use this in the project file:
Embedded substitutions only take effect if the containing assembly is included in the linker output. Embedded substitutions should only address methods from the containing assembly.
198
+
199
+
Substitutions XML can be specified on the command line via the [`--substitutions` parameter](illink-options.md#using-custom-substitutions). Using substitutions with `ipconstprop` optimization (enabled by default) can help reduce output size as any dependencies under conditional logic which will be evaluated as unreachable will be removed.
200
+
169
201
### Substitute method body with a constant
170
202
171
203
The `value` attribute is optional and only required when the method should be hardcoded to return a non-default value and the return type is not `void`.
@@ -256,6 +288,24 @@ Note that this will only have an effect where it is applied - the default value
256
288
257
289
## Custom Attributes Annotations Format
258
290
291
+
Attribute annotations direct the linker to behave as if the specified item has the specified attribute.
292
+
293
+
Attribute annotations can only be used to add attributes which have effect on linker behavior, all other attributes will be ignored. Attributes added via attribute annotations only influence linker behavior, they are never added to the output assembly.
294
+
295
+
Attribute annotation XML can be embedded in an assembly by including it as an embedded resource with logical name `ILLink.LinkAttributes.xml`. To include an XML file in an assembly this way, use this in the project file:
Embedded attribute annotations should only address methods from the containing assembly.
306
+
307
+
Attribute annotations XML can be specified on the command line via the [`--link-attributes` parameter](illink-options.md#supplementary-custom-attributes).
308
+
259
309
### Custom attribute on assembly
260
310
261
311
```xml
@@ -270,7 +320,7 @@ Note that this will only have an effect where it is applied - the default value
270
320
271
321
### Custom attribute on type
272
322
273
-
This allows to add a custom attribute to a class, interface, delegate, struct or enum
323
+
This allows to add a custom attribute to a class, interface, delegate, struct or enum.
274
324
275
325
```xml
276
326
<linker>
@@ -427,13 +477,13 @@ This allows to add a custom attribute to a class, interface, delegate, struct or
427
477
### Conditional custom attributes
428
478
429
479
The `feature` and `featurevalue` attributes are optional, but must be used together when used.
430
-
They can be applied to any element to specify conditions under which the contained custom
480
+
They can be applied to any element to specify conditions under which the contained custom
431
481
attributes are applied.
432
482
433
483
```xml
434
484
<linker>
435
485
<assemblyfullname="Assembly">
436
-
<!-- The substitution will apply only if "--feature EnableOptionalFeature false" are also used-->
486
+
<!-- The attribute will apply only if "EnableOptionalFeature" is set to "false"-->
Also if the attribute is used in a type, a special property can be used to specify that the type
478
-
is a Custom Attribute an it's instances should be removed by the linker. To do this the word "internal"
479
-
and value "RemoveAttributeInstances" should be included in the attribute as described in the following
529
+
is a Custom Attribute and it's instances should be removed by the linker. To do this use `internal="RemoveAttributeInstances"` instead of specifying `fullname` in the attribute as described in the following
480
530
example:
481
531
482
532
```xml
@@ -488,6 +538,7 @@ example:
488
538
</assembly>
489
539
</linker>
490
540
```
541
+
491
542
Notice that a descriptor file containing the custom attribute type overrides this behavior. In case the
492
-
custom attribute type is being referenced in a descriptor xml file and in the linkattributes xml file
493
-
for removal, the custom attribute will not be removed
543
+
custom attribute type is being referenced in a descriptor file and in the attribute annotations file
544
+
for removal, the custom attribute will not be removed.
0 commit comments