annotate gcc/go/go-backend.c @ 158:494b0b89df80 default tip

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 25 May 2020 18:13:55 +0900
parents 1830386684a0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 /* go-backend.c -- Go frontend interface to gcc backend.
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2 Copyright (C) 2010-2020 Free Software Foundation, Inc.
111
kono
parents:
diff changeset
3
kono
parents:
diff changeset
4 This file is part of GCC.
kono
parents:
diff changeset
5
kono
parents:
diff changeset
6 GCC is free software; you can redistribute it and/or modify it under
kono
parents:
diff changeset
7 the terms of the GNU General Public License as published by the Free
kono
parents:
diff changeset
8 Software Foundation; either version 3, or (at your option) any later
kono
parents:
diff changeset
9 version.
kono
parents:
diff changeset
10
kono
parents:
diff changeset
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
kono
parents:
diff changeset
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
kono
parents:
diff changeset
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
kono
parents:
diff changeset
14 for more details.
kono
parents:
diff changeset
15
kono
parents:
diff changeset
16 You should have received a copy of the GNU General Public License
kono
parents:
diff changeset
17 along with GCC; see the file COPYING3. If not see
kono
parents:
diff changeset
18 <http://www.gnu.org/licenses/>. */
kono
parents:
diff changeset
19
kono
parents:
diff changeset
20 #include "config.h"
kono
parents:
diff changeset
21 #include "system.h"
kono
parents:
diff changeset
22 #include "coretypes.h"
kono
parents:
diff changeset
23 #include "target.h"
kono
parents:
diff changeset
24 #include "tree.h"
kono
parents:
diff changeset
25 #include "memmodel.h"
kono
parents:
diff changeset
26 #include "tm_p.h"
kono
parents:
diff changeset
27 #include "diagnostic.h"
kono
parents:
diff changeset
28 #include "simple-object.h"
kono
parents:
diff changeset
29 #include "stor-layout.h"
kono
parents:
diff changeset
30 #include "intl.h"
kono
parents:
diff changeset
31 #include "output.h" /* for assemble_string */
kono
parents:
diff changeset
32 #include "common/common-target.h"
kono
parents:
diff changeset
33 #include "go-c.h"
kono
parents:
diff changeset
34
kono
parents:
diff changeset
35 /* The segment name we pass to simple_object_start_read to find Go
kono
parents:
diff changeset
36 export data. */
kono
parents:
diff changeset
37
kono
parents:
diff changeset
38 #ifndef GO_EXPORT_SEGMENT_NAME
kono
parents:
diff changeset
39 #define GO_EXPORT_SEGMENT_NAME "__GNU_GO"
kono
parents:
diff changeset
40 #endif
kono
parents:
diff changeset
41
kono
parents:
diff changeset
42 /* The section name we use when reading and writing export data. */
kono
parents:
diff changeset
43
kono
parents:
diff changeset
44 #ifndef GO_EXPORT_SECTION_NAME
kono
parents:
diff changeset
45 #define GO_EXPORT_SECTION_NAME ".go_export"
kono
parents:
diff changeset
46 #endif
kono
parents:
diff changeset
47
kono
parents:
diff changeset
48 #ifndef TARGET_AIX
kono
parents:
diff changeset
49 #define TARGET_AIX 0
kono
parents:
diff changeset
50 #endif
kono
parents:
diff changeset
51
kono
parents:
diff changeset
52 /* This file holds all the cases where the Go frontend needs
kono
parents:
diff changeset
53 information from gcc's backend. */
kono
parents:
diff changeset
54
kono
parents:
diff changeset
55 /* Return whether or not GCC has reported any errors. */
kono
parents:
diff changeset
56
kono
parents:
diff changeset
57 bool
kono
parents:
diff changeset
58 saw_errors (void)
kono
parents:
diff changeset
59 {
kono
parents:
diff changeset
60 return errorcount != 0 || sorrycount != 0;
kono
parents:
diff changeset
61 }
kono
parents:
diff changeset
62
kono
parents:
diff changeset
63 /* Return the alignment in bytes of a struct field of type T. */
kono
parents:
diff changeset
64
kono
parents:
diff changeset
65 unsigned int
kono
parents:
diff changeset
66 go_field_alignment (tree t)
kono
parents:
diff changeset
67 {
kono
parents:
diff changeset
68 unsigned int v;
kono
parents:
diff changeset
69
kono
parents:
diff changeset
70 v = TYPE_ALIGN (t);
kono
parents:
diff changeset
71
kono
parents:
diff changeset
72 #ifdef BIGGEST_FIELD_ALIGNMENT
kono
parents:
diff changeset
73 if (v > BIGGEST_FIELD_ALIGNMENT)
kono
parents:
diff changeset
74 v = BIGGEST_FIELD_ALIGNMENT;
kono
parents:
diff changeset
75 #endif
kono
parents:
diff changeset
76
kono
parents:
diff changeset
77 #ifdef ADJUST_FIELD_ALIGN
kono
parents:
diff changeset
78 v = ADJUST_FIELD_ALIGN (NULL_TREE, t, v);
kono
parents:
diff changeset
79 #endif
kono
parents:
diff changeset
80
kono
parents:
diff changeset
81 return v / BITS_PER_UNIT;
kono
parents:
diff changeset
82 }
kono
parents:
diff changeset
83
kono
parents:
diff changeset
84 /* This is called by the Go frontend proper if the unsafe package was
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
85 imported. When that happens we cannot do type-based alias
111
kono
parents:
diff changeset
86 analysis. */
kono
parents:
diff changeset
87
kono
parents:
diff changeset
88 void
kono
parents:
diff changeset
89 go_imported_unsafe (void)
kono
parents:
diff changeset
90 {
kono
parents:
diff changeset
91 flag_strict_aliasing = false;
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
92 TREE_OPTIMIZATION (optimization_default_node)->x_flag_strict_aliasing = false;
111
kono
parents:
diff changeset
93
kono
parents:
diff changeset
94 /* Let the backend know that the options have changed. */
kono
parents:
diff changeset
95 targetm.override_options_after_change ();
kono
parents:
diff changeset
96 }
kono
parents:
diff changeset
97
kono
parents:
diff changeset
98 /* This is called by the Go frontend proper to add data to the
kono
parents:
diff changeset
99 section containing Go export data. */
kono
parents:
diff changeset
100
kono
parents:
diff changeset
101 void
kono
parents:
diff changeset
102 go_write_export_data (const char *bytes, unsigned int size)
kono
parents:
diff changeset
103 {
kono
parents:
diff changeset
104 static section* sec;
kono
parents:
diff changeset
105
kono
parents:
diff changeset
106 if (sec == NULL)
kono
parents:
diff changeset
107 {
kono
parents:
diff changeset
108 gcc_assert (targetm_common.have_named_sections);
kono
parents:
diff changeset
109 sec = get_section (GO_EXPORT_SECTION_NAME,
kono
parents:
diff changeset
110 TARGET_AIX ? SECTION_EXCLUDE : SECTION_DEBUG,
kono
parents:
diff changeset
111 NULL);
kono
parents:
diff changeset
112 }
kono
parents:
diff changeset
113
kono
parents:
diff changeset
114 switch_to_section (sec);
kono
parents:
diff changeset
115 assemble_string (bytes, size);
kono
parents:
diff changeset
116 }
kono
parents:
diff changeset
117
kono
parents:
diff changeset
118 /* The go_read_export_data function is called by the Go frontend
kono
parents:
diff changeset
119 proper to read Go export data from an object file. FD is a file
kono
parents:
diff changeset
120 descriptor open for reading. OFFSET is the offset within the file
kono
parents:
diff changeset
121 where the object file starts; this will be 0 except when reading an
kono
parents:
diff changeset
122 archive. On success this returns NULL and sets *PBUF to a buffer
kono
parents:
diff changeset
123 allocated using malloc, of size *PLEN, holding the export data. If
kono
parents:
diff changeset
124 the data is not found, this returns NULL and sets *PBUF to NULL and
kono
parents:
diff changeset
125 *PLEN to 0. If some error occurs, this returns an error message
kono
parents:
diff changeset
126 and sets *PERR to an errno value or 0 if there is no relevant
kono
parents:
diff changeset
127 errno. */
kono
parents:
diff changeset
128
kono
parents:
diff changeset
129 const char *
kono
parents:
diff changeset
130 go_read_export_data (int fd, off_t offset, char **pbuf, size_t *plen,
kono
parents:
diff changeset
131 int *perr)
kono
parents:
diff changeset
132 {
kono
parents:
diff changeset
133 simple_object_read *sobj;
kono
parents:
diff changeset
134 const char *errmsg;
kono
parents:
diff changeset
135 off_t sec_offset;
kono
parents:
diff changeset
136 off_t sec_length;
kono
parents:
diff changeset
137 int found;
kono
parents:
diff changeset
138 char *buf;
kono
parents:
diff changeset
139 ssize_t c;
kono
parents:
diff changeset
140
kono
parents:
diff changeset
141 *pbuf = NULL;
kono
parents:
diff changeset
142 *plen = 0;
kono
parents:
diff changeset
143
kono
parents:
diff changeset
144 sobj = simple_object_start_read (fd, offset, GO_EXPORT_SEGMENT_NAME,
kono
parents:
diff changeset
145 &errmsg, perr);
kono
parents:
diff changeset
146 if (sobj == NULL)
kono
parents:
diff changeset
147 {
kono
parents:
diff changeset
148 /* If we get an error here, just pretend that we didn't find any
kono
parents:
diff changeset
149 export data. This is the right thing to do if the error is
kono
parents:
diff changeset
150 that the file was not recognized as an object file. This
kono
parents:
diff changeset
151 will ignore file I/O errors, but it's not too big a deal
kono
parents:
diff changeset
152 because we will wind up giving some other error later. */
kono
parents:
diff changeset
153 return NULL;
kono
parents:
diff changeset
154 }
kono
parents:
diff changeset
155
kono
parents:
diff changeset
156 found = simple_object_find_section (sobj, GO_EXPORT_SECTION_NAME,
kono
parents:
diff changeset
157 &sec_offset, &sec_length,
kono
parents:
diff changeset
158 &errmsg, perr);
kono
parents:
diff changeset
159 simple_object_release_read (sobj);
kono
parents:
diff changeset
160 if (!found)
kono
parents:
diff changeset
161 return errmsg;
kono
parents:
diff changeset
162
kono
parents:
diff changeset
163 if (lseek (fd, offset + sec_offset, SEEK_SET) < 0)
kono
parents:
diff changeset
164 {
kono
parents:
diff changeset
165 *perr = errno;
kono
parents:
diff changeset
166 return _("lseek failed while reading export data");
kono
parents:
diff changeset
167 }
kono
parents:
diff changeset
168
kono
parents:
diff changeset
169 buf = XNEWVEC (char, sec_length);
kono
parents:
diff changeset
170 if (buf == NULL)
kono
parents:
diff changeset
171 {
kono
parents:
diff changeset
172 *perr = errno;
kono
parents:
diff changeset
173 return _("memory allocation failed while reading export data");
kono
parents:
diff changeset
174 }
kono
parents:
diff changeset
175
kono
parents:
diff changeset
176 c = read (fd, buf, sec_length);
kono
parents:
diff changeset
177 if (c < 0)
kono
parents:
diff changeset
178 {
kono
parents:
diff changeset
179 *perr = errno;
kono
parents:
diff changeset
180 free (buf);
kono
parents:
diff changeset
181 return _("read failed while reading export data");
kono
parents:
diff changeset
182 }
kono
parents:
diff changeset
183
kono
parents:
diff changeset
184 if (c < sec_length)
kono
parents:
diff changeset
185 {
kono
parents:
diff changeset
186 free (buf);
kono
parents:
diff changeset
187 return _("short read while reading export data");
kono
parents:
diff changeset
188 }
kono
parents:
diff changeset
189
kono
parents:
diff changeset
190 *pbuf = buf;
kono
parents:
diff changeset
191 *plen = sec_length;
kono
parents:
diff changeset
192
kono
parents:
diff changeset
193 return NULL;
kono
parents:
diff changeset
194 }