1 dnl grub_ASM_USCORE checks if C symbols get an underscore after
2 dnl compiling to assembler.
3 dnl Written by Pavel Roskin. Based on grub_ASM_EXT_C written by
4 dnl Erich Boleyn and modified by Yoshinori K. Okuji.
5 AC_DEFUN(grub_ASM_USCORE,
6 [AC_REQUIRE([AC_PROG_CC])
7 AC_MSG_CHECKING([if C symbols get an underscore after compilation])
8 AC_CACHE_VAL(grub_cv_asm_uscore,
9 [cat > conftest.c <<\EOF
18 if AC_TRY_COMMAND([${CC-cc} ${CFLAGS} -S conftest.c]) && test -s conftest.s; then
21 AC_MSG_ERROR([${CC-cc} failed to produce assembly code])
24 if grep _func conftest.s >/dev/null 2>&1; then
25 grub_cv_asm_uscore=yes
32 if test "x$grub_cv_asm_uscore" = xyes; then
33 AC_DEFINE_UNQUOTED([HAVE_ASM_USCORE], $grub_cv_asm_uscore,
34 [Define if C symbols get an underscore after compilation])
37 AC_MSG_RESULT([$grub_cv_asm_uscore])
41 dnl Some versions of `objcopy -O binary' vary their output depending
42 dnl on the link address.
43 AC_DEFUN(grub_PROG_OBJCOPY_ABSOLUTE,
44 [AC_MSG_CHECKING([whether ${OBJCOPY} works for absolute addresses])
45 AC_CACHE_VAL(grub_cv_prog_objcopy_absolute,
46 [cat > conftest.c <<\EOF
50 *((int *) 0x1000) = 2;
54 if AC_TRY_EVAL(ac_compile) && test -s conftest.o; then :
56 AC_MSG_ERROR([${CC-cc} cannot compile C source code])
58 grub_cv_prog_objcopy_absolute=yes
59 for link_addr in 2000 8000 7C00; do
60 if AC_TRY_COMMAND([${CC-cc} ${CFLAGS} ${LDFLAGS} -nostdlib -Wl,-N -Wl,-Ttext -Wl,$link_addr conftest.o -o conftest.exec]); then :
62 AC_MSG_ERROR([${CC-cc} cannot link at address $link_addr])
64 if AC_TRY_COMMAND([${OBJCOPY-objcopy} -O binary conftest.exec conftest]); then :
66 AC_MSG_ERROR([${OBJCOPY-objcopy} cannot create binary files])
68 if test ! -f conftest.old || AC_TRY_COMMAND([cmp -s conftest.old conftest]); then
69 mv -f conftest conftest.old
71 grub_cv_prog_objcopy_absolute=no
76 AC_MSG_RESULT([$grub_cv_prog_objcopy_absolute])
78 if test "x$grub_cv_prog_objcopy_absolute" = xno; then
79 AC_MSG_ERROR([GRUB requires a working absolute objcopy; upgrade your binutils])
85 dnl Older versions of GAS interpret `.code16' to mean ``generate 32-bit
86 dnl instructions, but implicitly insert addr32 and data32 bytes so
87 dnl that the code works in real mode''.
89 dnl Newer versions of GAS interpret `.code16' to mean ``generate 16-bit
90 dnl instructions,'' which seems right. This requires the programmer
91 dnl to explicitly insert addr32 and data32 instructions when they want
94 dnl We only support the newer versions, because the old versions cause
95 dnl major pain, by requiring manual assembly to get 16-bit instructions into
97 AC_DEFUN(grub_I386_ASM_ADDR32,
98 [AC_REQUIRE([AC_PROG_CC])
99 AC_REQUIRE([grub_I386_ASM_PREFIX_REQUIREMENT])
100 AC_MSG_CHECKING([for .code16 addr32 assembler support])
101 AC_CACHE_VAL(grub_cv_i386_asm_addr32,
102 [cat > conftest.s.in <<\EOF
104 l1: @ADDR32@ movb %al, l1
107 if test "x$grub_cv_i386_asm_prefix_requirement" = xyes; then
108 sed -e s/@ADDR32@/addr32/ < conftest.s.in > conftest.s
110 sed -e s/@ADDR32@/addr32\;/ < conftest.s.in > conftest.s
113 if AC_TRY_COMMAND([${CC-cc} ${CFLAGS} -c conftest.s]) && test -s conftest.o; then
114 grub_cv_i386_asm_addr32=yes
116 grub_cv_i386_asm_addr32=no
121 AC_MSG_RESULT([$grub_cv_i386_asm_addr32])])
124 dnl Later versions of GAS requires that addr32 and data32 prefixes
125 dnl appear in the same lines as the instructions they modify, while
126 dnl earlier versions requires that they appear in separate lines.
127 AC_DEFUN(grub_I386_ASM_PREFIX_REQUIREMENT,
128 [AC_REQUIRE([AC_PROG_CC])
130 [whether addr32 must be in the same line as the instruction])
131 AC_CACHE_VAL(grub_cv_i386_asm_prefix_requirement,
132 [cat > conftest.s <<\EOF
134 l1: addr32 movb %al, l1
137 if AC_TRY_COMMAND([${CC-cc} ${CFLAGS} -c conftest.s]) && test -s conftest.o; then
138 grub_cv_i386_asm_prefix_requirement=yes
140 grub_cv_i386_asm_prefix_requirement=no
145 if test "x$grub_cv_i386_asm_prefix_requirement" = xyes; then
146 grub_tmp_addr32="addr32"
147 grub_tmp_data32="data32"
149 grub_tmp_addr32="addr32;"
150 grub_tmp_data32="data32;"
153 AC_DEFINE_UNQUOTED([ADDR32], $grub_tmp_addr32,
154 [Define it to \"addr32\" or \"addr32;\" to make GAS happy])
155 AC_DEFINE_UNQUOTED([DATA32], $grub_tmp_data32,
156 [Define it to \"data32\" or \"data32;\" to make GAS happy])
158 AC_MSG_RESULT([$grub_cv_i386_asm_prefix_requirement])])
161 dnl Older versions of GAS require that absolute indirect calls/jumps are
162 dnl not prefixed with `*', while later versions warn if not prefixed.
163 AC_DEFUN(grub_I386_ASM_ABSOLUTE_WITHOUT_ASTERISK,
164 [AC_REQUIRE([AC_PROG_CC])
166 [whether an absolute indirect call/jump must not be prefixed with an asterisk])
167 AC_CACHE_VAL(grub_cv_i386_asm_absolute_without_asterisk,
168 [cat > conftest.s <<\EOF
175 if AC_TRY_COMMAND([${CC-cc} ${CFLAGS} -c conftest.s]) && test -s conftest.o; then
176 grub_cv_i386_asm_absolute_without_asterisk=no
178 grub_cv_i386_asm_absolute_without_asterisk=yes
183 if test "x$grub_cv_i386_asm_absolute_without_asterisk" = xyes; then
184 AC_DEFINE([ABSOLUTE_WITHOUT_ASTERISK], 1,
185 [Define it if GAS requires that absolute indirect calls/jumps are not prefixed with an asterisk])
188 AC_MSG_RESULT([$grub_cv_i386_asm_absolute_without_asterisk])])
191 dnl Check what symbol is defined as a start symbol.
192 dnl Written by Yoshinori K. Okuji.
193 AC_DEFUN(grub_CHECK_START_SYMBOL,
194 [AC_REQUIRE([AC_PROG_CC])
195 AC_MSG_CHECKING([if start is defined by the compiler])
196 AC_CACHE_VAL(grub_cv_check_start_symbol,
197 [AC_TRY_LINK([], [asm ("incl start")],
198 grub_cv_check_start_symbol=yes,
199 grub_cv_check_start_symbol=no)])
201 AC_MSG_RESULT([$grub_cv_check_start_symbol])
203 AC_MSG_CHECKING([if _start is defined by the compiler])
204 AC_CACHE_VAL(grub_cv_check_uscore_start_symbol,
205 [AC_TRY_LINK([], [asm ("incl _start")],
206 grub_cv_check_uscore_start_symbol=yes,
207 grub_cv_check_uscore_start_symbol=no)])
209 AC_MSG_RESULT([$grub_cv_check_uscore_start_symbol])
211 AH_TEMPLATE([START_SYMBOL], [Define it to either start or _start])
213 if test "x$grub_cv_check_start_symbol" = xyes; then
214 AC_DEFINE([START_SYMBOL], [start])
215 elif test "x$grub_cv_check_uscore_start_symbol" = xyes; then
216 AC_DEFINE([START_SYMBOL], [_start])
218 AC_MSG_ERROR([neither start nor _start is defined])
222 dnl Check what symbol is defined as a bss start symbol.
223 dnl Written by Michael Hohmoth and Yoshinori K. Okuji.
224 AC_DEFUN(grub_CHECK_BSS_START_SYMBOL,
225 [AC_REQUIRE([AC_PROG_CC])
226 AC_MSG_CHECKING([if __bss_start is defined by the compiler])
227 AC_CACHE_VAL(grub_cv_check_uscore_uscore_bss_start_symbol,
228 [AC_TRY_LINK([], [asm ("incl __bss_start")],
229 grub_cv_check_uscore_uscore_bss_start_symbol=yes,
230 grub_cv_check_uscore_uscore_bss_start_symbol=no)])
232 AC_MSG_RESULT([$grub_cv_check_uscore_uscore_bss_start_symbol])
234 AC_MSG_CHECKING([if edata is defined by the compiler])
235 AC_CACHE_VAL(grub_cv_check_edata_symbol,
236 [AC_TRY_LINK([], [asm ("incl edata")],
237 grub_cv_check_edata_symbol=yes,
238 grub_cv_check_edata_symbol=no)])
240 AC_MSG_RESULT([$grub_cv_check_edata_symbol])
242 AC_MSG_CHECKING([if _edata is defined by the compiler])
243 AC_CACHE_VAL(grub_cv_check_uscore_edata_symbol,
244 [AC_TRY_LINK([], [asm ("incl _edata")],
245 grub_cv_check_uscore_edata_symbol=yes,
246 grub_cv_check_uscore_edata_symbol=no)])
248 AC_MSG_RESULT([$grub_cv_check_uscore_edata_symbol])
250 AH_TEMPLATE([BSS_START_SYMBOL], [Define it to one of __bss_start, edata and _edata])
252 if test "x$grub_cv_check_uscore_uscore_bss_start_symbol" = xyes; then
253 AC_DEFINE([BSS_START_SYMBOL], [__bss_start])
254 elif test "x$grub_cv_check_edata_symbol" = xyes; then
255 AC_DEFINE([BSS_START_SYMBOL], [edata])
256 elif test "x$grub_cv_check_uscore_edata_symbol" = xyes; then
257 AC_DEFINE([BSS_START_SYMBOL], [_edata])
259 AC_MSG_ERROR([none of __bss_start, edata or _edata is defined])
263 dnl Check what symbol is defined as an end symbol.
264 dnl Written by Yoshinori K. Okuji.
265 AC_DEFUN(grub_CHECK_END_SYMBOL,
266 [AC_REQUIRE([AC_PROG_CC])
267 AC_MSG_CHECKING([if end is defined by the compiler])
268 AC_CACHE_VAL(grub_cv_check_end_symbol,
269 [AC_TRY_LINK([], [asm ("incl end")],
270 grub_cv_check_end_symbol=yes,
271 grub_cv_check_end_symbol=no)])
273 AC_MSG_RESULT([$grub_cv_check_end_symbol])
275 AC_MSG_CHECKING([if _end is defined by the compiler])
276 AC_CACHE_VAL(grub_cv_check_uscore_end_symbol,
277 [AC_TRY_LINK([], [asm ("incl _end")],
278 grub_cv_check_uscore_end_symbol=yes,
279 grub_cv_check_uscore_end_symbol=no)])
281 AC_MSG_RESULT([$grub_cv_check_uscore_end_symbol])
283 AH_TEMPLATE([END_SYMBOL], [Define it to either end or _end])
285 if test "x$grub_cv_check_end_symbol" = xyes; then
286 AC_DEFINE([END_SYMBOL], [end])
287 elif test "x$grub_cv_check_uscore_end_symbol" = xyes; then
288 AC_DEFINE([END_SYMBOL], [_end])
290 AC_MSG_ERROR([neither end nor _end is defined])
294 dnl Check if the C compiler has a bug while using nested functions when
295 dnl mregparm is used on the i386. Some gcc versions do not pass the third
296 dnl parameter correctly to the nested function.
297 dnl Written by Marco Gerards.
298 AC_DEFUN(grub_I386_CHECK_REGPARM_BUG,
299 [AC_REQUIRE([AC_PROG_CC])
300 AC_MSG_CHECKING([if GCC has the regparm=3 bug])
301 AC_CACHE_VAL(grub_cv_i386_check_nested_functions,
302 [AC_RUN_IFELSE([AC_LANG_SOURCE(
311 testfunc (int __attribute__ ((__regparm__ (3))) (*hook) (int a, int b, int *c))
316 return hook (a, b, &c);
322 int __attribute__ ((__regparm__ (3))) nestedfunc (int a, int b, int *c)
324 return a == b && test (c);
326 return testfunc (nestedfunc) ? 0 : 1;
329 [grub_cv_i386_check_nested_functions=no],
330 [grub_cv_i386_check_nested_functions=yes])])
332 AC_MSG_RESULT([$grub_cv_i386_check_nested_functions])
334 if test "x$grub_cv_i386_check_nested_functions" = xyes; then
335 AC_DEFINE([NESTED_FUNC_ATTR],
336 [__attribute__ ((__regparm__ (1)))],
339 dnl Unfortunately, the above test does not detect a bug in gcc-4.0.
340 dnl So use regparm 2 until a better test is found.
341 AC_DEFINE([NESTED_FUNC_ATTR],
342 [__attribute__ ((__regparm__ (1)))],
347 dnl Check if the C compiler supports `-fstack-protector'.
348 AC_DEFUN(grub_CHECK_STACK_PROTECTOR,[
349 [# Smashing stack protector.
351 AC_MSG_CHECKING([whether `$CC' accepts `-fstack-protector'])
352 # Is this a reliable test case?
353 AC_LANG_CONFTEST([[void foo (void) { volatile char a[8]; a[3]; }]])
354 [# `$CC -c -o ...' might not be portable. But, oh, well... Is calling
355 # `ac_compile' like this correct, after all?
356 if eval "$ac_compile -S -fstack-protector -o conftest.s" 2> /dev/null; then]
358 [# Should we clear up other files as well, having called `AC_LANG_CONFTEST'?