Skip to content

ocamlc -c and ocamlopt -c differ for C files #7678

@vicuna

Description

@vicuna

Original bug ID: 7678
Reporter: @dbuenzli
Status: acknowledged (set by @xavierleroy on 2017-11-26T16:21:45Z)
Resolution: open
Priority: normal
Severity: minor
OS: Linux
Version: 4.06.0
Target version: 4.07.0+dev/beta2/rc1/rc2
Category: compiler driver
Monitored by: @gasche @yallop @dra27 @dbuenzli

Bug description

I don't know if that is intended but it seems that -fPIC is not passed in the second case.

This makes ocamlmklib to fail to produce libraries for C object files generated with ocamlopt -c.

Steps to reproduce

Our C file

cat a.c
#include <stdlib.h>
char *get_editor (void) { return getenv("EDITOR"); }

Here all is well

ocamlc -verbose -c a.c

  • gcc -std=gnu99 -O2 -fno-strict-aliasing -fwrapv -fno-builtin-memcmp -fPIC -D_FILE_OFFSET_BITS=64 -D_REENTRANT -c -I'/home/dbuenzli/.opam/default/lib/ocaml' 'a.c'

ocamlmklib a.o

Here we fail note the missing -fPIC w.r.t above invocation

ocamlopt -verbose -c a.c

  • gcc -std=gnu99 -O2 -fno-strict-aliasing -fwrapv -fno-builtin-memcmp -D_FILE_OFFSET_BITS=64 -D_REENTRANT -c -I'/home/dbuenzli/.opam/default/lib/ocaml' 'a.c'

Additional information

cat /etc/system-release
CentOS Linux release 7.4.1708 (Core)

ocamlc -config
ocamlc -config
version: 4.06.0
standard_library_default: /home/dbuenzli/.opam/default/lib/ocaml
standard_library: /home/dbuenzli/.opam/default/lib/ocaml
standard_runtime: /home/dbuenzli/.opam/default/bin/ocamlrun
ccomp_type: cc
c_compiler: gcc
ocamlc_cflags: -std=gnu99 -O2 -fno-strict-aliasing -fwrapv -fno-builtin-memcmp -fPIC
ocamlc_cppflags: -D_FILE_OFFSET_BITS=64 -D_REENTRANT
ocamlopt_cflags: -std=gnu99 -O2 -fno-strict-aliasing -fwrapv -fno-builtin-memcmp
ocamlopt_cppflags: -D_FILE_OFFSET_BITS=64 -D_REENTRANT
bytecomp_c_compiler: gcc -std=gnu99 -O2 -fno-strict-aliasing -fwrapv -fno-builtin-memcmp -fPIC -D_FILE_OFFSET_BITS=64 -D_REENTRANT
native_c_compiler: gcc -std=gnu99 -O2 -fno-strict-aliasing -fwrapv -fno-builtin-memcmp -D_FILE_OFFSET_BITS=64 -D_REENTRANT
bytecomp_c_libraries: -lm -ldl -lcurses -lpthread
native_c_libraries: -lm -ldl
native_pack_linker: ld -r -o
ranlib: ranlib
cc_profile: -pg
architecture: amd64
model: default
int_size: 63
word_size: 64
system: linux
asm: as
asm_cfi_supported: true
with_frame_pointers: false
ext_exe:
ext_obj: .o
ext_asm: .s
ext_lib: .a
ext_dll: .so
os_type: Unix
default_executable_name: a.out
systhread_supported: true
host: x86_64-unknown-linux-gnu
target: x86_64-unknown-linux-gnu
profiling: true
flambda: false
spacetime: false
safe_string: false
default_safe_string: true
flat_float_array: true
afl_instrument: false
windows_unicode: false
exec_magic_number: Caml1999X011
cmi_magic_number: Caml1999I022
cmo_magic_number: Caml1999O022
cma_magic_number: Caml1999A022
cmx_magic_number: Caml1999Y022
cmxa_magic_number: Caml1999Z022
ast_impl_magic_number: Caml1999M022
ast_intf_magic_number: Caml1999N022
cmxs_magic_number: Caml1999D022
cmt_magic_number: Caml1999T022

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions