summarylogtreecommitdiffstats
path: root/edg_eccp_config
blob: 8d3abbd83f76b3af1f65114c4d0673f5b095bf5e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# Part of the EDG Compiler Project, under the Apache License v2.0 with LLVM
# Exceptions.
# See https://edgcpp.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

################################################################################
#
# Configuration file for the EDG eccp script: native Linux with GCC, on
# x86_64 or AArch64, over the resident gcc and glibc.
#
# eccp.sh sources this file from $EDG_BASE on every run.  It is
# bases/docker/dev-env/gcc/edg_eccp_config adapted to the resident gcc: the
# header search lists and the gcc version are read from the gcc on this
# machine when eccp runs, not taken from the environment, and the C++
# runtime is EDG's libC.a unless g++ emulation asks for libstdc++.
#
# The predefined macro table, lib/predefined_macros.txt, is not part of
# this base.  It describes one gcc, so it is generated on the machine the
# base is installed on (util/make_predef_macro_table, run in lib/), and
# regenerated when gcc changes.
#
################################################################################
EDG_DEFAULT_DEFINES="-D__CHAR_BIT__=8"
EDG_DEFAULT_CPP_DEFINES="-D_POSIX_SOURCE"

# Use GCC.
EDG_C_TO_OBJ_COMPILER=gcc

# The predefined macro table is generated, not shipped (see above).  cpfe
# stops without it, with a message that names no cause.
edg_table=$EDG_BASE/lib/predefined_macros.txt
if [ ! -r "$edg_table" ] ; then
  echo "eccp: $edg_table is missing." >&2
  echo "eccp: generate it from the resident gcc: mkdir -p $EDG_BASE/lib &&" \
       "cd $EDG_BASE/lib && sh util/make_predef_macro_table" \
       "(the script is in the EDG source tree)." >&2
  exit 1
fi

# The resident gcc's header search list for language $1 (c or c++),
# colon-separated, in gcc's own order.
edg_gcc_includes() {
  "$EDG_C_TO_OBJ_COMPILER" -x "$1" -v -E /dev/null 2>&1 >/dev/null |
    sed -e '1,/^#include <\.\.\.> search starts here:/d' \
        -e '/^End of search list\./,$d' \
        -e 's/^ *//' |
    paste -sd: -
}

# The resident gcc's version: 16.2.1, and in --gnu_version form, 160201.
edg_gcc_version=$("$EDG_C_TO_OBJ_COMPILER" -dumpfullversion)
EDG_GCC_VER_SCRAPE=${EDG_GCC_VER_SCRAPE-$(
  printf '%s' "$edg_gcc_version" |
    awk -F. '{ printf "%d%02d%02d", $1, $2, $3 }')}

# The table records the gcc that made it.  After a gcc upgrade it is stale
# until regenerated: g++ emulation then fails on the __GNUC__ entries, and
# strict mode keeps the old target facts without a word.  Warn.
edg_table_gcc=$(sed -n '/^# gcc version /{s/^# gcc version \([^ ]*\).*/\1/p;q;}' \
                "$edg_table")
if [ -n "$edg_table_gcc" ] && [ "$edg_table_gcc" != "$edg_gcc_version" ] ; then
  echo "eccp: warning: $edg_table was made by gcc $edg_table_gcc;" \
       "the resident gcc is $edg_gcc_version. Regenerate the table" \
       "with util/make_predef_macro_table." >&2
fi

# Two switches.  EDG_USE_SYSTEM_HEADERS=1 is g++ emulation: g++'s search
# lists and --gnu_version.  EDG_LINK_SYSTEM_CXX_RUNTIME=1 links libstdc++
# and libgcc_s ahead of libC.a.  The second follows the first unless set on
# its own, for programs that carry libstdc++'s headers already expanded
# (preprocessed tests) and so need its library without its headers.
EDG_USE_SYSTEM_HEADERS=${EDG_USE_SYSTEM_HEADERS-0}
EDG_LINK_SYSTEM_CXX_RUNTIME=${EDG_LINK_SYSTEM_CXX_RUNTIME-$EDG_USE_SYSTEM_HEADERS}
if [ $EDG_USE_SYSTEM_HEADERS -eq 0 ] ; then
  # EDG's own headers, then the resident gcc's C search list: gcc's
  # freestanding headers and glibc.
  edg_cincl=$(edg_gcc_includes c)
  EDG_INCLDIR=${EDG_INCLDIR-"$EDG_BASE/include:$edg_cincl"}
  EDG_CINCLDIR=${EDG_CINCLDIR-"$EDG_BASE/include_c99:$edg_cincl"}
