]> git.proxmox.com Git - grub2.git/blob - aclocal.m4
2006-04-22 Yoshinori K. Okuji <okuji@enbug.org>
[grub2.git] / aclocal.m4
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
10 int
11 func (int *list)
12 {
13 *list = 0;
14 return *list;
15 }
16 EOF
17
18 if AC_TRY_COMMAND([${CC-cc} ${CFLAGS} -S conftest.c]) && test -s conftest.s; then
19 true
20 else
21 AC_MSG_ERROR([${CC-cc} failed to produce assembly code])
22 fi
23
24 if grep _func conftest.s >/dev/null 2>&1; then
25 grub_cv_asm_uscore=yes
26 else
27 grub_cv_asm_uscore=no
28 fi
29
30 rm -f conftest*])
31
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])
35 fi
36
37 AC_MSG_RESULT([$grub_cv_asm_uscore])
38 ])
39
40
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
47 void
48 cmain (void)
49 {
50 *((int *) 0x1000) = 2;
51 }
52 EOF
53
54 if AC_TRY_EVAL(ac_compile) && test -s conftest.o; then :
55 else
56 AC_MSG_ERROR([${CC-cc} cannot compile C source code])
57 fi
58 grub_cv_prog_objcopy_absolute=yes
59 for link_addr in 2000 8000 7C00; do
60 if AC_TRY_COMMAND([${CC-cc} ${CFLAGS} -nostdlib -Wl,-N -Wl,-Ttext -Wl,$link_addr conftest.o -o conftest.exec]); then :
61 else
62 AC_MSG_ERROR([${CC-cc} cannot link at address $link_addr])
63 fi
64 if AC_TRY_COMMAND([${OBJCOPY-objcopy} -O binary conftest.exec conftest]); then :
65 else
66 AC_MSG_ERROR([${OBJCOPY-objcopy} cannot create binary files])
67 fi
68 if test ! -f conftest.old || AC_TRY_COMMAND([cmp -s conftest.old conftest]); then
69 mv -f conftest conftest.old
70 else
71 grub_cv_prog_objcopy_absolute=no
72 break
73 fi
74 done
75 rm -f conftest*])
76 AC_MSG_RESULT([$grub_cv_prog_objcopy_absolute])
77
78 if test "x$grub_cv_prog_objcopy_absolute" = xno; then
79 AC_MSG_ERROR([GRUB requires a working absolute objcopy; upgrade your binutils])
80 fi
81 ])
82
83
84 dnl Mass confusion!
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''.
88 dnl
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
92 dnl them.
93 dnl
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
96 dnl asm files.
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
103 .code16
104 l1: @ADDR32@ movb %al, l1
105 EOF
106
107 if test "x$grub_cv_i386_asm_prefix_requirement" = xyes; then
108 sed -e s/@ADDR32@/addr32/ < conftest.s.in > conftest.s
109 else
110 sed -e s/@ADDR32@/addr32\;/ < conftest.s.in > conftest.s
111 fi
112
113 if AC_TRY_COMMAND([${CC-cc} ${CFLAGS} -c conftest.s]) && test -s conftest.o; then
114 grub_cv_i386_asm_addr32=yes
115 else
116 grub_cv_i386_asm_addr32=no
117 fi
118
119 rm -f conftest*])
120
121 AC_MSG_RESULT([$grub_cv_i386_asm_addr32])])
122
123
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])
129 AC_MSG_CHECKING(dnl
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
133 .code16
134 l1: addr32 movb %al, l1
135 EOF
136
137 if AC_TRY_COMMAND([${CC-cc} ${CFLAGS} -c conftest.s]) && test -s conftest.o; then
138 grub_cv_i386_asm_prefix_requirement=yes
139 else
140 grub_cv_i386_asm_prefix_requirement=no
141 fi
142
143 rm -f conftest*])
144
145 if test "x$grub_cv_i386_asm_prefix_requirement" = xyes; then
146 grub_tmp_addr32="addr32"
147 grub_tmp_data32="data32"
148 else
149 grub_tmp_addr32="addr32;"
150 grub_tmp_data32="data32;"
151 fi
152
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])
157
158 AC_MSG_RESULT([$grub_cv_i386_asm_prefix_requirement])])
159
160
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])
165 AC_MSG_CHECKING(dnl
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
169 lcall *(offset)
170 offset:
171 .long 0
172 .word 0
173 EOF
174
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
177 else
178 grub_cv_i386_asm_absolute_without_asterisk=yes
179 fi
180
181 rm -f conftest*])
182
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])
186 fi
187
188 AC_MSG_RESULT([$grub_cv_i386_asm_absolute_without_asterisk])])
189
190
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)])
200
201 AC_MSG_RESULT([$grub_cv_check_start_symbol])
202
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)])
208
209 AC_MSG_RESULT([$grub_cv_check_uscore_start_symbol])
210
211 AH_TEMPLATE([START_SYMBOL], [Define it to either start or _start])
212
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])
217 else
218 AC_MSG_ERROR([neither start nor _start is defined])
219 fi
220 ])
221
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)])
231
232 AC_MSG_RESULT([$grub_cv_check_uscore_uscore_bss_start_symbol])
233
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)])
239
240 AC_MSG_RESULT([$grub_cv_check_edata_symbol])
241
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)])
247
248 AC_MSG_RESULT([$grub_cv_check_uscore_edata_symbol])
249
250 AH_TEMPLATE([BSS_START_SYMBOL], [Define it to one of __bss_start, edata and _edata])
251
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])
258 else
259 AC_MSG_ERROR([none of __bss_start, edata or _edata is defined])
260 fi
261 ])
262
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)])
272
273 AC_MSG_RESULT([$grub_cv_check_end_symbol])
274
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)])
280
281 AC_MSG_RESULT([$grub_cv_check_uscore_end_symbol])
282
283 AH_TEMPLATE([END_SYMBOL], [Define it to either end or _end])
284
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])
289 else
290 AC_MSG_ERROR([neither end nor _end is defined])
291 fi
292 ])
293
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(
303 [[
304 static int
305 test (int *n)
306 {
307 return *n == -1;
308 }
309
310 static int
311 testfunc (int __attribute__ ((__regparm__ (3))) (*hook) (int a, int b, int *c))
312 {
313 int a = 0;
314 int b = 0;
315 int c = -1;
316 return hook (a, b, &c);
317 }
318
319 int
320 main (void)
321 {
322 int __attribute__ ((__regparm__ (3))) nestedfunc (int a, int b, int *c)
323 {
324 return a == b && test (c);
325 }
326 return testfunc (nestedfunc) ? 0 : 1;
327 }
328 ]])],
329 [grub_cv_i386_check_nested_functions=no],
330 [grub_cv_i386_check_nested_functions=yes])])
331
332 AC_MSG_RESULT([$grub_cv_i386_check_nested_functions])
333
334 if test "x$grub_cv_i386_check_nested_functions" = xyes; then
335 AC_DEFINE([NESTED_FUNC_ATTR],
336 [__attribute__ ((__regparm__ (2)))],
337 [Catch gcc bug])
338 else
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__ (2)))],
343 [Catch gcc bug])
344 fi
345 ])