Skip to content

Commit d43b4b5

Browse files
x
Signed-off-by: Jonathan Brouwer <[email protected]>
1 parent a9fb610 commit d43b4b5

Some content is hidden

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

44 files changed

+1253
-901
lines changed

Cargo.lock

Lines changed: 2 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

@@ -4431,6 +4432,7 @@ dependencies = [
44314432
"rand 0.9.1",
44324433
"rustc_abi",
44334434
"rustc_ast",
4435+
"rustc_attr_data_structures",
44344436
"rustc_data_structures",
44354437
"rustc_errors",
44364438
"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

0 commit comments

Comments
 (0)