Skip to content

Commit 47c45bb

Browse files
Fix
Signed-off-by: Jonathan Brouwer <[email protected]>
1 parent 5ca574e commit 47c45bb

File tree

20 files changed

+1013
-382
lines changed

20 files changed

+1013
-382
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3368,6 +3368,7 @@ dependencies = [
33683368
"rustc_macros",
33693369
"rustc_session",
33703370
"rustc_span",
3371+
"rustc_target",
33713372
"thin-vec",
33723373
]
33733374

@@ -4443,6 +4444,7 @@ dependencies = [
44434444
"rand 0.9.1",
44444445
"rustc_abi",
44454446
"rustc_ast",
4447+
"rustc_attr_data_structures",
44464448
"rustc_data_structures",
44474449
"rustc_errors",
44484450
"rustc_feature",

compiler/rustc_attr_data_structures/src/attributes.rs

Lines changed: 95 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use rustc_macros::{Decodable, Encodable, HashStable_Generic, PrintAttribute};
55
use rustc_span::hygiene::Transparency;
66
use rustc_span::{Span, Symbol};
77
use thin_vec::ThinVec;
8-
98
use crate::{DefaultBodyStability, PartialConstStability, PrintAttribute, RustcVersion, Stability};
109

1110
#[derive(Copy, Clone, PartialEq, Encodable, Decodable, Debug, HashStable_Generic, PrintAttribute)]
@@ -142,6 +141,98 @@ pub enum UsedBy {
142141
Linker,
143142
}
144143

144+
/// Different ways that the PE Format can decorate a symbol name.
145+
/// From <https://docs.microsoft.com/en-us/windows/win32/debug/pe-format#import-name-type>
146+
#[derive(Copy, Clone, Debug, Encodable, Decodable, HashStable_Generic, PartialEq, Eq, PrintAttribute)]
147+
pub enum PeImportNameType {
148+
/// IMPORT_ORDINAL
149+
/// Uses the ordinal (i.e., a number) rather than the name.
150+
Ordinal(u16),
151+
/// Same as IMPORT_NAME
152+
/// Name is decorated with all prefixes and suffixes.
153+
Decorated,
154+
/// Same as IMPORT_NAME_NOPREFIX
155+
/// Prefix (e.g., the leading `_` or `@`) is skipped, but suffix is kept.
156+
NoPrefix,
157+
/// Same as IMPORT_NAME_UNDECORATE
158+
/// Prefix (e.g., the leading `_` or `@`) and suffix (the first `@` and all
159+
/// trailing characters) are skipped.
160+
Undecorated,
161+
}
162+
163+
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Encodable, Decodable, PrintAttribute)]
164+
#[derive(HashStable_Generic)]
165+
pub enum NativeLibKind {
166+
/// Static library (e.g. `libfoo.a` on Linux or `foo.lib` on Windows/MSVC)
167+
Static {
168+
/// Whether to bundle objects from static library into produced rlib
169+
bundle: Option<bool>,
170+
/// Whether to link static library without throwing any object files away
171+
whole_archive: Option<bool>,
172+
},
173+
/// Dynamic library (e.g. `libfoo.so` on Linux)
174+
/// or an import library corresponding to a dynamic library (e.g. `foo.lib` on Windows/MSVC).
175+
Dylib {
176+
/// Whether the dynamic library will be linked only if it satisfies some undefined symbols
177+
as_needed: Option<bool>,
178+
},
179+
/// Dynamic library (e.g. `foo.dll` on Windows) without a corresponding import library.
180+
/// On Linux, it refers to a generated shared library stub.
181+
RawDylib,
182+
/// A macOS-specific kind of dynamic libraries.
183+
Framework {
184+
/// Whether the framework will be linked only if it satisfies some undefined symbols
185+
as_needed: Option<bool>,
186+
},
187+
/// Argument which is passed to linker, relative order with libraries and other arguments
188+
/// is preserved
189+
LinkArg,
190+
191+
/// Module imported from WebAssembly
192+
WasmImportModule,
193+
194+
/// The library kind wasn't specified, `Dylib` is currently used as a default.
195+
Unspecified,
196+
}
197+
198+
impl NativeLibKind {
199+
pub fn has_modifiers(&self) -> bool {
200+
match self {
201+
NativeLibKind::Static { bundle, whole_archive } => {
202+
bundle.is_some() || whole_archive.is_some()
203+
}
204+
NativeLibKind::Dylib { as_needed } | NativeLibKind::Framework { as_needed } => {
205+
as_needed.is_some()
206+
}
207+
NativeLibKind::RawDylib
208+
| NativeLibKind::Unspecified
209+
| NativeLibKind::LinkArg
210+
| NativeLibKind::WasmImportModule => false,
211+
}
212+
}
213+
214+
pub fn is_statically_included(&self) -> bool {
215+
matches!(self, NativeLibKind::Static { .. })
216+
}
217+
218+
pub fn is_dllimport(&self) -> bool {
219+
matches!(
220+
self,
221+
NativeLibKind::Dylib { .. } | NativeLibKind::RawDylib | NativeLibKind::Unspecified
222+
)
223+
}
224+
}
225+
226+
#[derive(Copy, Debug, Encodable, Decodable, Clone, HashStable_Generic, PrintAttribute)]
227+
pub struct LinkEntry {
228+
pub span: Span,
229+
pub kind: NativeLibKind,
230+
pub name: Symbol,
231+
pub cfg: Option<()>, //TODO
232+
pub verbatim: Option<bool>,
233+
pub import_name_type: Option<(PeImportNameType, Span)>,
234+
}
235+
145236
/// Represents parsed *built-in* inert attributes.
146237
///
147238
/// ## Overview
@@ -256,6 +347,9 @@ pub enum AttributeKind {
256347
/// Represents `#[link_name]`.
257348
LinkName { name: Symbol, span: Span },
258349

350+
/// Represents `#[link]`.
351+
Link(ThinVec<LinkEntry>),
352+
259353
/// Represents `#[loop_match]`.
260354
LoopMatch(Span),
261355

compiler/rustc_attr_data_structures/src/encode_cross_crate.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ impl AttributeKind {
2929
Stability { .. } => Yes,
3030
Cold(..) => No,
3131
ConstContinue(..) => No,
32+
Link(..) => No,
3233
LinkName { .. } => Yes,
3334
LoopMatch(..) => No,
3435
MayDangle(..) => 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

0 commit comments

Comments
 (0)