~ubuntu-branches/ubuntu/vivid/golang/vivid

« back to all changes in this revision

Viewing changes to src/cmd/5l/prof.c

  • Committer: Package Import Robot
  • Author(s): Serge Hallyn
  • Date: 2014-11-18 15:12:26 UTC
  • mfrom: (14.2.12 vivid-proposed)
  • Revision ID: package-import@ubuntu.com-20141118151226-zug7vn93mn3dtiz3
Tags: 2:1.3.2-1ubuntu1
* Merge from Debian unstable.  Remaining changes:
  - 016-armhf-elf-header.patch: Use correct ELF header for armhf binaries.
  - Support co-installability with gccgo-go tool:
    - d/rules,golang-go.install: Rename bin/go -> bin/golang-go
    - d/golang-go.{postinst,prerm}: Install/remove /usr/bin/go using
      alternatives.
  - d/copyright: Amendments for full compiliance with copyright format.
  - d/control: Demote golang-go.tools to Suggests to support Ubuntu MIR.
  - dropped patches (now upstream):
    - d/p/issue27650045_40001_50001.diff
    - d/p/issue28050043_60001_70001.diff
    - d/p/issue54790044_100001_110001.diff

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// Inferno utils/5l/obj.c
2
 
// http://code.google.com/p/inferno-os/source/browse/utils/5l/obj.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.vitanuova.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
 
// Profiling.
32
 
 
33
 
#include "l.h"
34
 
#include "../ld/lib.h"
35
 
 
36
 
void
37
 
doprof1(void)
38
 
{
39
 
#ifdef  NOTDEF  // TODO(rsc)
40
 
        Sym *s;
41
 
        int32 n;
42
 
        Prog *p, *q;
43
 
 
44
 
        if(debug['v'])
45
 
                Bprint(&bso, "%5.2f profile 1\n", cputime());
46
 
        Bflush(&bso);
47
 
        s = lookup("__mcount", 0);
48
 
        n = 1;
49
 
        for(p = firstp->link; p != P; p = p->link) {
50
 
                if(p->as == ATEXT) {
51
 
                        q = prg();
52
 
                        q->line = p->line;
53
 
                        q->link = datap;
54
 
                        datap = q;
55
 
                        q->as = ADATA;
56
 
                        q->from.type = D_OREG;
57
 
                        q->from.name = D_EXTERN;
58
 
                        q->from.offset = n*4;
59
 
                        q->from.sym = s;
60
 
                        q->reg = 4;
61
 
                        q->to = p->from;
62
 
                        q->to.type = D_CONST;
63
 
 
64
 
                        q = prg();
65
 
                        q->line = p->line;
66
 
                        q->pc = p->pc;
67
 
                        q->link = p->link;
68
 
                        p->link = q;
69
 
                        p = q;
70
 
                        p->as = AMOVW;
71
 
                        p->from.type = D_OREG;
72
 
                        p->from.name = D_EXTERN;
73
 
                        p->from.sym = s;
74
 
                        p->from.offset = n*4 + 4;
75
 
                        p->to.type = D_REG;
76
 
                        p->to.reg = REGTMP;
77
 
 
78
 
                        q = prg();
79
 
                        q->line = p->line;
80
 
                        q->pc = p->pc;
81
 
                        q->link = p->link;
82
 
                        p->link = q;
83
 
                        p = q;
84
 
                        p->as = AADD;
85
 
                        p->from.type = D_CONST;
86
 
                        p->from.offset = 1;
87
 
                        p->to.type = D_REG;
88
 
                        p->to.reg = REGTMP;
89
 
 
90
 
                        q = prg();
91
 
                        q->line = p->line;
92
 
                        q->pc = p->pc;
93
 
                        q->link = p->link;
94
 
                        p->link = q;
95
 
                        p = q;
96
 
                        p->as = AMOVW;
97
 
                        p->from.type = D_REG;
98
 
                        p->from.reg = REGTMP;
99
 
                        p->to.type = D_OREG;
100
 
                        p->to.name = D_EXTERN;
101
 
                        p->to.sym = s;
102
 
                        p->to.offset = n*4 + 4;
103
 
 
104
 
                        n += 2;
105
 
                        continue;
106
 
                }
107
 
        }
108
 
        q = prg();
109
 
        q->line = 0;
110
 
        q->link = datap;
111
 
        datap = q;
112
 
 
113
 
        q->as = ADATA;
114
 
        q->from.type = D_OREG;
115
 
        q->from.name = D_EXTERN;
116
 
        q->from.sym = s;
117
 
        q->reg = 4;
118
 
        q->to.type = D_CONST;
119
 
        q->to.offset = n;
120
 
 
121
 
        s->type = SBSS;
122
 
        s->value = n*4;
123
 
#endif
124
 
}
125
 
 
126
 
