Skip to content

Commit 147aeec

Browse files
x
Signed-off-by: Jonathan Brouwer <[email protected]>
1 parent 3014e79 commit 147aeec

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1024
-987
lines changed

Cargo.lock

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3323,6 +3323,7 @@ dependencies = [
33233323
"rustc_macros",
33243324
"rustc_session",
33253325
"rustc_span",
3326+
"rustc_target",
33263327
"thin-vec",
33273328
]
33283329

@@ -3880,6 +3881,7 @@ dependencies = [
38803881
"rustc_ast_lowering",
38813882
"rustc_ast_passes",
38823883
"rustc_ast_pretty",
3884+
"rustc_attr_data_structures",
38833885
"rustc_attr_parsing",
38843886
"rustc_borrowck",
38853887
"rustc_builtin_macros",
@@ -4431,6 +4433,7 @@ dependencies = [
44314433
"rand 0.9.1",
44324434
"rustc_abi",
44334435
"rustc_ast",
4436+
"rustc_attr_data_structures",
44344437
"rustc_data_structures",
44354438
"rustc_errors",
44364439
"rustc_feature",

compiler/rustc_attr_data_structures/src/attributes.rs

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,120 @@ pub enum CfgEntry {
165165
Version(Option<RustcVersion>, Span),
166166
}
167167

168+
/// Different ways that the PE Format can decorate a symbol name.
169+
/// From <https://docs.microsoft.com/en-us/windows/win32/debug/pe-format#import-name-type>
170+
#[derive(
171+
Copy,
172+
Clone,
173+
Debug,
174+
Encodable,
175+
Decodable,
176+
HashStable_Generic,
177+
PartialEq,
178+
Eq,
179+
PrintAttribute
180+
)]
181+
pub enum PeImportNameType {
182+
/// IMPORT_ORDINAL
183+
/// Uses the ordinal (i.e., a number) rather than the name.
184+
Ordinal(u16),
185+
/// Same as IMPORT_NAME
186+
/// Name is decorated with all prefixes and suffixes.
187+
Decorated,
188+
/// Same as IMPORT_NAME_NOPREFIX
189+
/// Prefix (e.g., the leading `_` or `@`) is skipped, but suffix is kept.
190+
NoPrefix,
191+
/// Same as IMPORT_NAME_UNDECORATE
192+
/// Prefix (e.g., the leading `_` or `@`) and suffix (the first `@` and all
193+
/// trailing characters) are skipped.
194+
Undecorated,
195+
}
196+
197+
#[derive(
198+
Copy,
199+
Clone,
200+
Debug,
201+
PartialEq,
202+
Eq,
203+
PartialOrd,
204+
Ord,
205+
Hash,
206+
Encodable,
207+
Decodable,
208+
PrintAttribute
209+
)]
210+
#[derive(HashStable_Generic)]
211+
pub enum NativeLibKind {
212+
/// Static library (e.g. `libfoo.a` on Linux or `foo.lib` on Windows/MSVC)
213+
Static {
214+
/// Whether to bundle objects from static library into produced rlib
215+
bundle: Option<bool>,
216+
/// Whether to link static library without throwing any object files away
217+
whole_archive: Option<bool>,
218+
},
219+
/// Dynamic library (e.g. `libfoo.so` on Linux)
220+
/// or an import library corresponding to a dynamic library (e.g. `foo.lib` on Windows/MSVC).
221+
Dylib {
222+
/// Whether the dynamic library will be linked only if it satisfies some undefined symbols
223+
as_needed: Option<bool>,
224+
},
225+
/// Dynamic library (e.g. `foo.dll` on Windows) without a corresponding import library.
226+
/// On Linux, it refers to a generated shared library stub.
227+
RawDylib,
228+
/// A macOS-specific kind of dynamic libraries.
229+
Framework {
230+
/// Whether the framework will be linked only if it satisfies some undefined symbols
231+
as_needed: Option<bool>,
232+
},
233+
/// Argument which is passed to linker, relative order with libraries and other arguments
234+
/// is preserved
235+
LinkArg,
236+
237+
/// Module imported from WebAssembly
238+
WasmImportModule,
239+
240+
/// The library kind wasn't specified, `Dylib` is currently used as a default.
241+
Unspecified,
242+
}
243+
244+
impl NativeLibKind {
245+
pub fn has_modifiers(&self) -> bool {
246+
match self {
247+
NativeLibKind::Static { bundle, whole_archive } => {
248+
bundle.is_some() || whole_archive.is_some()
249+
}
250+
NativeLibKind::Dylib { as_needed } | NativeLibKind::Framework { as_needed } => {
251+
as_needed.is_some()
252+
}
253+
NativeLibKind::RawDylib
254+
| NativeLibKind::Unspecified
255+
| NativeLibKind::LinkArg
256+
| NativeLibKind::WasmImportModule => false,
257+
}
258+
}
259+
260+
pub fn is_statically_included(&self) -> bool {
261+
matches!(self, NativeLibKind::Static { .. })
262+
}
263+
264+
pub fn is_dllimport(&self) -> bool {
265+
matches!(
266+
self,
267+
NativeLibKind::Dylib { .. } | NativeLibKind::RawDylib | NativeLibKind::Unspecified
268+
)
269+
}
270+
}
271+
272+
#[derive(Debug, Encodable, Decodable, Clone, HashStable_Generic, PrintAttribute)]
273+
pub struct LinkEntry {
274+
pub span: Span,
275+
pub kind: NativeLibKind,
276+
pub name: Symbol,
277+
pub cfg: Option<CfgEntry>,
278+
pub verbatim: Option<bool>,
279+
pub import_name_type: Option<(PeImportNameType, Span)>,
280+
}
281+
168282
/// Represents parsed *built-in* inert attributes.
169283
///
170284
/// ## Overview
@@ -319,6 +433,9 @@ pub enum AttributeKind {
319433
/// Represents `#[inline]` and `#[rustc_force_inline]`.
320434
Inline(InlineAttr, Span),
321435

436+
/// Represents `#[link]`.
437+
Link(ThinVec<LinkEntry>, Span),
438+
322439
/// Represents `#[link_name]`.
323440
LinkName { name: Symbol, span: Span },
324441

compiler/rustc_attr_data_structures/src/encode_cross_crate.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ impl AttributeKind {
4040
Fundamental { .. } => Yes,
4141
Ignore { .. } => No,
4242
Inline(..) => No,
43+
Link(..) => No,
4344
LinkName { .. } => Yes,
4445
LinkOrdinal { .. } => No,
4546
LinkSection { .. } => No,

compiler/rustc_attr_parsing/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@ rustc_lexer = { path = "../rustc_lexer" }
1717
rustc_macros = { path = "../rustc_macros" }
1818
rustc_session = { path = "../rustc_session" }
1919
rustc_span = { path = "../rustc_span" }
20+
rustc_target = { path = "../rustc_target" }
2021
thin-vec = "0.2.12"
2122
# tidy-alphabetical-end

compiler/rustc_attr_parsing/messages.ftl

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,3 +158,56 @@ attr_parsing_unused_multiple =
158158
159159
-attr_parsing_previously_accepted =
160160
this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
161+
162+
163+
attr_parsing_as_needed_compatibility =
164+
linking modifier `as-needed` is only compatible with `dylib` and `framework` linking kinds
165+
166+
attr_parsing_bundle_needs_static =
167+
linking modifier `bundle` is only compatible with `static` linking kind
168+
169+
attr_parsing_empty_link_name =
170+
link name must not be empty
171+
.label = empty link name
172+
173+
attr_parsing_import_name_type_raw =
174+
import name type can only be used with link kind `raw-dylib`
175+
176+
attr_parsing_import_name_type_x86 =
177+
import name type is only supported on x86
178+
179+
attr_parsing_incompatible_wasm_link =
180+
`wasm_import_module` is incompatible with other arguments in `#[link]` attributes
181+
182+
attr_parsing_invalid_link_modifier =
183+
invalid linking modifier syntax, expected '+' or '-' prefix before one of: bundle, verbatim, whole-archive, as-needed
184+
185+
attr_parsing_link_arg_unstable =
186+
link kind `link-arg` is unstable
187+
188+
attr_parsing_link_cfg_unstable =
189+
link cfg is unstable
190+
191+
attr_parsing_link_framework_apple =
192+
link kind `framework` is only supported on Apple targets
193+
194+
attr_parsing_link_requires_name =
195+
`#[link]` attribute requires a `name = "string"` argument
196+
.label = missing `name` argument
197+
198+
attr_parsing_multiple_modifiers =
199+
multiple `{$modifier}` modifiers in a single `modifiers` argument
200+
201+
attr_parsing_multiple_renamings =
202+
multiple renamings were specified for library `{$lib_name}`
203+
attr_parsing_raw_dylib_no_nul =
204+
link name must not contain NUL characters if link kind is `raw-dylib`
205+
206+
attr_parsing_raw_dylib_elf_unstable =
207+
link kind `raw-dylib` is unstable on ELF platforms
208+
209+
attr_parsing_raw_dylib_only_windows =
210+
link kind `raw-dylib` is only supported on Windows targets
211+
212+
attr_parsing_whole_archive_needs_static =
213+
linking modifier `whole-archive` is only compatible with `static` linking kind

compiler/rustc_attr_parsing/src/attributes/cfg.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub fn parse_cfg_attr<'c, S: Stage>(
3232
parse_cfg_entry(cx, single)
3333
}
3434

35-
fn parse_cfg_entry<S: Stage>(
35+
pub(crate) fn parse_cfg_entry<S: Stage>(
3636
cx: &mut AcceptContext<'_, '_, S>,
3737
item: &MetaItemOrLitParser<'_>,
3838
) -> Option<CfgEntry> {

0 commit comments

Comments
 (0)