@@ -828,7 +828,27 @@ impl<'a> Linker for GccLinker<'a> {
828
828
self . sess . dcx ( ) . emit_fatal ( errors:: LibDefWriteFailure { error } ) ;
829
829
}
830
830
self . link_arg ( path) ;
831
- } else if crate_type == CrateType :: Executable && !self . sess . target . is_like_solaris {
831
+ } else if self . sess . target . is_like_solaris {
832
+ // Write a Solaris LD mapfile
833
+ // Documented at https://docs.oracle.com/cd/E53394_01/html/E54813/gjpky.html#OSLLGman-scsvd
834
+ let res: io:: Result < ( ) > = try {
835
+ let mut f = File :: create_buffered ( & path) ?;
836
+ writeln ! ( f, "$mapfile_version 2" ) ?;
837
+ writeln ! ( f, "SYMBOL_SCOPE {{" ) ?;
838
+ if !symbols. is_empty ( ) {
839
+ writeln ! ( f, " global:" ) ?;
840
+ for ( sym, _) in symbols {
841
+ debug ! ( " {sym};" ) ;
842
+ writeln ! ( f, " {sym};" ) ?;
843
+ }
844
+ }
845
+ writeln ! ( f, "\n local:\n *;\n }};" ) ?;
846
+ } ;
847
+ if let Err ( error) = res {
848
+ self . sess . dcx ( ) . emit_fatal ( errors:: VersionScriptWriteFailure { error } ) ;
849
+ }
850
+ self . link_arg ( "-M" ) . link_arg ( path) ;
851
+ } else if crate_type == CrateType :: Executable {
832
852
let res: io:: Result < ( ) > = try {
833
853
let mut f = File :: create_buffered ( & path) ?;
834
854
writeln ! ( f, "{{" ) ?;
@@ -859,13 +879,9 @@ impl<'a> Linker for GccLinker<'a> {
859
879
if let Err ( error) = res {
860
880
self . sess . dcx ( ) . emit_fatal ( errors:: VersionScriptWriteFailure { error } ) ;
861
881
}
862
- if self . sess . target . is_like_solaris {
863
- self . link_arg ( "-M" ) . link_arg ( path) ;
864
- } else {
865
- let mut arg = OsString :: from ( "--version-script=" ) ;
866
- arg. push ( path) ;
867
- self . link_arg ( arg) . link_arg ( "--no-undefined-version" ) ;
868
- }
882
+ let mut arg = OsString :: from ( "--version-script=" ) ;
883
+ arg. push ( path) ;
884
+ self . link_arg ( arg) . link_arg ( "--no-undefined-version" ) ;
869
885
}
870
886
}
871
887
0 commit comments