void
127
 
doprof2(void)
128
 
{
129
 
        Sym *s2, *s4;
130
 
        Prog *p, *q, *ps2, *ps4;
131
 
 
132
 
        if(debug['v'])
133
 
                Bprint(&bso, "%5.2f profile 2\n", cputime());
134
 
        Bflush(&bso);
135
 
        s2 = lookup("_profin", 0);
136
 
        s4 = lookup("_profout", 0);
137
 
        if(s2->type != STEXT || s4->type != STEXT) {
138
 
                diag("_profin/_profout not defined");
139
 
                return;
140
 
        }
141
 
        ps2 = P;
142
 
        ps4 = P;
143
 
        for(cursym = textp; cursym != nil; cursym = cursym->next) {
144
 
                p = cursym->text;
145
 
                if(cursym == s2) {
146
 
                        ps2 = p;
147
 
                        p->reg = 1;
148
 
                }
149
 
                if(cursym == s4) {
150
 
                        ps4 = p;
151
 
                        p->reg = 1;
152
 
                }
153
 
        }
154
 
        for(cursym = textp; cursym != nil; cursym = cursym->next)
155
 
        for(p = cursym->text; p != P; p = p->link) {
156
 
                if(p->as == ATEXT) {
157
 
                        if(p->reg & NOPROF) {
158
 
                                for(;;) {
159
 
                                        q = p->link;
160
 
                                        if(q == P)
161
 
                                                break;
162
 
                                        if(q->as == ATEXT)
163
 
                                                break;
164
 
                                        p = q;
165
 
                                }
166
 
                                continue;
167
 
                        }
168
 
 
169
 
                        /*
170
 
                         * BL   profin, R2
171
 
                         */
172
 
                        q = prg();
173
 
                        q->line = p->line;
174
 
                        q->pc = p->pc;
175
 
                        q->link = p->link;
176
 
                        p->link = q;
177
 
                        p = q;
178
 
                        p->as = ABL;
179
 
                        p->to.type = D_BRANCH;
180
 
                        p->cond = ps2;
181
 
                        p->to.sym = s2;
182
 
 
183
 
                        continue;
184
 
                }
185
 
                if(p->as == ARET) {
186
 
                        /*
187
 
                         * RET
188
 
                         */
189
 
                        q = prg();
190
 
                        q->as = ARET;
191
 
                        q->from = p->from;
192
 
                        q->to = p->to;
193
 
                        q->link = p->link;
194
 
                        p->link = q;
195
 
 
196
 
                        /*
197
 
                         * BL   profout
198
 
                         */
199
 
                        p->as = ABL;
200
 
                        p->from = zprg.from;
201
 
                        p->to = zprg.to;
202
 
                        p->to.type = D_BRANCH;
203
 
                        p->cond = ps4;
204
 
                        p->to.sym = s4;
205
 
 
206
 
                        p = q;
207
 
 
208
 
                        continue;
209
 
                }
210
 
        }
211
 
}