Skip to content

Commit 41553af

Browse files
committed
x86 support for -fpic
1 parent 50df9b1 commit 41553af

File tree

10 files changed

+35
-15
lines changed

10 files changed

+35
-15
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,5 @@ jobs:
6666
run: tools/runner.sh test1
6767
- name: Test alternate configuration
6868
run: tools/runner.sh test2
69+
- name: Test alternate configuration 2
70+
run: tools/runner.sh test3

configure

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@ if test "$arch" = "x86" -a "$bitsize" = "64"; then
356356
cprepro="${toolprefix}cc"
357357
cprepro_options="-m64 -U__GNUC__ -U__SIZEOF_INT128__ -E"
358358
system="bsd"
359+
pic_supported=true
359360
;;
360361
linux)
361362
abi="standard"
@@ -364,6 +365,7 @@ if test "$arch" = "x86" -a "$bitsize" = "64"; then
364365
clinker_options="-m64"
365366
cprepro_options="-m64 -U__GNUC__ -U__SIZEOF_INT128__ -E"
366367
system="linux"
368+
pic_supported=true
367369
;;
368370
macos|macosx)
369371
abi="macos"
@@ -374,6 +376,7 @@ if test "$arch" = "x86" -a "$bitsize" = "64"; then
374376
cprepro_options="-arch x86_64 -U__GNUC__ -U__SIZEOF_INT128__ -U__clang__ -U__BLOCKS__ '-D__attribute__(x)=' '-D__asm(x)=' '-D_Nullable=' '-D_Nonnull=' '-D__DARWIN_OS_INLINE=static inline' -Wno-\\#warnings -E"
375377
libmath=""
376378
system="macos"
379+
pic_supported=true
377380
;;
378381
cygwin)
379382
abi="standard"

tools/runner.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,17 @@ case "$target,$os" in
205205
1) Run_test "$simu_rv64" "";;
206206
2) Run_test "$simu_rv64" "-Os";;
207207
esac;;
208-
x86_32,*|x86_64,*)
208+
x86_32,*)
209209
case "$1" in
210210
1) Run_test "" "";;
211211
2) Run_test "" "-Os";;
212212
esac;;
213+
x86_64,*)
214+
case "$1" in
215+
1) Run_test "" "";;
216+
2) Run_test "" "-fpic";;
217+
3) Run_test "" "-Os";;
218+
esac;;
213219
*)
214220
Fatal "Unknown configuration \"$target\" - \"$os\""
215221
esac

x86/ConstpropOp.vp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Definition const_for_result (a: aval) : option operation :=
3030
| F n => if Compopts.generate_float_constants tt then Some(Ofloatconst n) else None
3131
| FS n => if Compopts.generate_float_constants tt then Some(Osingleconst n) else None
3232
| Ptr(Gl id ofs) =>
33-
if SelectOp.symbol_is_external id then
33+
if SelectOp.symbol_is_relocatable id then
3434
if Ptrofs.eq ofs Ptrofs.zero then Some (Oindirectsymbol id) else None
3535
else
3636
Some (Olea_ptr (Aglobal id ofs))

x86/ConstpropOpproof.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ Proof.
109109
- (* pointer *)
110110
destruct p; try discriminate; SimplVM.
111111
+ (* global *)
112-
destruct (SelectOp.symbol_is_external id).
112+
destruct (SelectOp.symbol_is_relocatable id).
113113
* revert H2; predSpec Ptrofs.eq Ptrofs.eq_spec ofs Ptrofs.zero; intros EQ; inv EQ.
114114
exists (Genv.symbol_address ge id Ptrofs.zero); auto.
115115
* inv H2. exists (Genv.symbol_address ge id ofs); split.

x86/SelectOp.vp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,15 @@ Local Open Scope cminorsel_scope.
4848

4949
(** External oracle to determine whether a symbol should be addressed
5050
through [Oindirectsymbol] or can be addressed via [Oleal Aglobal].
51-
This is to accommodate MacOS X's limitations on references to data
52-
symbols imported from shared libraries. It can also help with PIC
53-
code under ELF. *)
51+
Indirect access is needed for data symbols imported from shared libraries
52+
in macOS and Cygwin, and for PIC code in ELF. *)
5453

55-
Parameter symbol_is_external: ident -> bool.
54+
Parameter symbol_is_relocatable: ident -> bool.
5655

5756
Definition Olea_ptr (a: addressing) := if Archi.ptr64 then Oleal a else Olea a.
5857

