summaryrefslogtreecommitdiff
path: root/m4/check_for_gold_t22266.m4
blob: e540eb928b6004bdd04df90c74fc3873b1db61b0 (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
# CHECK_FOR_GOLD_T22266
# ----------------------
#
# Test for binutils #22266. This bug manifested as GHC bug #14328 (see also:
# #14675, #14291).
# Uses test from
# https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=033bfb739b525703bfe23f151d09e9beee3a2afe
#
# $1 = linker to test
# Sets $result to 0 if not affected, 1 otherwise
AC_DEFUN([CHECK_FOR_GOLD_T22266],[
    AC_MSG_CHECKING([for ld.gold object merging bug (binutils 22266)])
    if ! $1 --version | grep -q "GNU gold" 2>/dev/null; then
        # Not gold
        result=0
    elif test "$cross_compiling" = "yes"; then
        AC_MSG_RESULT([cross-compiling, assuming LD can merge objects correctly.])
        result=0
    else
        FPTOOLS_WRITE_FILE([conftest.a.c], [
          __attribute__((section(".data.a")))
          static int int_from_a_1 = 0x11223344;

          __attribute__((section(".data.rel.ro.a")))
          int *p_int_from_a_2 = &int_from_a_1;

          const char *hello (void);

          const char *
          hello (void)
          {
            return "XXXHello, world!" + 3;
          }
        ])

        FPTOOLS_WRITE_FILE([conftest.main.c], [
          #include <stdlib.h>
          #include <string.h>

          extern int *p_int_from_a_2;
          extern const char *hello (void);

          int main (void) {
            if (*p_int_from_a_2 != 0x11223344)
              abort ();
            if (strcmp(hello(), "Hello, world!") != 0)
              abort ();
            return 0;
          }
        ])

        FPTOOLS_WRITE_FILE([conftest.t], [
          SECTIONS
          {
              .text : {
                  *(.text*)
              }
              .rodata :
              {
                  *(.rodata .rodata.* .gnu.linkonce.r.*)
              }
              .data.rel.ro : {
                  *(.data.rel.ro*)
              }
              .data : {
                  *(.data*)
              }
              .bss : {
                  *(.bss*)
              }
          }
        ])

        $CC -c -o conftest.a.o conftest.a.c || AC_MSG_ERROR([Failed to compile test])
        $MergeObjsCmd $MergeObjsArgs -T conftest.t conftest.a.o -o conftest.ar.o || AC_MSG_ERROR([Failed to merge test object])

        $CC -c -o conftest.main.o conftest.main.c || AC_MSG_ERROR([Failed to compile test driver])
        $CC conftest.ar.o conftest.main.o -o conftest || AC_MSG_ERROR([Failed to link test driver])

        if ./conftest; then
            AC_MSG_RESULT([not affected])
            result=0
        else
            AC_MSG_RESULT([affected])
            result=1
        fi
        rm -f conftest.a.o conftest.a.c  conttest.ar.o conftest.main.c conftest.main.o conftest
    fi
])