]>
Commit | Line | Data |
---|---|---|
4b13b216 | 1 | dnl grub_ASM_USCORE checks if C symbols get an underscore after |
6a161fa9 | 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. | |
4b13b216 | 5 | AC_DEFUN(grub_ASM_USCORE, |
6a161fa9 | 6 | [AC_REQUIRE([AC_PROG_CC]) |
7 | AC_MSG_CHECKING([if C symbols get an underscore after compilation]) | |
4b13b216 | 8 | AC_CACHE_VAL(grub_cv_asm_uscore, |
6a161fa9 | 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 | |
4b13b216 | 25 | grub_cv_asm_uscore=yes |
6a161fa9 | 26 | else |
4b13b216 | 27 | grub_cv_asm_uscore=no |
6a161fa9 | 28 | fi |
29 | ||
30 | rm -f conftest*]) | |
31 | ||
4b13b216 | 32 | if test "x$grub_cv_asm_uscore" = xyes; then |
33 | AC_DEFINE_UNQUOTED([HAVE_ASM_USCORE], $grub_cv_asm_uscore, | |
6a161fa9 | 34 | [Define if C symbols get an underscore after compilation]) |
35 | fi | |
36 | ||
4b13b216 | 37 | AC_MSG_RESULT([$grub_cv_asm_uscore]) |
6a161fa9 | 38 | ]) |
39 | ||
40 | ||
41 | dnl Some versions of `objcopy -O binary' vary their output depending | |
42 | dnl on the link address. | |
4b13b216 | 43 | AC_DEFUN(grub_PROG_OBJCOPY_ABSOLUTE, |
6a161fa9 | 44 | [AC_MSG_CHECKING([whether ${OBJCOPY} works for absolute addresses]) |
4b13b216 | 45 | AC_CACHE_VAL(grub_cv_prog_objcopy_absolute, |
6a161fa9 | 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 | |
4b13b216 | 58 | grub_cv_prog_objcopy_absolute=yes |
6a161fa9 | 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 | |
4b13b216 | 71 | grub_cv_prog_objcopy_absolute=no |
6a161fa9 | 72 | break |
73 | fi | |
74 | done | |
75 | rm -f conftest*]) | |
4b13b216 | 76 | AC_MSG_RESULT([$grub_cv_prog_objcopy_absolute]) |
6a161fa9 | 77 | |
4b13b216 | 78 | if test "x$grub_cv_prog_objcopy_absolute" = xno; then |
79 | AC_MSG_ERROR([GRUB requires a working absolute objcopy; upgrade your binutils]) | |
6a161fa9 | 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. | |
4b13b216 | 97 | AC_DEFUN(grub_I386_ASM_ADDR32, |
6a161fa9 | 98 | [AC_REQUIRE([AC_PROG_CC]) |
4b13b216 | 99 | AC_REQUIRE([grub_I386_ASM_PREFIX_REQUIREMENT]) |
6a161fa9 | 100 | AC_MSG_CHECKING([for .code16 addr32 assembler support]) |
4b13b216 | 101 | AC_CACHE_VAL(grub_cv_i386_asm_addr32, |
6a161fa9 | 102 | [cat > conftest.s.in <<\EOF |
103 | .code16 | |
104 | l1: @ADDR32@ movb %al, l1 | |
105 | EOF | |
106 | ||
4b13b216 | 107 | if test "x$grub_cv_i386_asm_prefix_requirement" = xyes; then |
6a161fa9 | 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 | |
4b13b216 | 114 | grub_cv_i386_asm_addr32=yes |
6a161fa9 | 115 | else |
4b13b216 | 116 | grub_cv_i386_asm_addr32=no |
6a161fa9 | 117 | fi |
118 | ||
119 | rm -f conftest*]) | |
120 | ||
4b13b216 | 121 | AC_MSG_RESULT([$grub_cv_i386_asm_addr32])]) |
6a161fa9 | 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. | |
4b13b216 | 127 | AC_DEFUN(grub_I386_ASM_PREFIX_REQUIREMENT, |
6a161fa9 | 128 | [AC_REQUIRE([AC_PROG_CC]) |
129 | AC_MSG_CHECKING(dnl | |
130 | [whether addr32 must be in the same line as the instruction]) | |
4b13b216 | 131 | AC_CACHE_VAL(grub_cv_i386_asm_prefix_requirement, |
6a161fa9 | 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 | |
4b13b216 | 138 | grub_cv_i386_asm_prefix_requirement=yes |
6a161fa9 | 139 | else |
4b13b216 | 140 | grub_cv_i386_asm_prefix_requirement=no |
6a161fa9 | 141 | fi |
142 | ||
143 | rm -f conftest*]) | |
144 | ||
4b13b216 | 145 | if test "x$grub_cv_i386_asm_prefix_requirement" = xyes; then |
146 | grub_tmp_addr32="addr32" | |
147 | grub_tmp_data32="data32" | |
6a161fa9 | 148 | else |
4b13b216 | 149 | grub_tmp_addr32="addr32;" |
150 | grub_tmp_data32="data32;" | |
6a161fa9 | 151 | fi |
152 | ||
4b13b216 | 153 | AC_DEFINE_UNQUOTED([ADDR32], $grub_tmp_addr32, |
6a161fa9 | 154 | [Define it to \"addr32\" or \"addr32;\" to make GAS happy]) |
4b13b216 | 155 | AC_DEFINE_UNQUOTED([DATA32], $grub_tmp_data32, |
6a161fa9 | 156 | [Define it to \"data32\" or \"data32;\" to make GAS happy]) |
157 | ||
4b13b216 | 158 | AC_MSG_RESULT([$grub_cv_i386_asm_prefix_requirement])]) |
6a161fa9 | 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. | |
4b13b216 | 163 | AC_DEFUN(grub_I386_ASM_ABSOLUTE_WITHOUT_ASTERISK, |
6a161fa9 | 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]) | |
4b13b216 | 167 | AC_CACHE_VAL(grub_cv_i386_asm_absolute_without_asterisk, |
6a161fa9 | 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 | |
4b13b216 | 176 | grub_cv_i386_asm_absolute_without_asterisk=no |
6a161fa9 | 177 | else |
4b13b216 | 178 | grub_cv_i386_asm_absolute_without_asterisk=yes |
6a161fa9 | 179 | fi |
180 | ||
181 | rm -f conftest*]) | |
182 | ||
4b13b216 | 183 | if test "x$grub_cv_i386_asm_absolute_without_asterisk" = xyes; then |
6a161fa9 | 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 | ||
4b13b216 | 188 | AC_MSG_RESULT([$grub_cv_i386_asm_absolute_without_asterisk])]) |
6a161fa9 | 189 | |
190 | ||
191 | dnl Check what symbol is defined as a start symbol. | |
192 | dnl Written by Yoshinori K. Okuji. | |
4b13b216 | 193 | AC_DEFUN(grub_CHECK_START_SYMBOL, |
6a161fa9 | 194 | [AC_REQUIRE([AC_PROG_CC]) |
195 | AC_MSG_CHECKING([if start is defined by the compiler]) | |
4b13b216 | 196 | AC_CACHE_VAL(grub_cv_check_start_symbol, |
6a161fa9 | 197 | [AC_TRY_LINK([], [asm ("incl start")], |
4b13b216 | 198 | grub_cv_check_start_symbol=yes, |
199 | grub_cv_check_start_symbol=no)]) | |
6a161fa9 | 200 | |
4b13b216 | 201 | AC_MSG_RESULT([$grub_cv_check_start_symbol]) |
6a161fa9 | 202 | |
203 | AC_MSG_CHECKING([if _start is defined by the compiler]) | |
4b13b216 | 204 | AC_CACHE_VAL(grub_cv_check_uscore_start_symbol, |
6a161fa9 | 205 | [AC_TRY_LINK([], [asm ("incl _start")], |
4b13b216 | 206 | grub_cv_check_uscore_start_symbol=yes, |
207 | grub_cv_check_uscore_start_symbol=no)]) | |
6a161fa9 | 208 | |
4b13b216 | 209 | AC_MSG_RESULT([$grub_cv_check_uscore_start_symbol]) |
6a161fa9 | 210 | |
211 | AH_TEMPLATE([START_SYMBOL], [Define it to either start or _start]) | |
212 | ||
4b13b216 | 213 | if test "x$grub_cv_check_start_symbol" = xyes; then |
6a161fa9 | 214 | AC_DEFINE([START_SYMBOL], [start]) |
4b13b216 | 215 | elif test "x$grub_cv_check_uscore_start_symbol" = xyes; then |
6a161fa9 | 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. | |
4b13b216 | 224 | AC_DEFUN(grub_CHECK_BSS_START_SYMBOL, |
6a161fa9 | 225 | [AC_REQUIRE([AC_PROG_CC]) |
226 | AC_MSG_CHECKING([if __bss_start is defined by the compiler]) | |
4b13b216 | 227 | AC_CACHE_VAL(grub_cv_check_uscore_uscore_bss_start_symbol, |
6a161fa9 | 228 | [AC_TRY_LINK([], [asm ("incl __bss_start")], |
4b13b216 | 229 | grub_cv_check_uscore_uscore_bss_start_symbol=yes, |
230 | grub_cv_check_uscore_uscore_bss_start_symbol=no)]) | |
6a161fa9 | 231 | |
4b13b216 | 232 | AC_MSG_RESULT([$grub_cv_check_uscore_uscore_bss_start_symbol]) |
6a161fa9 | 233 | |
234 | AC_MSG_CHECKING([if edata is defined by the compiler]) | |
4b13b216 | 235 | AC_CACHE_VAL(grub_cv_check_edata_symbol, |
6a161fa9 | 236 | [AC_TRY_LINK([], [asm ("incl edata")], |
4b13b216 | 237 | grub_cv_check_edata_symbol=yes, |
238 | grub_cv_check_edata_symbol=no)]) | |
6a161fa9 | 239 | |
4b13b216 | 240 | AC_MSG_RESULT([$grub_cv_check_edata_symbol]) |
6a161fa9 | 241 | |
242 | AC_MSG_CHECKING([if _edata is defined by the compiler]) | |
4b13b216 | 243 | AC_CACHE_VAL(grub_cv_check_uscore_edata_symbol, |
6a161fa9 | 244 | [AC_TRY_LINK([], [asm ("incl _edata")], |
4b13b216 | 245 | grub_cv_check_uscore_edata_symbol=yes, |
246 | grub_cv_check_uscore_edata_symbol=no)]) | |
6a161fa9 | 247 | |
4b13b216 | 248 | AC_MSG_RESULT([$grub_cv_check_uscore_edata_symbol]) |
6a161fa9 | 249 | |
250 | AH_TEMPLATE([BSS_START_SYMBOL], [Define it to one of __bss_start, edata and _edata]) | |
251 | ||
4b13b216 | 252 | if test "x$grub_cv_check_uscore_uscore_bss_start_symbol" = xyes; then |
6a161fa9 | 253 | AC_DEFINE([BSS_START_SYMBOL], [__bss_start]) |
4b13b216 | 254 | elif test "x$grub_cv_check_edata_symbol" = xyes; then |
6a161fa9 | 255 | AC_DEFINE([BSS_START_SYMBOL], [edata]) |
4b13b216 | 256 | elif test "x$grub_cv_check_uscore_edata_symbol" = xyes; then |
6a161fa9 | 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. | |
4b13b216 | 265 | AC_DEFUN(grub_CHECK_END_SYMBOL, |
6a161fa9 | 266 | [AC_REQUIRE([AC_PROG_CC]) |
267 | AC_MSG_CHECKING([if end is defined by the compiler]) | |
4b13b216 | 268 | AC_CACHE_VAL(grub_cv_check_end_symbol, |
6a161fa9 | 269 | [AC_TRY_LINK([], [asm ("incl end")], |
4b13b216 | 270 | grub_cv_check_end_symbol=yes, |
271 | grub_cv_check_end_symbol=no)]) | |
6a161fa9 | 272 | |
4b13b216 | 273 | AC_MSG_RESULT([$grub_cv_check_end_symbol]) |
6a161fa9 | 274 | |
275 | AC_MSG_CHECKING([if _end is defined by the compiler]) | |
4b13b216 | 276 | AC_CACHE_VAL(grub_cv_check_uscore_end_symbol, |
6a161fa9 | 277 | [AC_TRY_LINK([], [asm ("incl _end")], |
4b13b216 | 278 | grub_cv_check_uscore_end_symbol=yes, |
279 | grub_cv_check_uscore_end_symbol=no)]) | |
6a161fa9 | 280 | |
4b13b216 | 281 | AC_MSG_RESULT([$grub_cv_check_uscore_end_symbol]) |
6a161fa9 | 282 | |
283 | AH_TEMPLATE([END_SYMBOL], [Define it to either end or _end]) | |
284 | ||
4b13b216 | 285 | if test "x$grub_cv_check_end_symbol" = xyes; then |
6a161fa9 | 286 | AC_DEFINE([END_SYMBOL], [end]) |
4b13b216 | 287 | elif test "x$grub_cv_check_uscore_end_symbol" = xyes; then |
6a161fa9 | 288 | AC_DEFINE([END_SYMBOL], [_end]) |
289 | else | |
290 | AC_MSG_ERROR([neither end nor _end is defined]) | |
291 | fi | |
292 | ]) | |
5aded270 | 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. | |
4b13b216 | 298 | AC_DEFUN(grub_I386_CHECK_REGPARM_BUG, |
5aded270 | 299 | [AC_REQUIRE([AC_PROG_CC]) |
300 | AC_MSG_CHECKING([if GCC has the regparm=3 bug]) | |
4b13b216 | 301 | AC_CACHE_VAL(grub_cv_i386_check_nested_functions, |
5aded270 | 302 | [AC_RUN_IFELSE([AC_LANG_SOURCE( |
e9c6f39b | 303 | [[ |
304 | static int | |
305 | test (int *n) | |
306 | { | |
307 | return *n == -1; | |
308 | } | |
5aded270 | 309 | |
e9c6f39b | 310 | static int |
311 | testfunc (int __attribute__ ((__regparm__ (3))) (*hook) (int a, int b, int *c)) | |
5aded270 | 312 | { |
e9c6f39b | 313 | int a = 0; |
314 | int b = 0; | |
315 | int c = -1; | |
316 | return hook (a, b, &c); | |
317 | } | |
5aded270 | 318 | |
e9c6f39b | 319 | int |
320 | main (void) | |
321 | { | |
322 | int __attribute__ ((__regparm__ (3))) nestedfunc (int a, int b, int *c) | |
5aded270 | 323 | { |
e9c6f39b | 324 | return a == b && test (c); |
5aded270 | 325 | } |
e9c6f39b | 326 | return testfunc (nestedfunc) ? 0 : 1; |
5aded270 | 327 | } |
328 | ]])], | |
e9c6f39b | 329 | [grub_cv_i386_check_nested_functions=no], |
330 | [grub_cv_i386_check_nested_functions=yes])]) | |
5aded270 | 331 | |
4b13b216 | 332 | AC_MSG_RESULT([$grub_cv_i386_check_nested_functions]) |
5aded270 | 333 | |
4b13b216 | 334 | if test "x$grub_cv_i386_check_nested_functions" = xyes; then |
5aded270 | 335 | AC_DEFINE([NESTED_FUNC_ATTR], |
336 | [__attribute__ ((__regparm__ (2)))], | |
337 | [Catch gcc bug]) | |
338 | else | |
e9c6f39b | 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]) | |
5aded270 | 344 | fi |
345 | ]) |