5958
Definition addrsymbol (id: ident) (ofs: ptrofs) :=
60-
if symbol_is_external id then
59+
if symbol_is_relocatable id then
6160
if Ptrofs.eq ofs Ptrofs.zero
6261
then Eop (Oindirectsymbol id) Enil
6362
else Eop (Olea_ptr (Aindexed (Ptrofs.unsigned ofs))) (Eop (Oindirectsymbol id) Enil ::: Enil)

x86/SelectOpproof.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ Theorem eval_addrsymbol:
117117
exists v, eval_expr ge sp e m le (addrsymbol id ofs) v /\ Val.lessdef (Genv.symbol_address ge id ofs) v.
118118
Proof.
119119
intros. unfold addrsymbol. exists (Genv.symbol_address ge id ofs); split; auto.
120-
destruct (symbol_is_external id).
120+
destruct (symbol_is_relocatable id).
121121
predSpec Ptrofs.eq Ptrofs.eq_spec ofs Ptrofs.zero.
122122
subst. EvalOp.
123123
EvalOp. econstructor. EvalOp. simpl; eauto. econstructor.

x86/TargetPrinter.ml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ module type SYSTEM =
107107
val raw_symbol: out_channel -> string -> unit
108108
val symbol: out_channel -> P.t -> unit
109109
val symbol_paren: out_channel -> P.t -> unit
110+
val symbol_function: out_channel -> P.t -> unit
110111
val label: out_channel -> int -> unit
111112
val name_of_section: section_name -> string
112113
val stack_alignment: int
@@ -137,6 +138,10 @@ module ELF_System : SYSTEM =
137138
then fprintf oc "(%s)" s
138139
else fprintf oc "%s" s
139140

141+
let symbol_function oc symb =
142+
symbol_paren oc symb;
143+
if !Clflags.option_fpic then fprintf oc "@PLT"
144+
140145
let label = elf_label
141146

142147
let name_of_section = function
@@ -206,6 +211,9 @@ module MacOS_System : SYSTEM =
206211
let symbol_paren = symbol
207212
(* the leading '_' protects the leading '$' *)
208213

214+
let symbol_function = symbol
215+
(* no need for @PLT even in PIC mode *)
216+
209217
let label oc lbl =
210218
fprintf oc "L%d" lbl
211219

@@ -278,6 +286,8 @@ module Cygwin_System : SYSTEM =
278286
then fprintf oc "(%a)" raw_symbol s
279287
else raw_symbol oc s
280288

289+
let symbol_function = symbol_paren
290+
281291
let label oc lbl =
282292
fprintf oc "L%d" lbl
283293

@@ -723,7 +733,7 @@ module Target(System: SYSTEM):TARGET =
723733
| Pjmp_l(l) ->
724734
fprintf oc " jmp %a\n" label (transl_label l)
725735
| Pjmp_s(f, sg) ->
726-
fprintf oc " jmp %a\n" symbol_paren f
736+
fprintf oc " jmp %a\n" symbol_function f
727737
| Pjmp_r(r, sg) ->
728738
fprintf oc " jmp *%a\n" ireg r
729739
| Pjcc(c, l) ->
@@ -749,7 +759,7 @@ module Target(System: SYSTEM):TARGET =
749759
fprintf oc " jmp *%a(, %a, 4)\n" label l ireg r
750760
end
751761
| Pcall_s(f, sg) ->
752-
fprintf oc " call %a\n" symbol_paren f;
762+
fprintf oc " call %a\n" symbol_function f;
753763
if (not Archi.ptr64) && sg.sig_cc.cc_structret then
754764
fprintf oc " pushl %%eax\n"
755765
| Pcall_r(r, sg) ->

x86/extractionMachdep.v

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ Extract Constant Archi.win64 =>
2727

2828
(* SelectOp *)
2929

30-
Extract Constant SelectOp.symbol_is_external =>
30+
Extract Constant SelectOp.symbol_is_relocatable =>
3131
"match Configuration.system with
3232
| ""macos"" -> C2C.atom_is_external
33-
| ""cygwin"" when Archi.ptr64 -> C2C.atom_is_external
34-
| _ -> (fun _ -> false)".
33+
| ""cygwin"" -> if Archi.ptr64 then C2C.atom_is_external else (fun _ -> false)
34+
| _ -> C2C.atom_needs_GOT_access".

0 commit comments

Comments
 (0)