]> git.wh0rd.org - patches.git/blob - nasm-elf-visibility.patch
sync vapier-m
[patches.git] / nasm-elf-visibility.patch
1 Index: output/outelf32.c
2 ===================================================================
3 RCS file: /cvsroot/nasm/nasm/output/outelf32.c,v
4 retrieving revision 1.3
5 diff -u -p -r1.3 outelf32.c
6 --- output/outelf32.c 29 Apr 2007 20:57:53 -0000 1.3
7 +++ output/outelf32.c 6 Jul 2007 05:33:12 -0000
8 @@ -51,6 +51,7 @@ struct Symbol {
9 int32_t strpos; /* string table position of name */
10 int32_t section; /* section ID of the symbol */
11 int type; /* symbol type */
12 + int other; /* symbol visibility */
13 int32_t value; /* address, or COMMON variable align */
14 int32_t size; /* size of symbol */
15 int32_t globnum; /* symbol table offset if global */
16 @@ -115,9 +116,15 @@ extern struct ofmt of_elf;
17
18 #define SYM_SECTION 0x04
19 #define SYM_GLOBAL 0x10
20 +#define SYM_NOTYPE 0x00
21 #define SYM_DATA 0x01
22 #define SYM_FUNCTION 0x02
23
24 +#define STV_DEFAULT 0
25 +#define STV_INTERNAL 1
26 +#define STV_HIDDEN 2
27 +#define STV_PROTECTED 3
28 +
29 #define GLOBAL_TEMP_BASE 16 /* bigger than any constant sym id */
30
31 #define SEG_ALIGN 16 /* alignment of sections in file */
32 @@ -495,6 +502,7 @@ static void elf_deflabel(char *name, int
33
34 sym->strpos = pos;
35 sym->type = is_global ? SYM_GLOBAL : 0;
36 + sym->other = STV_DEFAULT;
37 sym->size = 0;
38 if (segment == NO_SEG)
39 sym->section = SHN_ABS;
40 @@ -566,17 +574,38 @@ static void elf_deflabel(char *name, int
41 sects[sym->section - 1]->gsyms = sym;
42
43 if (special) {
44 - int n = strcspn(special, " ");
45 + int n = strcspn(special, " \t");
46
47 if (!nasm_strnicmp(special, "function", n))
48 sym->type |= SYM_FUNCTION;
49 else if (!nasm_strnicmp(special, "data", n) ||
50 !nasm_strnicmp(special, "object", n))
51 sym->type |= SYM_DATA;
52 + else if (!nasm_strnicmp(special, "notype", n))
53 + sym->type |= SYM_NOTYPE;
54 else
55 error(ERR_NONFATAL, "unrecognised symbol type `%.*s'",
56 n, special);
57 - if (special[n]) {
58 + special += n;
59 +
60 + while (isspace(*special))
61 + ++special;
62 + if (*special) {
63 + n = strcspn(special, " \t");
64 + if (!nasm_strnicmp(special, "default", n))
65 + sym->other = STV_DEFAULT;
66 + else if (!nasm_strnicmp(special, "internal", n))
67 + sym->other = STV_INTERNAL;
68 + else if (!nasm_strnicmp(special, "hidden", n))
69 + sym->other = STV_HIDDEN;
70 + else if (!nasm_strnicmp(special, "protected", n))
71 + sym->other = STV_PROTECTED;
72 + else
73 + n = 0;
74 + special += n;
75 + }
76 +
77 + if (*special) {
78 struct tokenval tokval;
79 expr *e;
80 int fwd = FALSE;
81 @@ -1115,7 +1144,8 @@ static struct SAA *elf_build_symtab(int3
82 WRITELONG(p, sym->strpos);
83 WRITELONG(p, sym->value);
84 WRITELONG(p, sym->size);
85 - WRITESHORT(p, sym->type); /* local non-typed thing */
86 + WRITECHAR(p, sym->type); /* local non-typed thing */
87 + WRITECHAR(p, sym->other);
88 WRITESHORT(p, sym->section);
89 saa_wbytes(s, entry, 16L);
90 *len += 16;
91 @@ -1133,7 +1163,8 @@ static struct SAA *elf_build_symtab(int3
92 WRITELONG(p, sym->strpos);
93 WRITELONG(p, sym->value);
94 WRITELONG(p, sym->size);
95 - WRITESHORT(p, sym->type); /* global non-typed thing */
96 + WRITECHAR(p, sym->type); /* global non-typed thing */
97 + WRITECHAR(p, sym->other);
98 WRITESHORT(p, sym->section);
99 saa_wbytes(s, entry, 16L);
100 *len += 16;
101 Index: output/outelf64.c
102 ===================================================================
103 RCS file: /cvsroot/nasm/nasm/output/outelf64.c,v
104 retrieving revision 1.4
105 diff -u -p -r1.4 outelf64.c
106 --- output/outelf64.c 4 May 2007 18:47:16 -0000 1.4
107 +++ output/outelf64.c 6 Jul 2007 05:33:13 -0000
108 @@ -71,6 +71,7 @@ struct Symbol {
109 int32_t strpos; /* string table position of name */
110 int32_t section; /* section ID of the symbol */
111 int type; /* symbol type */
112 + int other; /* symbol visibility */
113 int32_t value; /* address, or COMMON variable align */
114 int32_t size; /* size of symbol */
115 int32_t globnum; /* symbol table offset if global */
116 @@ -126,9 +127,15 @@ extern struct ofmt of_elf64;
117
118 #define SYM_SECTION 0x04
119 #define SYM_GLOBAL 0x10
120 +#define SYM_NOTYPE 0x00
121 #define SYM_DATA 0x01
122 #define SYM_FUNCTION 0x02
123
124 +#define STV_DEFAULT 0
125 +#define STV_INTERNAL 1
126 +#define STV_HIDDEN 2
127 +#define STV_PROTECTED 3
128 +
129 #define GLOBAL_TEMP_BASE 16 /* bigger than any constant sym id */
130
131 #define SEG_ALIGN 16 /* alignment of sections in file */
132 @@ -507,6 +514,7 @@ static void elf_deflabel(char *name, int
133
134 sym->strpos = pos;
135 sym->type = is_global ? SYM_GLOBAL : 0;
136 + sym->other = STV_DEFAULT;
137 sym->size = 0;
138 if (segment == NO_SEG)
139 sym->section = SHN_ABS;
140 @@ -578,17 +586,38 @@ static void elf_deflabel(char *name, int
141 sects[sym->section - 1]->gsyms = sym;
142
143 if (special) {
144 - int n = strcspn(special, " ");
145 + int n = strcspn(special, " \t");
146
147 if (!nasm_strnicmp(special, "function", n))
148 sym->type |= SYM_FUNCTION;
149 else if (!nasm_strnicmp(special, "data", n) ||
150 !nasm_strnicmp(special, "object", n))
151 sym->type |= SYM_DATA;
152 + else if (!nasm_strnicmp(special, "notype", n))
153 + sym->type |= SYM_NOTYPE;
154 else
155 error(ERR_NONFATAL, "unrecognised symbol type `%.*s'",
156 n, special);
157 - if (special[n]) {
158 + special += n;
159 +
160 + while (isspace(*special))
161 + ++special;
162 + if (*special) {
163 + n = strcspn(special, " \t");
164 + if (!nasm_strnicmp(special, "default", n))
165 + sym->other = STV_DEFAULT;
166 + else if (!nasm_strnicmp(special, "internal", n))
167 + sym->other = STV_INTERNAL;
168 + else if (!nasm_strnicmp(special, "hidden", n))
169 + sym->other = STV_HIDDEN;
170 + else if (!nasm_strnicmp(special, "protected", n))
171 + sym->other = STV_PROTECTED;
172 + else
173 + n = 0;
174 + special += n;
175 + }
176 +
177 + if (*special) {
178 struct tokenval tokval;
179 expr *e;
180 int fwd = FALSE;
181 @@ -1127,7 +1156,8 @@ static struct SAA *elf_build_symtab(int3
182 continue;
183 p = entry;
184 WRITELONG(p, sym->strpos);
185 - WRITESHORT(p, sym->type); /* local non-typed thing */
186 + WRITECHAR(p, sym->type); /* local non-typed thing */
187 + WRITECHAR(p, sym->other);
188 WRITESHORT(p, sym->section);
189 WRITEDLONG(p, (int64_t)sym->value);
190 WRITEDLONG(p, (int64_t)sym->size);
191 @@ -1145,7 +1175,8 @@ static struct SAA *elf_build_symtab(int3
192 continue;
193 p = entry;
194 WRITELONG(p, sym->strpos);
195 - WRITESHORT(p, sym->type); /* global non-typed thing */
196 + WRITECHAR(p, sym->type); /* global non-typed thing */
197 + WRITECHAR(p, sym->other);
198 WRITESHORT(p, sym->section);
199 WRITEDLONG(p, (int64_t)sym->value);
200 WRITEDLONG(p, (int64_t)sym->size);
201 Index: doc/nasmdoc.src
202 ===================================================================
203 RCS file: /cvsroot/nasm/nasm/doc/nasmdoc.src,v
204 retrieving revision 1.83
205 diff -u -p -r1.83 nasmdoc.src
206 --- doc/nasmdoc.src 4 May 2007 02:16:08 -0000 1.83
207 +++ doc/nasmdoc.src 6 Jul 2007 18:35:30 -0000
208 @@ -4408,6 +4408,13 @@ object by suffixing the name with a colo
209 exports the global symbol \c{hashlookup} as a function and
210 \c{hashtable} as a data object.
211
212 +Optionally, you can control the ELF visibility of the symbol. Just
213 +add one of the visibility keywords: \i\c{default}, \i\c{internal},
214 +\i\c{hidden}, or \i\c{protected}. The default is \i\c{default} of
215 +course. For example, to make \c{hashlookup} hidden:
216 +
217 +\c global hashlookup:function hidden
218 +
219 You can also specify the size of the data associated with the
220 symbol, as a numeric expression (which may involve labels, and even
221 forward references) after the type specifier. Like this: