Skip to content

Commit a30650b

Browse files
committed
Address review comments, round 1
1 parent d97434c commit a30650b

File tree

1 file changed

+27
-7
lines changed

1 file changed

+27
-7
lines changed

text/0000-native-link-modifiers.md

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,16 @@ but it could be changed later on some future edition boundary.
8383

8484
### `verbatim`
8585

86-
`+verbatim` means that `rustc` won't add any target-specified library prefixes or suffixes
87-
(like `lib` or `.a`) to the library name.
86+
`+verbatim` means that `rustc` itself won't add any target-specified library prefixes or suffixes
87+
(like `lib` or `.a`) to the library name,
88+
and will try its best to ask for the same thing from the linker.
8889

8990
For `ld`-like linkers `rustc` will use the `-l:filename` syntax (note the colon)
9091
when passing the library, so the linker won't add any prefixes or suffixes as well. \
9192
See [`-l namespec`](https://sourceware.org/binutils/docs/ld/Options.html) in `ld` documentation
92-
for more details.
93+
for more details. \
94+
For linkers not supporting any verbatim modifiers (e.g. `link.exe` or `ld64`)
95+
the library name will be passed as is.
9396

9497
The default for this modifier is `-verbatim`.
9598

@@ -107,23 +110,32 @@ Only compatible with the `static` linking kind.
107110
without throwing any object files away.
108111

109112
This modifier translates to `--whole-archive` for `ld`-like linkers,
110-
and to `/WHOLEARCHIVE` for `link.exe`.
113+
to `/WHOLEARCHIVE` for `link.exe`, and to `-force_load` for `ld64`. \
114+
The modifier does nothing for linkers that don't support it.
111115

112116
The default for this modifier is `-whole-archive`.
113117

118+
A motivating example for this modifier can be found in
119+
[issue #56306](https://github.com/rust-lang/rust/issues/56306).
120+
114121
### `as-needed`
115122

116-
Only compatible with the `dynamic` linking kind.
123+
Only compatible with the `dynamic` and `framework` linking kinds.
117124

118125
`+as-needed` means that the library will be actually linked only if it satisfies some
119126
undefined symbols at the point at which it is specified on the command line,
120127
making it similar to static libraries in this regard.
121128

122-
This modifier translates to `--as-needed` for `ld`-like linkers.
129+
This modifier translates to `--as-needed` for `ld`-like linkers,
130+
and to `-dead_strip_dylibs` / `-needed_library` / `-needed_framework` for `ld64`. \
131+
The modifier does nothing for linkers that don't support it (e.g. `link.exe`).
123132

124133
The default for this modifier is unclear, some targets currently specify it as `+as-needed`,
125134
some do not. We may want to try making `+as-needed` a default for all targets.
126135

136+
A motivating example for this modifier can be found in
137+
[issue #57837](https://github.com/rust-lang/rust/issues/57837).
138+
127139
## Stability story
128140

129141
The modifier syntax can be stabilized independently from any specific modifiers.
@@ -180,6 +192,14 @@ regarding this, see the `LINKER:` modifier for
180192
Relying on raw linker options while linking with attributes will requires introducing
181193
a new attribute, see the paragraph about `#[link(arg = "string")]` in "Future possibilities".
182194

195+
## Alternative: merge modifiers into kind in attributes
196+
197+
`#[link(kind = "static", modifiers = "+foo,-bar")]` -> `#[link(kind = "static:+foo,-bar")]`.
198+
199+
This make attributes closer to command line, but it's unclear whether it's a goal we want to pursue.
200+
For example, we already write `kind=name` on command line,
201+
but `kind = "...", name = "..."` in attributes.
202+
183203
# Prior art
184204
[prior-art]: #prior-art
185205

@@ -195,7 +215,7 @@ so it is not as relevant to modifying behavior of specific libraries as with `ld
195215
# Unresolved questions
196216
[unresolved-questions]: #unresolved-questions
197217

198-
What about the `framework` linking kind? What does it mean? What modifiers is it compatible with?
218+
None currently.
199219

200220
# Future possibilities
201221
[future-possibilities]: #future-possibilities

0 commit comments

Comments
 (0)