Skip to content

Commit 744dc27

Browse files
committed
Merge pull request #43 from AbsInt/standard-headers
Merge of the "standard-headers" branch. This provides CompCert-compatible implementations of the following standard headers: float.h, stdarg.h, stdbool.h, stddef.h, varargs.h. These are the headers that are provided by GCC, Clang, and TCC. Other standard headers are provided by Glibc and similar C standard libraries. So far in CompCert we rely on the headers provided by whatever C compiler is installed on the host platform. This causes some difficulties that this branch addresses: 1- Diab C's stdarg.h is not compatible with CompCert 2- On IA32 and PowerPC, CompCert's "long double" type differs from the "long double" type specified by the ABI. Hence, the platform's float.h gives "long double" parameters that do not match CompCert.
2 parents 584eac7 + 1cdf4f2 commit 744dc27

File tree

11 files changed

+339
-13
lines changed

11 files changed

+339
-13
lines changed

Makefile

+4-5
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ compcert.ini: Makefile.config VERSION
202202
echo "abi=$(ABI)"; \
203203
echo "system=$(SYSTEM)"; \
204204
echo "has_runtime_lib=$(HAS_RUNTIME_LIB)"; \
205+
echo "has_standard_headers=$(HAS_STANDARD_HEADERS)"; \
205206
echo "asm_supports_cfi=$(ASM_SUPPORTS_CFI)"; \
206207
echo "advanced_debug=$(ADVANCED_DEBUG)"; \
207208
echo "struct_passing_style=$(STRUCT_PASSING)"; \
@@ -220,15 +221,13 @@ depend: $(FILES) exportclight/Clightdefs.v
220221

221222
install:
222223
install -d $(BINDIR)
223-
install ./ccomp $(BINDIR)
224+
install -m 0755 ./ccomp $(BINDIR)
224225
install -d $(SHAREDIR)
225-
install ./compcert.ini $(SHAREDIR)
226+
install -m 0644 ./compcert.ini $(SHAREDIR)
226227
ifeq ($(CCHECKLINK),true)
227-
install ./cchecklink $(BINDIR)
228+
install -m 0755 ./cchecklink $(BINDIR)
228229
endif
229-
ifeq ($(HAS_RUNTIME_LIB),true)
230230
$(MAKE) -C runtime install
231-
endif
232231

233232
clean:
234233
rm -f $(patsubst %, %/*.vo, $(DIRS))

configure

+11-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ libdir='$(PREFIX)/lib/compcert'
1818
toolprefix=''
1919
target=''
2020
has_runtime_lib=true
21+
has_standard_headers=true
2122
build_checklink=true
2223
advanced_debug=false
2324

@@ -49,6 +50,7 @@ Options:
4950
-libdir <dir> Install libraries in <dir>
5051
-toolprefix <pref> Prefix names of tools ("gcc", etc) with <pref>
5152
-no-runtime-lib Do not compile nor install the runtime support library
53+
-no-standard-headers Do not install nor use the standard .h headers
5254
'
5355

5456
# Parse command-line arguments
@@ -66,6 +68,8 @@ while : ; do
6668
toolprefix="$2"; shift;;
6769
-no-runtime-lib)
6870
has_runtime_lib=false;;
71+
-no-standard-headers)
72+
has_standard_headers=false;;
6973
-no-checklink)
7074
build_checklink=false;;
7175
*)
@@ -357,6 +361,7 @@ CASMRUNTIME=$casmruntime
357361
CLINKER=$clinker
358362
LIBMATH=$libmath
359363
HAS_RUNTIME_LIB=$has_runtime_lib
364+
HAS_STANDARD_HEADERS=$has_standard_headers
360365
CCHECKLINK=$cchecklink
361366
ASM_SUPPORTS_CFI=$asm_supports_cfi
362367
ADVANCED_DEBUG=$advanced_debug
@@ -428,9 +433,12 @@ CLINKER=gcc
428433
# Math library. Set to empty under MacOS X
429434
LIBMATH=-lm
430435
431-
# Do not change
436+
# Turn on/off the installation and use of the runtime support library
432437
HAS_RUNTIME_LIB=true
433438
439+
# Turn on/off the installation and use of the standard header files
440+
HAS_STANDARD_HEADERS=true
441+
434442
# Whether the assembler $(CASM) supports .cfi debug directives
435443
ASM_SUPPORTS_CFI=false
436444
#ASM_SUPPORTS_CFI=true
@@ -471,6 +479,8 @@ CompCert configuration:
471479
Binaries installed in......... $bindirexp
472480
Runtime library provided...... $has_runtime_lib
473481
Library files installed in.... $libdirexp
482+
Standard headers provided..... $has_standard_headers
483+
Standard headers installed in. $libdirexp/include
474484
cchecklink tool supported..... $cchecklink
475485
Build command to use.......... $make
476486

driver/Configuration.ml

+5
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ let has_runtime_lib =
8282
| "true" -> true
8383
| "false" -> false
8484
| v -> bad_config "has_runtime_lib" [v]
85+
let has_standard_headers =
86+
match get_config_string "has_standard_headers" with
87+
| "true" -> true
88+
| "false" -> false
89+
| v -> bad_config "has_standard_headers" [v]
8590
let stdlib_path =
8691
if has_runtime_lib then
8792
get_config_string "stdlib_path"

driver/Configuration.mli

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ val stdlib_path: string
3131
(** Path to CompCert's library *)
3232
val has_runtime_lib: bool
3333
(** True if CompCert's library is available. *)
34+
val has_standard_headers: bool
35+
(** True if CompCert's standard header files is available. *)
3436
val advanced_debug: bool
3537
(** True if advanced debug is implement for the Target *)
3638

driver/Driver.ml

+2-2
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ let preprocess ifile ofile =
9393
let cmd = List.concat [
9494
Configuration.prepro;
9595
["-D__COMPCERT__"];
96-
(if Configuration.has_runtime_lib
97-
then ["-I" ^ !stdlib_path]
96+
(if Configuration.has_standard_headers
97+
then ["-I" ^ Filename.concat !stdlib_path "include" ]
9898
else []);
9999
List.rev !prepro_options;
100100
[ifile]

runtime/Makefile

+14-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
include ../Makefile.config
22

33
CFLAGS=-O1 -g -Wall
4-
INCLUDES=
54
OBJS=i64_dtos.o i64_dtou.o i64_sar.o i64_sdiv.o i64_shl.o \
65
i64_shr.o i64_smod.o i64_stod.o i64_stof.o \
76
i64_udivmod.o i64_udiv.o i64_umod.o i64_utod.o i64_utof.o \
87
vararg.o
98
LIB=libcompcert.a
9+
INCLUDES=include/float.h include/stdarg.h include/stdbool.h \
10+
include/stddef.h include/varargs.h
1011

1112
ifeq ($(strip $(HAS_RUNTIME_LIB)),true)
12-
all: $(LIB) $(INCLUDES)
13+
all: $(LIB)
1314
else
1415
all:
1516
endif
@@ -28,11 +29,19 @@ clean::
2829
rm -f *.o $(LIB)
2930

3031
ifeq ($(strip $(HAS_RUNTIME_LIB)),true)
31-
install:
32+
install::
3233
install -d $(LIBDIR)
33-
install -c $(LIB) $(INCLUDES) $(LIBDIR)
34+
install -m 0644 $(LIB) $(LIBDIR)
3435
else
35-
install:
36+
install::
37+
endif
38+
39+
ifeq ($(strip $(HAS_STANDARD_HEADERS)),true)
40+
install::
41+
install -d $(LIBDIR)/include
42+
install -m 0644 $(INCLUDES) $(LIBDIR)/include
43+
else
44+
install::
3645
endif
3746

3847
test/test_int64: test/test_int64.c $(LIB)

runtime/include/float.h

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/* This file is part of the Compcert verified compiler.
2+
*
3+
* Copyright (c) 2015 Institut National de Recherche en Informatique et
4+
* en Automatique.
5+
*
6+
* Redistribution and use in source and binary forms, with or without
7+
* modification, are permitted provided that the following conditions are met:
8+
* * Redistributions of source code must retain the above copyright
9+
* notice, this list of conditions and the following disclaimer.
10+
* * Redistributions in binary form must reproduce the above copyright
11+
* notice, this list of conditions and the following disclaimer in the
12+
* documentation and/or other materials provided with the distribution.
13+
* * Neither the name of the <organization> nor the
14+
* names of its contributors may be used to endorse or promote products
15+
* derived from this software without specific prior written permission.
16+
*
17+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20+
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT
21+
* HOLDER> BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22+
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23+
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24+
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25+
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26+
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28+
*/
29+
30+
/* <float.h> -- characteristics of floating types (ISO C99 7.7) */
31+
32+
#ifndef _FLOAT_H
33+
#define _FLOAT_H
34+
35+
/* FP numbers are in binary */
36+
#define FLT_RADIX 2
37+
38+
/* No excess precision is used during FP arithmetic */
39+
#define FLT_EVAL_METHOD 0
40+
41+
/* FP operations round to nearest even */
42+
#define FLT_ROUNDS 1
43+
44+
/* Number of decimal digits sufficient to represent FP numbers */
45+
#define DECIMAL_DIG 17
46+
47+
/* The "float" type is IEEE binary32 */
48+
#define FLT_MANT_DIG 24
49+
#define FLT_DIG 6
50+
#define FLT_ROUNDS 1
51+
#define FLT_EPSILON 0x1p-23F
52+
#define FLT_MIN_EXP (-125)
53+
#define FLT_MIN 0x1p-126F
54+
#define FLT_MIN_10_EXP (-37)
55+
#define FLT_MAX_EXP 128
56+
#define FLT_MAX 0x1.fffffep+127F
57+
#define FLT_MAX_10_EXP 38
58+
59+
/* The "double" type is IEEE binary64 */
60+
#define DBL_MANT_DIG 53
61+
#define DBL_DIG 15
62+
#define DBL_EPSILON 0x1p-52
63+
#define DBL_MIN_EXP (-1021)
64+
#define DBL_MIN 0x1p-1022
65+
#define DBL_MIN_10_EXP (-307)
66+
#define DBL_MAX_EXP 1024
67+
#define DBL_MAX 0x1.fffffffffffffp+1023
68+
#define DBL_MAX_10_EXP 308
69+
70+
/* The "long double" type, when supported, is IEEE binary64 */
71+
#define LDBL_MANT_DIG 53
72+
#define LDBL_DIG 15
73+
#define LDBL_EPSILON 0x1p-52L
74+
#define LDBL_MIN_EXP (-1021)
75+
#define LDBL_MIN 0x1p-1022L
76+
#define LDBL_MIN_10_EXP (-307)
77+
#define LDBL_MAX_EXP 1024
78+
#define LDBL_MAX 0x1.fffffffffffffp+1023L
79+
#define LDBL_MAX_10_EXP 308
80+
81+
#endif
82+

runtime/include/stdarg.h

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/* This file is part of the Compcert verified compiler.
2+
*
3+
* Copyright (c) 2015 Institut National de Recherche en Informatique et
4+
* en Automatique.
5+
*
6+
* Redistribution and use in source and binary forms, with or without
7+
* modification, are permitted provided that the following conditions are met:
8+
* * Redistributions of source code must retain the above copyright
9+
* notice, this list of conditions and the following disclaimer.
10+
* * Redistributions in binary form must reproduce the above copyright
11+
* notice, this list of conditions and the following disclaimer in the
12+
* documentation and/or other materials provided with the distribution.
13+
* * Neither the name of the <organization> nor the
14+
* names of its contributors may be used to endorse or promote products
15+
* derived from this software without specific prior written permission.
16+
*
17+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20+
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT
21+
* HOLDER> BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22+
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23+
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24+
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25+
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26+
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28+
*/
29+
30+
/* <stdarg.h> -- variable argument handling (ISO C99 7.15) */
31+
32+
#ifndef _STDARG_H
33+
34+
/* Glibc compatibility: if __need___va_list is set,
35+
just define __gnuc_va_list and don't consider this file as included. */
36+
#ifndef __need___va_list
37+
#define _STDARG_H
38+
#endif
39+
#undef __need___va_list
40+
41+
#ifndef __GNUC_VA_LIST
42+
#define __GNUC_VA_LIST
43+
typedef __builtin_va_list __gnuc_va_list;
44+
#endif
45+
46+
#ifdef _STDARG_H
47+
48+
#ifndef _VA_LIST_T
49+
#define _VA_LIST_T
50+
typedef __builtin_va_list va_list;
51+
#endif
52+
53+
#define va_start(v,l) __builtin_va_start(v,l)
54+
#define va_end(v) __builtin_va_end(v)
55+
#define va_arg(v,l) __builtin_va_arg(v,l)
56+
#define va_copy(d,s) __builtin_va_copy(d,s)
57+
58+
#endif
59+
60+
#endif
61+

runtime/include/stdbool.h

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/* This file is part of the Compcert verified compiler.
2+
*
3+
* Copyright (c) 2015 Institut National de Recherche en Informatique et
4+
* en Automatique.
5+
*
6+
* Redistribution and use in source and binary forms, with or without
7+
* modification, are permitted provided that the following conditions are met:
8+
* * Redistributions of source code must retain the above copyright
9+
* notice, this list of conditions and the following disclaimer.
10+
* * Redistributions in binary form must reproduce the above copyright
11+
* notice, this list of conditions and the following disclaimer in the
12+
* documentation and/or other materials provided with the distribution.
13+
* * Neither the name of the <organization> nor the
14+
* names of its contributors may be used to endorse or promote products
15+
* derived from this software without specific prior written permission.
16+
*
17+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20+
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT
21+
* HOLDER> BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22+
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23+
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24+
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25+
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26+
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28+
*/
29+
30+
/* <stdbool.h> -- Boolean type and values (ISO C99 7.16) */
31+
32+
#ifndef _STDBOOL_H
33+
#define _STDBOOL_H
34+
35+
#define bool _Bool
36+
#define true 1
37+
#define false 0
38+
39+
#endif

0 commit comments

Comments
 (0)