Skip to content

Commit 39bface

Browse files
authored
Merge pull request #1550 from N1ark/weak-linkage
Handle `#[linkage]` statics
2 parents 43b517e + 0ffb7b8 commit 39bface

26 files changed

Lines changed: 343 additions & 38 deletions

‎charon-ml/src/CharonVersion.ml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
(* This is an automatically generated file, generated from `charon/Cargo.toml`. *)
22
(* To re-generate this file, rune `make` in the root directory *)
3-
let supported_charon_version = "0.1.295"
3+
let supported_charon_version = "0.1.296"

‎charon-ml/src/PrintFmt.ml‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,7 @@ and pp_constant_expr (env : fmt_env) (fmt : Format.formatter)
590590
Format.fprintf fmt "[%a]" (pp_sep_list ", " (pp_constant_expr env)) fields
591591
| CGlobal gref -> pp_global_decl_ref env fmt gref
592592
| CPtrNoProvenance n -> Format.fprintf fmt "no-provenance %s" (Z.to_string n)
593+
| CExternSymbol name -> Format.fprintf fmt "&raw const <extern:%s>" name
593594
| CRef (c, meta) ->
594595
Format.fprintf fmt "&%a" (pp_global_place env) c;
595596
Option.iter
@@ -1291,6 +1292,20 @@ let pp_rustc_attribute_kind (fmt : Format.formatter)
12911292
| RustcInlineAttrForce _ -> pp_string fmt "rustc_force_inline")
12921293
| RustcAttributeKindLinkSection name ->
12931294
Format.fprintf fmt "link_section = \"%s\"" name
1295+
| RustcAttributeKindLinkage (linkage, _) ->
1296+
let linkage =
1297+
match linkage with
1298+
| RustcLinkageAvailableExternally -> "available_externally"
1299+
| RustcLinkageCommon -> "common"
1300+
| RustcLinkageExternalWeak -> "extern_weak"
1301+
| RustcLinkageExternal -> "external"
1302+
| RustcLinkageInternal -> "internal"
1303+
| RustcLinkageLinkOnceAny -> "linkonce"
1304+
| RustcLinkageLinkOnceODR -> "linkonce_odr"
1305+
| RustcLinkageWeakAny -> "weak"
1306+
| RustcLinkageWeakODR -> "weak_odr"
1307+
in
1308+
Format.fprintf fmt "linkage = \"%s\"" linkage
12941309
| RustcAttributeKindMayDangle _ -> pp_string fmt "may_dangle"
12951310
| RustcAttributeKindNaked _ -> pp_string fmt "naked"
12961311
| RustcAttributeKindNoLink -> pp_string fmt "no_link"

