Skip to content

Commit

Permalink
Add -native-pic {false,true} option
Browse files Browse the repository at this point in the history
Can be used to override a platform-determined default.

See MLton#191
  • Loading branch information
MatthewFluet committed Jan 21, 2020
1 parent 234bc62 commit 57427ba
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 13 deletions.
4 changes: 2 additions & 2 deletions mlton/codegen/amd64-codegen/amd64-allocate-registers.fun
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(* Copyright (C) 1999-2010 Matthew Fluet.
(* Copyright (C) 2010,2020 Matthew Fluet.
* Copyright (C) 1999-2007 Henry Cejtin, Matthew Fluet, Suresh
* Jagannathan, and Stephen Weeks.
* Copyright (C) 1997-2000 NEC Research Institute.
Expand Down Expand Up @@ -3824,7 +3824,7 @@ struct
assembly = AppendList.empty,
registerAllocation = registerAllocation}
| (_, NONE, SOME memIndex) (* label + index => use lea if PIC *)
=> if !Control.positionIndependent = false
=> if not (!Control.Native.pic)
then {disp = SOME disp,
register = NONE,
assembly = AppendList.empty,
Expand Down
2 changes: 1 addition & 1 deletion mlton/codegen/amd64-codegen/amd64-generate-transfers.fun
Original file line number Diff line number Diff line change
Expand Up @@ -1550,7 +1550,7 @@ struct
in
case (symbolScope,
!Control.Target.os,
!Control.positionIndependent) of
!Control.Native.pic) of
(* Private functions can be easily reached
* with a direct (rip-relative) call.
*)
Expand Down
2 changes: 1 addition & 1 deletion mlton/codegen/amd64-codegen/amd64-translate.fun
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ struct
in
case (symbolScope,
!Control.Target.os,
!Control.positionIndependent) of
!Control.Native.pic) of
(* As long as the symbol is private (this means it is not
* exported to code outside this text segment), then
* RIP-relative addressing works on every OS/format.
Expand Down
4 changes: 2 additions & 2 deletions mlton/codegen/x86-codegen/x86-allocate-registers.fun
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(* Copyright (C) 2010 Matthew Fluet.
(* Copyright (C) 2010,2020 Matthew Fluet.
* Copyright (C) 1999-2007 Henry Cejtin, Matthew Fluet, Suresh
* Jagannathan, and Stephen Weeks.
* Copyright (C) 1997-2000 NEC Research Institute.
Expand Down Expand Up @@ -38,7 +38,7 @@ struct
fun mungeLabelDarwin l =
Label.fromString (Label.toString l ^ "-MLtonLocalBaseSymbol")
in
case (!Control.Target.os, !Control.positionIndependent) of
case (!Control.Target.os, !Control.Native.pic) of
(* Only darwin and ELF might be using PIC *)
(Darwin, true) => (mungeLabelDarwin, SOME Register.esp)
| (_, true) => (mungeLabelELF, SOME Register.ebx)
Expand Down
2 changes: 1 addition & 1 deletion mlton/codegen/x86-codegen/x86-generate-transfers.fun
Original file line number Diff line number Diff line change
Expand Up @@ -1393,7 +1393,7 @@ struct
in
case (symbolScope,
!Control.Target.os,
!Control.positionIndependent) of
!Control.Native.pic) of
(* Private functions can be easily reached
* with a direct (eip-relative) call.
*)
Expand Down
2 changes: 1 addition & 1 deletion mlton/codegen/x86-codegen/x86-translate.fun
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ struct
in
case (symbolScope,
!Control.Target.os,
!Control.positionIndependent) of
!Control.Native.pic) of
(* Even private PIC symbols on darwin need indirection. *)
(Private, Darwin, true) => indirect ()
(* As long as the symbol is private (thus it is not
Expand Down
5 changes: 3 additions & 2 deletions mlton/control/control-flags.sig
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,9 @@ signature CONTROL_FLAGS =

(* whether or not to split assembly file in native codegen *)
val split: int option ref

(* whether or not to use position-independent code in native codegen *)
val pic: bool ref
end

val numExports: int ref
Expand All @@ -379,8 +382,6 @@ signature CONTROL_FLAGS =
val setAll: string -> unit Result.t
end

val positionIndependent : bool ref

(* Only duplicate big functions when
* (size - small) * (number of occurrences - 1) <= product
*)
Expand Down
6 changes: 4 additions & 2 deletions mlton/control/control-flags.sml
Original file line number Diff line number Diff line change
Expand Up @@ -1269,6 +1269,10 @@ structure Native =
val split = control {name = "native split",
default = SOME 20000,
toString = Option.toString Int.toString}

val pic = control {name = "native pic",
default = false,
toString = Bool.toString}
end

val numExports: int ref = ref 0
Expand Down Expand Up @@ -1344,8 +1348,6 @@ val polyvariance =
("product", Int.layout product)])
p)}

val positionIndependent = ref false

val preferAbsPaths = control {name = "prefer abs paths",
default = false,
toString = Bool.toString}
Expand Down
9 changes: 8 additions & 1 deletion mlton/main/main.fun
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ val explicitAlign: Control.align option ref = ref NONE
val explicitChunkify: Control.Chunkify.t option ref = ref NONE
datatype explicitCodegen = Native | Explicit of Control.Codegen.t
val explicitCodegen: explicitCodegen option ref = ref NONE
val explicitNativePIC: bool option ref = ref NONE
val keepGenerated = ref false
val keepO = ref false
val output: string option ref = ref NONE
Expand Down Expand Up @@ -650,6 +651,8 @@ fun makeOptions {usage} =
boolRef Native.moveHoist),
(Expert, "native-optimize", " <n>", "level of optimizations",
intRef Native.optimize),
(Expert, "native-pic", " {false|true}", "generate position-independent code",
Bool (fn b => explicitNativePIC := SOME b)),
(Expert, "native-split", " <n>", "split assembly files at ~n lines",
Int (fn i => Native.split := SOME i)),
(Expert, "native-shuffle", " {true|false}",
Expand Down Expand Up @@ -1009,7 +1012,11 @@ fun commandLine (args: string list): unit =
| (_, _, Library) => true
| (_, _, LibArchive) => true
| _ => false
val () = Control.positionIndependent := positionIndependent

val () =
Native.pic := (case !explicitNativePIC of
NONE => positionIndependent
| SOME b => b)

val stop = !stop

Expand Down

0 comments on commit 57427ba

Please sign in to comment.