Skip to content

Commit aaf7d53

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

File tree

20 files changed

+1053
-390
lines changed

20 files changed

+1053
-390
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: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,120 @@ pub enum UsedBy {
142142
Linker,
143143
}
144144

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

373+
/// Represents `#[link]`.
374+
Link(ThinVec<LinkEntry>),
375+
259376
/// Represents `#[loop_match]`.
260377
LoopMatch(Span),
261378

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)