1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/build/unix/elfhack/test.c Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,162 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +#ifdef DEF 1.9 +DEF(This) 1.10 +DEF(is) 1.11 +DEF(a) 1.12 +DEF(test) 1.13 +DEF(of) 1.14 +DEF(string) 1.15 +DEF(array) 1.16 +DEF(for) 1.17 +DEF(use) 1.18 +DEF(with) 1.19 +DEF(elfhack) 1.20 +DEF(to) 1.21 +DEF(see) 1.22 +DEF(whether) 1.23 +DEF(it) 1.24 +DEF(breaks) 1.25 +DEF(anything) 1.26 +DEF(but) 1.27 +DEF(one) 1.28 +DEF(needs) 1.29 +DEF(quite) 1.30 +DEF(some) 1.31 +DEF(strings) 1.32 +DEF(before) 1.33 +DEF(the) 1.34 +DEF(program) 1.35 +DEF(can) 1.36 +DEF(do) 1.37 +DEF(its) 1.38 +DEF(work) 1.39 +DEF(efficiently) 1.40 +DEF(Without) 1.41 +DEF(enough) 1.42 +DEF(data) 1.43 +DEF(relocation) 1.44 +DEF(sections) 1.45 +DEF(are) 1.46 +DEF(not) 1.47 +DEF(sufficiently) 1.48 +DEF(large) 1.49 +DEF(and) 1.50 +DEF(injected) 1.51 +DEF(code) 1.52 +DEF(wouldnt) 1.53 +DEF(fit) 1.54 +DEF(Said) 1.55 +DEF(otherwise) 1.56 +DEF(we) 1.57 +DEF(need) 1.58 +DEF(more) 1.59 +DEF(words) 1.60 +DEF(than) 1.61 +DEF(up) 1.62 +DEF(here) 1.63 +DEF(so) 1.64 +DEF(that) 1.65 +DEF(relocations) 1.66 +DEF(take) 1.67 +DEF(significant) 1.68 +DEF(bytes) 1.69 +DEF(amounts) 1.70 +DEF(which) 1.71 +DEF(isnt) 1.72 +DEF(exactly) 1.73 +DEF(easily) 1.74 +DEF(achieved) 1.75 +DEF(like) 1.76 +DEF(this) 1.77 +DEF(Actually) 1.78 +DEF(I) 1.79 +DEF(must) 1.80 +DEF(cheat) 1.81 +DEF(by) 1.82 +DEF(including) 1.83 +DEF(these) 1.84 +DEF(phrases) 1.85 +DEF(several) 1.86 +DEF(times) 1.87 + 1.88 +#else 1.89 +#pragma GCC visibility push(default) 1.90 +#include <stdlib.h> 1.91 +#include <stdio.h> 1.92 + 1.93 +#define DEF(w) static const char str_ ## w[] = #w; 1.94 +#include "test.c" 1.95 +#undef DEF 1.96 + 1.97 +const char *strings[] = { 1.98 +#define DEF(w) str_ ## w, 1.99 +#include "test.c" 1.100 +#include "test.c" 1.101 +#include "test.c" 1.102 +}; 1.103 + 1.104 +/* Create a hole between two zones of relative relocations */ 1.105 +const int hole[] = { 1.106 + 42, 42, 42, 42 1.107 +}; 1.108 + 1.109 +const char *strings2[] = { 1.110 +#include "test.c" 1.111 +#include "test.c" 1.112 +#include "test.c" 1.113 +#include "test.c" 1.114 +#include "test.c" 1.115 +#undef DEF 1.116 +}; 1.117 + 1.118 +static int ret = 1; 1.119 + 1.120 +int print_status() { 1.121 + fprintf(stderr, "%s\n", ret ? "FAIL" : "PASS"); 1.122 + return ret; 1.123 +} 1.124 + 1.125 +/* On ARM, this creates a .tbss section before .init_array, which 1.126 + * elfhack could then pick instead of .init_array. 1.127 + * Also, when .tbss is big enough, elfhack may wrongfully consider 1.128 + * following sections as part of the PT_TLS segment. 1.129 + * Finally, gold makes TLS segments end on an aligned virtual address, 1.130 + * even when the underlying section ends before that, and elfhack 1.131 + * sanity checks may yield an error. */ 1.132 +__thread int foo; 1.133 +__thread long long int bar[512]; 1.134 + 1.135 +void end_test() { 1.136 + static int count = 0; 1.137 + /* Only exit when both constructors have been called */ 1.138 + if (++count == 2) 1.139 + ret = 0; 1.140 +} 1.141 + 1.142 +void test() { 1.143 + int i = 0, j = 0; 1.144 +#define DEF_(a,i,w) \ 1.145 + if (a[i++] != str_ ## w) return; 1.146 +#define DEF(w) DEF_(strings,i,w) 1.147 +#include "test.c" 1.148 +#include "test.c" 1.149 +#include "test.c" 1.150 +#undef DEF 1.151 +#define DEF(w) DEF_(strings2,j,w) 1.152 +#include "test.c" 1.153 +#include "test.c" 1.154 +#include "test.c" 1.155 +#include "test.c" 1.156 +#include "test.c" 1.157 +#undef DEF 1.158 + if (i != sizeof(strings)/sizeof(strings[0]) && 1.159 + j != sizeof(strings2)/sizeof(strings2[0])) 1.160 + fprintf(stderr, "WARNING: Test doesn't cover the whole array\n"); 1.161 + end_test(); 1.162 +} 1.163 + 1.164 +#pragma GCC visibility pop 1.165 +#endif