else
  # g++ emulation: the resident g++'s search lists, libstdc++ first.
  EDG_INCLDIR=${EDG_INCLDIR-${EDG_GCC_INCL_SCRAPE-$(edg_gcc_includes c++)}}
  EDG_CINCLDIR=${EDG_CINCLDIR-${EDG_GCC_CINCL_SCRAPE-$(edg_gcc_includes c)}}
  # Inject --gnu_version to the resident gcc's version.
  EDG_CPFE_DEFAULT_OPTIONS="--gnu_version=$EDG_GCC_VER_SCRAPE $EDG_CPFE_DEFAULT_OPTIONS"
fi
if [ $EDG_LINK_SYSTEM_CXX_RUNTIME -eq 0 ] ; then
  # The C++ runtime is EDG's libC.a, which eccp.sh links last.
  EDG_C_TO_OBJ_LIBRARIES="$EDG_C_TO_OBJ_LIBRARIES -lpthread"
else
  EDG_C_TO_OBJ_LIBRARIES="$EDG_C_TO_OBJ_LIBRARIES -lstdc++ -lgcc_s -lpthread"
fi

# Get rid of the annoying "nm: stubs.o: no symbols" errors:
EDG_PRELINK_DEFAULT_OPTIONS='-c "nm -og 2>/dev/null" '$EDG_PRELINK_DEFAULT_OPTIONS

default_opts=$(printf '%s' \
  "$EDG_C_TO_OBJ_DEFAULT_OPTIONS " \
  '-w -Dva_copy=__va_copy -falign-functions=4 -fdiagnostics-plain-output'
)

if [ $EDG_GCC_VER_SCRAPE -ge 140000 ] ; then
  #
  # As of GCC 14 the following flags are required to prevent spurious
  # errors when compiling the generated C code.
  #
  # See https://gcc.gnu.org/gcc-14/porting_to.html for more information.
  #
  warnings_to_disable=$(printf '%s' \
    '-Wno-error=implicit-function-declaration ' \
    '-Wno-error=incompatible-pointer-types ' \
    '-Wno-error=int-conversion ' \
    '-Wno-error=return-mismatch '
  )
  default_opts="$default_opts $warnings_to_disable"
fi

# The target is the machine the resident gcc compiles for.  eccp reads
# EDG_C_TO_OBJ_DEFAULT_OPTIONS_<target> whenever --target is given, the
# default target's own name included, and warns when it is unset.
case $("$EDG_C_TO_OBJ_COMPILER" -dumpmachine) in
  x86_64-*)
    EDG_C_TO_OBJ_DEFAULT_OPTIONS=$default_opts
    EDG_C_TO_OBJ_DEFAULT_OPTIONS_linux_x86_64="$default_opts -m64 -march=x86-64"
    ;;
  aarch64-*)
    # GCC on AArch64 has no __float128.  The front end keeps it, as a
    # binary128 type distinct from long double, because the _Float128
    # keyword that glibc's headers need in C++ comes with it; map the
    # spelling in the generated C to GCC's _Float128.
    default_opts="$default_opts -D__float128=_Float128"
    EDG_C_TO_OBJ_DEFAULT_OPTIONS=$default_opts
    EDG_C_TO_OBJ_DEFAULT_OPTIONS_linux_aarch64=$default_opts
    ;;
  *)
    EDG_C_TO_OBJ_DEFAULT_OPTIONS=$default_opts
    ;;
esac

EDG_C_TO_OBJ_C99_OPTIONS="-std=gnu9x"

EDG_SUPPRESS_PATCH_MUNCH=1
EDG_STD_LIBS=${EDG_STD_LIBS-""}
COLLECT_NO_DEMANGLE=1
export COLLECT_NO_DEMANGLE