Skip to content

Commit 54d47c0

Browse files
committed
Add options -fpic and -shared
`-fpic` is not implemented yet and just ignored (with an "unsupported" warning). `-shared` is passed to the GNU linker.
1 parent a3f52d4 commit 54d47c0

File tree

8 files changed

+31
-7
lines changed

8 files changed

+31
-7
lines changed

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,8 @@ compcert.ini: Makefile.config
330330
echo "has_runtime_lib=$(HAS_RUNTIME_LIB)"; \
331331
echo "has_standard_headers=$(HAS_STANDARD_HEADERS)"; \
332332
echo "asm_supports_cfi=$(ASM_SUPPORTS_CFI)"; \
333-
echo "response_file_style=$(RESPONSEFILE)";) \
333+
echo "response_file_style=$(RESPONSEFILE)"; \
334+
echo "pic_supported=$(PIC_SUPPORTED)") \
334335
> compcert.ini
335336

336337
compcert.config: Makefile.config

configure

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ cprepro_options="-E"
234234
archiver="${toolprefix}ar rcs"
235235
libmath="-lm"
236236
responsefile="gnu"
237+
pic_supported=false
237238

238239
#
239240
# ARM Target Configuration
@@ -426,8 +427,7 @@ if test "$arch" = "aarch64"; then
426427
cprepro="${toolprefix}cc"
427428
cprepro_options="-arch arm64 -U__GNUC__ -U__clang__ -U__BLOCKS__ '-D__attribute__(x)=' '-D__asm(x)=' '-D_Nullable=' '-D_Nonnull=' '-D__DARWIN_OS_INLINE=static inline' -Wno-\\#warnings -E"
428429
libmath=""
429-
system="macos"
430-
;;
430+
system="macos";;
431431
*)
432432
echo "Error: invalid eabi/system '$target' for architecture AArch64." 1>&2
433433
echo "$usage" 1>&2
@@ -697,6 +697,7 @@ HAS_STANDARD_HEADERS=$has_standard_headers
697697
INSTALL_COQDEV=$install_coqdev
698698
LIBMATH=$libmath
699699
MODEL=$model
700+
PIC_SUPPORTED=$pic_supported
700701
SYSTEM=$system
701702
RESPONSEFILE=$responsefile
702703
LIBRARY_FLOCQ=$library_Flocq
@@ -760,6 +761,10 @@ ENDIANNESS=
760761
# SYSTEM=cygwin
761762
SYSTEM=
762763
764+
# Are we able to produce position-independent code (with the `-fpic` option)?
765+
#PIC_SUPPORTED=true
766+
PIC_SUPPORTED=false
767+
763768
# C compiler (for testing only)
764769
CC=cc
765770
@@ -858,6 +863,7 @@ CompCert configuration:
858863
Hardware model................ $model
859864
Application binary interface.. $abi
860865
Endianness.................... $endianness
866+
PIC generation supported...... $pic_supported
861867
OS and development env........ $system
862868
C compiler.................... $cc $cc_options
863869
C preprocessor................ $cprepro $cprepro_options

driver/Clflags.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ let option_funprototyped = ref true
2222
let option_fpacked_structs = ref false
2323
let option_funstructured_switch = ref false
2424
let option_ffpu = ref true
25+
let option_fpic = ref false
2526
let option_ffloatconstprop = ref 2
2627
let option_ftailcalls = ref true
2728
let option_fconstprop = ref true

driver/Configuration.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ let stdlib_path =
142142
else
143143
""
144144
let asm_supports_cfi = get_bool_config "asm_supports_cfi"
145+
let pic_supported = get_bool_config "pic_supported"
145146

146147
type response_file_style =
147148
| Gnu (* responsefiles in gnu compatible syntax *)

driver/Configuration.mli

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,6 @@ val gnu_toolchain: bool
5959

6060
val elf_target: bool
6161
(** Is the target binary format ELF? *)
62+
63+
val pic_supported: bool
64+
(** Are we able to generate PIC code? *)

driver/Driver.ml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ Processing options:
200200
single caller [on]
201201
-fif-conversion Perform if-conversion (generation of conditional moves) [on]
202202
Code generation options: (use -fno-<opt> to turn off -f<opt>)
203+
-fpic / -fPIC Generate position-independent code [off]
203204
-ffpu Use FP registers for some integer operations [on]
204205
-fsmall-data <n> Set maximal size <n> for allocation in small data area
205206
-fsmall-const <n> Set maximal size <n> for allocation in small constant area
@@ -266,6 +267,11 @@ let cmdline_actions =
266267
if n <= 0 || ((n land (n - 1)) <> 0) then
267268
error no_loc "requested alignment %d is not a power of 2" n
268269
in
270+
let set_pic_mode () =
271+
if Configuration.pic_supported
272+
then option_fpic := true
273+
else warning no_loc Unnamed
274+
"option -fpic not supported on this platform, ignored" in
269275
[
270276
(* Getting help *)
271277
Exact "-help", Unit print_usage_and_exit;
@@ -301,7 +307,11 @@ let cmdline_actions =
301307
Exact "-ffloat-const-prop", Integer(fun n -> option_ffloatconstprop := n);
302308
Exact "-falign-functions", Integer(fun n -> check_align n; option_falignfunctions := Some n);
303309
Exact "-falign-branch-targets", Integer(fun n -> check_align n; option_falignbranchtargets := n);
304-
Exact "-falign-cond-branches", Integer(fun n -> check_align n; option_faligncondbranchs := n);] @
310+
Exact "-falign-cond-branches", Integer(fun n -> check_align n; option_faligncondbranchs := n);
311+
Exact "-fpic", Unit set_pic_mode;
312+
Exact "-fPIC", Unit set_pic_mode;
313+
Exact "-fno-pic", Unset option_fpic;
314+
Exact "-fno-PIC", Unset option_fpic ] @
305315
f_opt "common" option_fcommon @
306316
(* Target processor options *)
307317
(if Configuration.arch = "arm" then

driver/Linker.ml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ let linker exe_name files =
3535

3636

3737
let gnu_linker_help =
38-
{| -nodefaultlibs Do not use the standard system libraries when
38+
{| -shared Produce a shared library instead of an executable
39+
-nodefaultlibs Do not use the standard system libraries when
3940
linking
4041
-nostdlib Do not use the standard system startup files or
4142
libraries when linking
@@ -71,7 +72,8 @@ let linker_actions =
7172
] @
7273
(if Configuration.gnu_toolchain then
7374
[ Exact "-nodefaultlibs", Self push_linker_arg;
74-
Exact "-nostdlib", Self push_linker_arg;]
75+
Exact "-nostdlib", Self push_linker_arg;
76+
Exact "-shared", Self push_linker_arg]
7577
else []) @
7678
[ Exact "-s", Self push_linker_arg;
7779
Exact "-static", Self push_linker_arg;

test

0 commit comments

Comments
 (0)