Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1836)

Side by Side Diff: src/cmd/ld/symtab.c

Issue 2587041: code review 2587041: 5l, 6l, 8l: link pclntab and symtab as ordinary rodata ... (Closed)
Patch Set: code review 2587041: 5l, 6l, 8l: link pclntab and symtab as ordinary rodata ... Created 14 years, 5 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/cmd/ld/pe.c ('k') | src/libmach/executable.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Inferno utils/6l/span.c
2 // http://code.google.com/p/inferno-os/source/browse/utils/6l/span.c
3 //
4 // Copyright © 1994-1999 Lucent Technologies Inc. All rights reserved.
5 // Portions Copyright © 1995-1997 C H Forsyth (forsyth@terzarima.net)
6 // Portions Copyright © 1997-1999 Vita Nuova Limited
7 // Portions Copyright © 2000-2007 Vita Nuova Holdings Limited (www.vitanuov a.com)
8 // Portions Copyright © 2004,2006 Bruce Ellis
9 // Portions Copyright © 2005-2007 C H Forsyth (forsyth@terzarima.net)
10 // Revisions Copyright © 2000-2007 Lucent Technologies Inc. and others
11 // Portions Copyright © 2009 The Go Authors. All rights reserved.
12 //
13 // Permission is hereby granted, free of charge, to any person obtaining a copy
14 // of this software and associated documentation files (the "Software"), to deal
15 // in the Software without restriction, including without limitation the rights
16 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17 // copies of the Software, and to permit persons to whom the Software is
18 // furnished to do so, subject to the following conditions:
19 //
20 // The above copyright notice and this permission notice shall be included in
21 // all copies or substantial portions of the Software.
22 //
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
29 // THE SOFTWARE.
30
31 // Symbol table.
32
33 #include "l.h"
34 #include "../ld/lib.h"
35 #include "../ld/elf.h"
36
37 char *elfstrdat;
38 int elfstrsize;
39 int maxelfstr;
40 int elftextsh;
41
42 int
43 putelfstr(char *s)
44 {
45 int off, n;
46
47 if(elfstrsize == 0 && s[0] != 0) {
48 // first entry must be empty string
49 putelfstr("");
50 }
51
52 n = strlen(s)+1;
53 if(elfstrsize+n > maxelfstr) {
54 maxelfstr = 2*(elfstrsize+n+(1<<20));
55 elfstrdat = realloc(elfstrdat, maxelfstr);
56 }
57 off = elfstrsize;
58 elfstrsize += n;
59 memmove(elfstrdat+off, s, n);
60 return off;
61 }
62
63 void
64 putelfsymb(char *s, int t, vlong addr, vlong size, int ver, Sym *go)
65 {
66 int bind, type, shndx, stroff;
67 ········
68 bind = STB_GLOBAL;
69 switch(t) {
70 default:
71 return;
72 case 'T':
73 type = STT_FUNC;
74 shndx = elftextsh + 0;
75 break;
76 case 'D':
77 type = STT_OBJECT;
78 shndx = elftextsh + 1;
79 break;
80 case 'B':
81 type = STT_OBJECT;
82 shndx = elftextsh + 2;
83 break;
84 }
85 ········
86 stroff = putelfstr(s);
87 LPUT(stroff); // string
88 cput((bind<<4)|(type&0xF));
89 cput(0);
90 WPUT(shndx);
91 VPUT(addr);
92 VPUT(size);
93 }
94
95 void
96 asmelfsym64(void)
97 {
98 // genasmsym(putelfsymb64);
99 }
100
101 static Sym *symt;
102
103 static void
104 scput(int b)
105 {
106 uchar *p;
107
108 symgrow(symt, symt->size+1);
109 p = symt->p + symt->size;
110 *p = b;
111 symt->size++;
112 }
113
114 static void
115 slputb(int32 v)
116 {
117 uchar *p;
118 ········
119 symgrow(symt, symt->size+4);
120 p = symt->p + symt->size;
121 *p++ = v>>24;
122 *p++ = v>>16;
123 *p++ = v>>8;
124 *p = v;
125 symt->size += 4;
126 }
127
128 void
129 putsymb(Sym *s, char *name, int t, vlong v, vlong size, int ver, Sym *typ)
130 {
131 int i, f, l;
132 Reloc *rel;
133
134 if(t == 'f')
135 name++;
136 l = 4;
137 // if(!debug['8'])
138 // l = 8;
139 if(s != nil) {
140 rel = addrel(symt);
141 rel->siz = l + Rbig;
142 rel->sym = s;
143 rel->type = D_ADDR;
144 rel->off = symt->size;
145 v = 0;
146 }·······
147 if(l == 8)
148 slputb(v>>32);
149 slputb(v);
150 if(ver)
151 t += 'a' - 'A';
152 scput(t+0x80); /* 0x80 is variable length */
153
154 if(t == 'Z' || t == 'z') {
155 scput(name[0]);
156 for(i=1; name[i] != 0 || name[i+1] != 0; i += 2) {
157 scput(name[i]);
158 scput(name[i+1]);
159 }
160 scput(0);
161 scput(0);
162 i++;
163 }
164 else {
165 for(i=0; name[i]; i++)
166 scput(name[i]);
167 scput(0);
168 }
169 if(typ) {
170 if(!typ->reachable)
171 diag("unreachable type %s", typ->name);
172 rel = addrel(symt);
173 rel->siz = l;
174 rel->sym = typ;
175 rel->type = D_ADDR;
176 rel->off = symt->size;
177 }
178 if(l == 8)
179 slputb(0);
180 slputb(0);
181
182 if(debug['n']) {
183 if(t == 'z' || t == 'Z') {
184 Bprint(&bso, "%c %.8llux ", t, v);
185 for(i=1; name[i] != 0 || name[i+1] != 0; i+=2) {
186 f = ((name[i]&0xff) << 8) | (name[i+1]&0xff);
187 Bprint(&bso, "/%x", f);
188 }
189 Bprint(&bso, "\n");
190 return;
191 }
192 if(ver)
193 Bprint(&bso, "%c %.8llux %s<%d> %s\n", t, v, s, ver, typ ? typ->name : "");
194 else
195 Bprint(&bso, "%c %.8llux %s %s\n", t, v, s, typ ? typ->n ame : "");
196 }
197 }
198
199 void
200 symtab(void)
201 {
202 // Define these so that they'll get put into the symbol table.
203 // data.c:/^address will provide the actual values.
204 xdefine("text", STEXT, 0);
205 xdefine("etext", STEXT, 0);
206 xdefine("rodata", SRODATA, 0);
207 xdefine("erodata", SRODATA, 0);
208 xdefine("data", SBSS, 0);
209 xdefine("edata", SBSS, 0);
210 xdefine("end", SBSS, 0);
211 xdefine("epclntab", SRODATA, 0);
212 xdefine("esymtab", SRODATA, 0);
213
214 symt = lookup("symtab", 0);
215 symt->type = SRODATA;
216 symt->size = 0;
217 symt->reachable = 1;
218
219 genasmsym(putsymb);
220 }
OLDNEW
« no previous file with comments | « src/cmd/ld/pe.c ('k') | src/libmach/executable.c » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b