Last change
on this file since 675 was
444,
checked in by satin@…, 7 years ago
|
add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc
|
File size:
1.3 KB
|
Line | |
---|
1 | /* Code to byte-swap static constructor/destructor tables on |
---|
2 | broken a.out little-endian targets. The startup code should call |
---|
3 | __fix_ctors just before calling main. It is safe to use on non-broken |
---|
4 | or big-endian targets. */ |
---|
5 | |
---|
6 | extern long __CTOR_LIST__[]; |
---|
7 | extern long __DTOR_LIST__[]; |
---|
8 | |
---|
9 | static void |
---|
10 | byte_swap (long *entry) |
---|
11 | { |
---|
12 | unsigned char *p = (unsigned char *)entry; |
---|
13 | unsigned char tmp; |
---|
14 | |
---|
15 | tmp = p[0]; |
---|
16 | p[0] = p[3]; |
---|
17 | p[3] = tmp; |
---|
18 | tmp = p[1]; |
---|
19 | p[1] = p[2]; |
---|
20 | p[2] = tmp; |
---|
21 | } |
---|
22 | |
---|
23 | static void |
---|
24 | fix_table (long *table) |
---|
25 | { |
---|
26 | long len = table[0]; |
---|
27 | |
---|
28 | /* The heuristic for deciding if a table is broken is to examine |
---|
29 | the word at the start of the table, which contains the number |
---|
30 | of function pointers immediately following. If the low word |
---|
31 | is zero, and the high word is non-zero, it's very likely that |
---|
32 | it is byte-swapped. This test will fail if the program has |
---|
33 | an exact multiple of 64K static constructors or destructors, a very |
---|
34 | unlikely situation. */ |
---|
35 | if ((len & 0xffff) == 0 && (len & 0xffff0000) != 0) |
---|
36 | { |
---|
37 | |
---|
38 | /* The table looks broken. Byte-swap all the words in the table, up |
---|
39 | to a NULL entry, which marks the end of the table. */ |
---|
40 | do |
---|
41 | { |
---|
42 | byte_swap (table); |
---|
43 | table++; |
---|
44 | } |
---|
45 | while (*table); |
---|
46 | } |
---|
47 | } |
---|
48 | |
---|
49 | void |
---|
50 | __fix_ctors (void) |
---|
51 | { |
---|
52 | fix_table (__CTOR_LIST__); |
---|
53 | fix_table (__DTOR_LIST__); |
---|
54 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.