]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/config/mips/irix6-libc-compat.c
Merge basic-improvements-branch to trunk
[thirdparty/gcc.git] / gcc / config / mips / irix6-libc-compat.c
1 /* Compensate for inconsistent structure passing conventions on IRIX 6. */
2 /* Compile this one with gcc. */
3 /* Copyright (C) 2001 Free Software Foundation, Inc.
4
5 This file is part of GNU CC.
6
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 In addition to the permissions in the GNU General Public License, the
13 Free Software Foundation gives you unlimited permission to link the
14 compiled version of this file into combinations with other programs,
15 and to distribute those combinations without any restriction coming
16 from the use of this file. (The General Public License restrictions
17 do apply in other respects; for example, they cover modification of
18 the file, and distribution when not linked into a combine
19 executable.)
20
21 GNU CC is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 GNU General Public License for more details.
25
26 You should have received a copy of the GNU General Public License
27 along with GNU CC; see the file COPYING. If not, write to
28 the Free Software Foundation, 59 Temple Place - Suite 330,
29 Boston, MA 02111-1307, USA. */
30
31 /* GCC doesn't correctly implement the structure and union passing and return
32 conventions of the N32 and N64 ABIs on IRIX 6, as described in the
33 MIPSpro N32 ABI Handbook, ch. 2, Calling Convention Implementations, p.7.
34 The ABI requires that structures (or trailing parts of structures) smaller
35 than 8 bytes (a 64-bit register) are left-justified, whereas GCC
36 right-justifies them.
37
38 While GCC is internally consistent, calling routines compiled with a
39 compiler that does implement the documented ABI (like SGIs MIPSpro C
40 compiler) doesn't work. This is primarily an issue for system libraries
41 like libc. Fortunately, there exist only very few routines that take
42 structure value arguments or return structures by value, so until the
43 underlying bug is fixed, it is possible to work around it by providing
44 wrapper functions for the few affected routines that compensate for the
45 inconsistent alignment.
46
47 These wrappers rely on the fact that e.g. libc contains weak versions of
48 those routines, and the real implementation is provided by _-prefixed
49 variants. So we can provide our own versions, which will only be linked
50 if the application uses any of the affected functions, calling the private
51 variants after shifting the arguments or results as required.
52
53 This is a rewrite of code created by Andy Polyakov. */
54
55 #include "config.h"
56 #include "system.h"
57 #include "coretypes.h"
58 #include "tm.h"
59
60 /* This must only be used for the N32 and N64 ABIs. O32 is correct. */
61
62 #if _MIPS_SIM == _ABIN32 || _MIPS_SIM == _ABI64
63
64 /* The affected arguments need to be shifted by
65
66 BITS_PER_WORD - (sizeof (arg) * BITS_PER_UNIT).
67
68 Since only 32-bit args and results are involved, the shift count is
69 always 32. */
70 #define SHIFT_BITS 32
71
72 extern machreg_t inet_ntoa PARAMS ((machreg_t));
73 extern machreg_t inet_lnaof PARAMS ((machreg_t));
74 extern machreg_t inet_netof PARAMS ((machreg_t));
75 extern machreg_t inet_makeaddr PARAMS ((machreg_t, machreg_t));
76
77 extern machreg_t _inet_ntoa PARAMS ((machreg_t));
78 extern machreg_t _inet_lnaof PARAMS ((machreg_t));
79 extern machreg_t _inet_netof PARAMS ((machreg_t));
80 extern machreg_t _inet_makeaddr PARAMS ((machreg_t, machreg_t));
81
82 /* <arpa/inet.h> has
83
84 char *inet_ntoa (struct in_addr);
85
86 on both IRIX 6.2 and 6.5, with struct in_addr containing a 32-bit int. */
87
88 machreg_t
89 inet_ntoa (machreg_t in)
90 {
91 return _inet_ntoa (in << SHIFT_BITS);
92 }
93
94 /* <arpa/inet.h> has
95
96 unsigned long inet_lnaof (struct in_addr); (IRIX 6.2)
97 in_addr_t inet_lnaof (struct in_addr); (IRIX 6.5)
98
99 in_addr_t is a 32-bit int. */
100
101 machreg_t
102 inet_lnaof (machreg_t in)
103 {
104 return _inet_lnaof (in << SHIFT_BITS);
105 }
106
107 /* <arpa/inet.h> has
108
109 unsigned long inet_netof (struct in_addr); (IRIX 6.2)
110 in_addr_t inet_netof (struct in_addr); (IRIX 6.5) */
111
112 machreg_t
113 inet_netof (machreg_t in)
114 {
115 return _inet_netof (in << SHIFT_BITS);
116 }
117
118 /* <arpa/inet.h> has
119
120 struct in_addr inet_makeaddr (int, int); (IRIX 6.2)
121 struct in_addr inet_makeaddr (in_addr_t, in_addr_t); (IRIX 6.5) */
122
123 machreg_t
124 inet_makeaddr (machreg_t net, machreg_t lna)
125 {
126 return _inet_makeaddr (net, lna) >> SHIFT_BITS;
127 }
128
129 #if _MIPS_SIM == _ABIN32
130 extern machreg_t semctl PARAMS ((machreg_t, machreg_t, machreg_t, machreg_t));
131 extern machreg_t _semctl PARAMS ((machreg_t, machreg_t, machreg_t, machreg_t));
132
133 /* <sys/sem.h> has
134
135 int semctl (int, int, int, ...);
136
137 where the variadic argument is union semun if used. union semun contains
138 an int and two pointers, so the union is already 64 bits wide under the
139 N64 ABI and alignment is not an issue. */
140
141 machreg_t
142 semctl (machreg_t semid, machreg_t semnum, machreg_t cmd, machreg_t arg)
143 {
144 return _semctl(semid, semnum, cmd, arg << SHIFT_BITS);
145 }
146 #endif /* _ABIN32 */
147
148 #endif /* _ABIN32 || _ABI64 */