summaryrefslogtreecommitdiff
path: root/testsuite/tests/rts/linker_error.c
blob: 715eabd184214b14a17cc37e09e1af7e7fe758e4 (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
#include "ghcconfig.h"
#include <stdio.h>
#include <stdlib.h>
#include "Rts.h"
#if defined(mingw32_HOST_OS)
#include <malloc.h>
#endif

#define ITERATIONS 10

typedef int testfun(int);

int main (int argc, char *argv[])
{
    testfun *f;
    int i, r;
#if defined(mingw32_HOST_OS)
    wchar_t *obj;
#else
    char *obj;
#endif

    hs_init(&argc, &argv);

    initLinker_(0);

    // Load object file argv[1] repeatedly

    if (argc != 2) {
        errorBelch("syntax: linker_error <object-file>");
        exit(1);
    }

#if defined(mingw32_HOST_OS)
    size_t len = mbstowcs(NULL, argv[1], 0) + 1;
    if (len == -1) {
        errorBelch("invalid multibyte sequence in argument %d: %s", i, argv[i]);
        exit(1);
    }
    wchar_t *buf = (wchar_t*)_alloca(len * sizeof(wchar_t));
    size_t len2 = mbstowcs(buf, argv[1], len);
    if (len != len2 + 1) {
        errorBelch("something fishy is going on in argument %d: %s", i, argv[i]);
        exit(1);
    }
    obj = buf;
#else
    obj = argv[1];
#endif

    for (i=0; i < ITERATIONS; i++) {
        r = loadObj(obj);
        if (!r) {
            debugBelch("loadObj(%s) failed", obj);
            continue;
        }
        r = resolveObjs();
        if (!r) {
            debugBelch("resolveObjs failed");
            unloadObj(obj);
            continue;
        }
        errorBelch("loading succeeded");
        exit(1);
    }

    hs_exit();
    return 0;
}