‎charon-ml/src/generated/Generated_Meta.ml‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,8 @@ and rustc_attribute_kind =
218218
219219
Fields:
220220
- [name] *)
221+
| RustcAttributeKindLinkage of rustc_linkage * span
222+
(** Represents [#[linkage]]. *)
221223
| RustcAttributeKindMayDangle of span
222224
(** Represents
223225
[[#[may_dangle]]](https://std-dev-guide.rust-lang.org/tricky/may-dangle.html).
@@ -333,6 +335,22 @@ and item_id =
333335
| IdFun of fun_decl_id
334336
| IdGlobal of global_decl_id
335337

338+
(** Possible values for the [#[linkage]] attribute, allowing to specify the
339+
linkage type for a [MonoItem].
340+
341+
See <https://llvm.org/docs/LangRef.html#linkage-types> for more details
342+
about these variants. *)
343+
and rustc_linkage =
344+
| RustcLinkageAvailableExternally
345+
| RustcLinkageCommon
346+
| RustcLinkageExternalWeak
347+
| RustcLinkageExternal
348+
| RustcLinkageInternal
349+
| RustcLinkageLinkOnceAny
350+
| RustcLinkageLinkOnceODR
351+
| RustcLinkageWeakAny
352+
| RustcLinkageWeakODR
353+
336354
and loc = {
337355
line : int; (** The (1-based) line number. *)
338356
col : int; (** The (0-based) column offset. *)

‎charon-ml/src/generated/Generated_OfJson.ml‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,9 @@ and constant_expr_kind_of_json (ctx : of_json_ctx) (js : json) :
672672
| `Assoc [ ("PtrNoProvenance", _0) ] ->
673673
let* _0 = big_int_of_json ctx _0 in
674674
Ok (CPtrNoProvenance _0)
675+
| `Assoc [ ("ExternSymbol", _0) ] ->
676+
let* _0 = string_of_json ctx _0 in
677+
Ok (CExternSymbol _0)
675678
| `Assoc [ ("TypeId", _0) ] ->
676679
let* _0 = ty_of_json ctx _0 in
677680
Ok (CTypeId _0)
@@ -2408,6 +2411,10 @@ and rustc_attribute_kind_of_json (ctx : of_json_ctx) (js : json) :
24082411
| `Assoc [ ("LinkSection", `Assoc [ ("name", name) ]) ] ->
24092412
let* name = string_of_json ctx name in
24102413
Ok (RustcAttributeKindLinkSection name)
2414+
| `Assoc [ ("Linkage", `List [ _0; _1 ]) ] ->
2415+
let* _0 = rustc_linkage_of_json ctx _0 in
2416+
let* _1 = span_of_json ctx _1 in
2417+
Ok (RustcAttributeKindLinkage (_0, _1))
24112418
| `Assoc [ ("MayDangle", _0) ] ->
24122419
let* _0 = span_of_json ctx _0 in
24132420
Ok (RustcAttributeKindMayDangle _0)
@@ -3658,6 +3665,21 @@ and layout_of_json (ctx : of_json_ctx) (js : json) : (layout, string) result =
36583665
: layout)
36593666
| _ -> Error "")
36603667

3668+
and rustc_linkage_of_json (ctx : of_json_ctx) (js : json) :
3669+
(rustc_linkage, string) result =
3670+
combine_error_msgs js __FUNCTION__
3671+
(match js with
3672+
| `String "AvailableExternally" -> Ok RustcLinkageAvailableExternally
3673+
| `String "Common" -> Ok RustcLinkageCommon
3674+
| `String "ExternalWeak" -> Ok RustcLinkageExternalWeak
3675+
| `String "External" -> Ok RustcLinkageExternal
3676+
| `String "Internal" -> Ok RustcLinkageInternal
3677+
| `String "LinkOnceAny" -> Ok RustcLinkageLinkOnceAny
3678+
| `String "LinkOnceODR" -> Ok RustcLinkageLinkOnceODR
3679+
| `String "WeakAny" -> Ok RustcLinkageWeakAny
3680+
| `String "WeakODR" -> Ok RustcLinkageWeakODR
3681+
| _ -> Error "")
3682+
36613683
and local_of_json (ctx : of_json_ctx) (js : json) : (local, string) result =
36623684
combine_error_msgs js __FUNCTION__
36633685
(match js with

‎charon-ml/src/generated/Generated_OfPostcard.ml‎

Lines changed: 44 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -605,46 +605,49 @@ and constant_expr_kind_of_postcard (ctx : of_postcard_ctx) (st : postcard_state)
605605
let* _0 = big_uint_of_postcard ctx st in
606606
Ok (CPtrNoProvenance _0)
607607
| 14 ->
608+
let* _0 = string_of_postcard ctx st in
609+
Ok (CExternSymbol _0)
610+
| 15 ->
608611
let* _0 = ty_of_postcard ctx st in
609612
Ok (CTypeId _0)
610-
| 15 ->
613+
| 16 ->
611614
let* _0 = list_of_postcard byte_of_postcard ctx st in
612615
Ok (CRawMemory _0)
613-
| 16 ->
616+
| 17 ->
614617
let* _0 =
615618
de_bruijn_var_of_postcard const_generic_var_id_of_postcard ctx st
616619
in
617620
Ok (CVar _0)
618-
| 17 ->
621+
| 18 ->
619622
let* _0 = global_decl_ref_of_postcard ctx st in
620623
Ok (CGlobal _0)
621-
| 18 ->
624+
| 19 ->
622625
let* _0 = fn_ptr_of_postcard ctx st in
623626
let* _1 = list_of_postcard constant_expr_of_postcard ctx st in
624627
Ok (CCall (_0, _1))
625-
| 19 ->
628+
| 20 ->
626629
let* _0 = trait_ref_of_postcard ctx st in
627630
let* _1 = assoc_const_id_of_postcard ctx st in
628631
Ok (CTraitConst (_0, _1))
629-
| 20 ->
632+
| 21 ->
630633
let* _0 = poly_trait_ref_of_postcard ctx st in
631634
Ok (CVTableRef _0)
632-
| 21 ->
635+
| 22 ->
633636
let* _0 = type_decl_ref_of_postcard ctx st in
634637
let* _1 = variant_id_of_postcard ctx st in
635638
Ok (CDiscriminant (_0, _1))
636-
| 22 ->
639+
| 23 ->
637640
let* _0 = ty_of_postcard ctx st in
638641
Ok (CSizeOf _0)
639-
| 23 ->
642+
| 24 ->
640643
let* _0 = ty_of_postcard ctx st in
641644
Ok (CAlignOf _0)
642-
| 24 ->
645+
| 25 ->
643646
let* _0 = type_decl_ref_of_postcard ctx st in
644647
let* _1 = option_of_postcard variant_id_of_postcard ctx st in
645648
let* _2 = field_id_of_postcard ctx st in
646649
Ok (COffsetOf (_0, _1, _2))
647-
| 25 ->
650+
| 26 ->
648651
let* _0 = string_of_postcard ctx st in
649652
Ok (COpaque _0)
650653
| _ -> Error ("unknown enum variant tag: " ^ string_of_int __tag))
@@ -2033,31 +2036,35 @@ and rustc_attribute_kind_of_postcard (ctx : of_postcard_ctx)
20332036
let* name = string_of_postcard ctx st in
20342037
Ok (RustcAttributeKindLinkSection name)
20352038
| 8 ->
2039+
let* _0 = rustc_linkage_of_postcard ctx st in
2040+
let* _1 = span_of_postcard ctx st in
2041+
Ok (RustcAttributeKindLinkage (_0, _1))
2042+
| 9 ->
20362043
let* _0 = span_of_postcard ctx st in
20372044
Ok (RustcAttributeKindMayDangle _0)
2038-
| 9 ->
2045+
| 10 ->
20392046
let* _0 = span_of_postcard ctx st in
20402047
Ok (RustcAttributeKindNaked _0)
2041-
| 10 -> Ok RustcAttributeKindNoLink
2042-
| 11 ->
2048+
| 11 -> Ok RustcAttributeKindNoLink
2049+
| 12 ->
20432050
let* _0 = span_of_postcard ctx st in
20442051
Ok (RustcAttributeKindNoMangle _0)
2045-
| 12 ->
2052+
| 13 ->
20462053
let* _0 = span_of_postcard ctx st in
20472054
Ok (RustcAttributeKindNonExhaustive _0)
2048-
| 13 ->
2055+
| 14 ->
20492056
let* _0 = rustc_optimize_attr_of_postcard ctx st in
20502057
let* _1 = span_of_postcard ctx st in
20512058
Ok (RustcAttributeKindOptimize (_0, _1))
2052-
| 14 ->
2059+
| 15 ->
20532060
let* align = u64_of_postcard ctx st in
20542061
let* span = span_of_postcard ctx st in
20552062
Ok (RustcAttributeKindRustcAlign (align, span))
2056-
| 15 -> Ok RustcAttributeKindRustcIntrinsic
2057-
| 16 ->
2063+
| 16 -> Ok RustcAttributeKindRustcIntrinsic
2064+
| 17 ->
20582065
let* reason = option_of_postcard string_of_postcard ctx st in
20592066
Ok (RustcAttributeKindShouldPanic reason)
2060-
| 17 ->
2067+
| 18 ->
20612068
let* features =
20622069
list_of_postcard
20632070
(pair_of_postcard string_of_postcard span_of_postcard)
@@ -2066,7 +2073,7 @@ and rustc_attribute_kind_of_postcard (ctx : of_postcard_ctx)
20662073
let* attr_span = span_of_postcard ctx st in
20672074
let* was_forced = bool_of_postcard ctx st in
20682075
Ok (RustcAttributeKindTargetFeature (features, attr_span, was_forced))
2069-
| 18 ->
2076+
| 19 ->
20702077
let* _0 = span_of_postcard ctx st in
20712078
Ok (RustcAttributeKindTrackCaller _0)
20722079
| _ -> Error ("unknown enum variant tag: " ^ string_of_int __tag))
@@ -3035,6 +3042,22 @@ and layout_of_postcard (ctx : of_postcard_ctx) (st : postcard_state) :
30353042
({ size; align; discriminator; inhabited; variant_layouts; repr }
30363043
: layout))
30373044

3045+
and rustc_linkage_of_postcard (ctx : of_postcard_ctx) (st : postcard_state) :
3046+
(rustc_linkage, string) result =
3047+
combine_error_msgs st __FUNCTION__
3048+
(let* __tag = int_of_postcard ctx st in
3049+
match __tag with
3050+
| 0 -> Ok RustcLinkageAvailableExternally
3051+
| 1 -> Ok RustcLinkageCommon
3052+
| 2 -> Ok RustcLinkageExternalWeak
3053+
| 3 -> Ok RustcLinkageExternal
3054+
| 4 -> Ok RustcLinkageInternal
3055+
| 5 -> Ok RustcLinkageLinkOnceAny
3056+
| 6 -> Ok RustcLinkageLinkOnceODR
3057+
| 7 -> Ok RustcLinkageWeakAny
3058+
| 8 -> Ok RustcLinkageWeakODR
3059+
| _ -> Error ("unknown enum variant tag: " ^ string_of_int __tag))
3060+
30383061
and local_of_postcard (ctx : of_postcard_ctx) (st : postcard_state) :
30393062
(local, string) result =
30403063
combine_error_msgs st __FUNCTION__

‎charon-ml/src/generated/Generated_Types.ml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,9 @@ and constant_expr_kind =
390390
(** A pointer with no provenance (e.g. 0 for the null pointer)
391391
392392
This is eliminated inside functions if [--raw-consts] is off. *)
393+
| CExternSymbol of string
394+
(** The address of a linker symbol, as a [*const ()]. The address may be
395+
null, if the symbol wasn't defined at link time. *)
393396
| CTypeId of ty (** The [TypeId] value for a type. *)
394397
| CRawMemory of byte list
395398
(** Raw memory value obtained from constant evaluation. Used when a more

‎charon/Cargo.lock‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎charon/Cargo.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ tracing = { version = "0.1", features = ["max_level_trace"] }
2727

2828
[package]
2929
name = "charon"
30-
version = "0.1.295"
30+
version = "0.1.296"
3131
authors.workspace = true
3232
edition.workspace = true
3333
license.workspace = true

‎charon/src/ast/bodies/values.rs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ pub enum ConstantExprKind {
6161
///
6262
/// This is eliminated inside functions if `--raw-consts` is off.
6363
PtrNoProvenance(#[serde(with = "scalar_value_ser_de")] u128),
64+
/// The address of a linker symbol, as a `*const ()`. The address may be null, if the
65+
/// symbol wasn't defined at link time.
66+
ExternSymbol(String),
6467
/// The `TypeId` value for a type.
6568
TypeId(Ty),
6669
/// Raw memory value obtained from constant evaluation. Used when a more structured

‎charon/src/ast/from_rustc.rs‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ pub enum AttributeKind {
100100
Inline(InlineAttr, Span),
101101
/// Represents [`#[link_section]`](https://doc.rust-lang.org/reference/abi.html#the-link_section-attribute)
102102
LinkSection { name: Ustr },
103+
/// Represents `#[linkage]`.
104+
Linkage(Linkage, Span),
103105
/// Represents [`#[may_dangle]`](https://std-dev-guide.rust-lang.org/tricky/may-dangle.html).
104106
MayDangle(Span),
105107
/// Represents `#[naked]`
@@ -816,6 +818,26 @@ pub enum InlineAttr {
816818
},
817819
}
818820

821+
/// Possible values for the `#[linkage]` attribute, allowing to specify the
822+
/// linkage type for a `MonoItem`.
823+
///
824+
/// See <https://llvm.org/docs/LangRef.html#linkage-types> for more details about these variants.
825+
#[derive(Debug, Clone, PartialEq, Eq)]
826+
#[derive(Serialize, Deserialize, Drive, DriveMut, DriveTwo)]
827+
#[cfg_attr(feature = "charon_on_charon", charon::rename("RustcLinkage"))]
828+
#[cfg_attr(feature = "charon_on_charon", charon::variants_prefix("RustcLinkage"))]
829+
pub enum Linkage {
830+
AvailableExternally,
831+
Common,
832+
ExternalWeak,
833+
External,
834+
Internal,
835+
LinkOnceAny,
836+
LinkOnceODR,
837+
WeakAny,
838+
WeakODR,
839+
}
840+
819841
#[derive(Debug, Clone, PartialEq, Eq)]
820842
#[derive(Serialize, Deserialize, Drive, DriveMut, DriveTwo)]
821843
#[cfg_attr(feature = "charon_on_charon", charon::rename("RustcOptimizeAttr"))]

0 commit comments

Comments
 (0)