11use crate :: abi:: Endian ;
22use crate :: spec:: { Cc , cvs, LinkerFlavor , Lld , PanicStrategy , TargetOptions } ;
33
4- pub fn opts ( ) -> TargetOptions {
5- let linker_script = r"
4+ const V0_LINKER_SCRIPT : & str = r"
65PHDRS
76{
87 text PT_LOAD ;
@@ -28,10 +27,64 @@ SECTIONS
2827 }
2928}
3029" ;
30+
31+ const V3_LINKER_SCRIPT : & str = r"
32+ SECTIONS
33+ {
34+ .rodata 0x000000000 : SUBALIGN(8) {
35+ BYTE(0);
36+ *(.rodata*)
37+ *(.data.rel.ro*)
38+ . = ALIGN(8);
39+ } :rodata
40+ .text 0x100000000 : {
41+ *(.text*)
42+ } :text
43+ /DISCARD/ : {
44+ *(.comment*)
45+ *(.eh_frame*)
46+ *(*hash*)
47+ *(.bss*)
48+ *(.data*)
49+ *(.rel.dyn*)
50+ *(.dynamic)
51+ *(.dynsym)
52+ *(.dynstr)
53+ }
54+ }
55+
56+ PHDRS
57+ {
58+ rodata PT_LOAD FLAGS(4);
59+ text PT_LOAD FLAGS(1);
60+ other PT_NULL FLAGS(0);
61+ }
62+
63+ " ;
64+
65+ pub ( crate ) fn opts ( version : & ' static str ) -> TargetOptions {
66+ let mut linker_args = vec ! [ "--threads=1" , "notext" ] ;
67+ let linker_script = if version == "v3" || version == "v4" {
68+ V3_LINKER_SCRIPT
69+ } else {
70+ linker_args. push ( "-z" ) ;
71+ linker_args. push ( "max-page-size=4096" ) ;
72+ V0_LINKER_SCRIPT
73+ } ;
3174 let pre_link_args = TargetOptions :: link_args (
3275 LinkerFlavor :: Gnu ( Cc :: No , Lld :: No ) ,
33- & [ "--threads=1" , "-z" , "notext" ] ,
76+ & linker_args ,
3477 ) ;
78+ let cpu = if version == "v0" {
79+ "generic"
80+ } else {
81+ version
82+ } ;
83+ let features = match version {
84+ "v4" => "+solana,+static-syscalls,+abi-v2" ,
85+ "v3" => "+solana,+static-syscalls" ,
86+ _ => "+solana,"
87+ } ;
3588
3689 TargetOptions {
3790 allow_asm : true ,
@@ -44,7 +97,6 @@ SECTIONS
4497 endian : Endian :: Little ,
4598 env : "" . into ( ) ,
4699 executables : true ,
47- features : "+solana" . into ( ) ,
48100 families : cvs ! [ "solana" ] ,
49101 link_script : Some ( linker_script. into ( ) ) ,
50102 linker : Some ( "rust-lld" . into ( ) ) ,
@@ -61,6 +113,8 @@ SECTIONS
61113 singlethread : true ,
62114 vendor : "solana" . into ( ) ,
63115 c_enum_min_bits : Some ( 32 ) ,
116+ cpu : cpu. into ( ) ,
117+ features : features. into ( ) ,
64118 .. Default :: default ( )
65119 }
66120}
0 commit comments