1 /* go-backend.c -- Go frontend interface to gcc backend.
2 Copyright (C) 2010-2017 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
22 #include "coretypes.h"
27 #include "diagnostic.h"
28 #include "simple-object.h"
29 #include "stor-layout.h"
31 #include "output.h" /* for assemble_string */
32 #include "common/common-target.h"
35 /* The segment name we pass to simple_object_start_read to find Go
38 #ifndef GO_EXPORT_SEGMENT_NAME
39 #define GO_EXPORT_SEGMENT_NAME "__GNU_GO"
42 /* The section name we use when reading and writing export data. */
44 #ifndef GO_EXPORT_SECTION_NAME
45 #define GO_EXPORT_SECTION_NAME ".go_export"
48 /* This file holds all the cases where the Go frontend needs
49 information from gcc's backend. */
51 /* Return whether or not GCC has reported any errors. */
56 return errorcount
!= 0 || sorrycount
!= 0;
59 /* Return the alignment in bytes of a struct field of type T. */
62 go_field_alignment (tree t
)
68 #ifdef BIGGEST_FIELD_ALIGNMENT
69 if (v
> BIGGEST_FIELD_ALIGNMENT
)
70 v
= BIGGEST_FIELD_ALIGNMENT
;
73 #ifdef ADJUST_FIELD_ALIGN
74 v
= ADJUST_FIELD_ALIGN (NULL_TREE
, t
, v
);
77 return v
/ BITS_PER_UNIT
;
80 /* This is called by the Go frontend proper if the unsafe package was
81 imported. When that happens we can not do type-based alias
85 go_imported_unsafe (void)
87 flag_strict_aliasing
= false;
89 /* Let the backend know that the options have changed. */
90 targetm
.override_options_after_change ();
93 /* This is called by the Go frontend proper to add data to the
94 section containing Go export data. */
97 go_write_export_data (const char *bytes
, unsigned int size
)
103 gcc_assert (targetm_common
.have_named_sections
);
104 sec
= get_section (GO_EXPORT_SECTION_NAME
, SECTION_DEBUG
, NULL
);
107 switch_to_section (sec
);
108 assemble_string (bytes
, size
);
111 /* The go_read_export_data function is called by the Go frontend
112 proper to read Go export data from an object file. FD is a file
113 descriptor open for reading. OFFSET is the offset within the file
114 where the object file starts; this will be 0 except when reading an
115 archive. On success this returns NULL and sets *PBUF to a buffer
116 allocated using malloc, of size *PLEN, holding the export data. If
117 the data is not found, this returns NULL and sets *PBUF to NULL and
118 *PLEN to 0. If some error occurs, this returns an error message
119 and sets *PERR to an errno value or 0 if there is no relevant
123 go_read_export_data (int fd
, off_t offset
, char **pbuf
, size_t *plen
,
126 simple_object_read
*sobj
;
137 sobj
= simple_object_start_read (fd
, offset
, GO_EXPORT_SEGMENT_NAME
,
141 /* If we get an error here, just pretend that we didn't find any
142 export data. This is the right thing to do if the error is
143 that the file was not recognized as an object file. This
144 will ignore file I/O errors, but it's not too big a deal
145 because we will wind up giving some other error later. */
149 found
= simple_object_find_section (sobj
, GO_EXPORT_SECTION_NAME
,
150 &sec_offset
, &sec_length
,
152 simple_object_release_read (sobj
);
156 if (lseek (fd
, offset
+ sec_offset
, SEEK_SET
) < 0)
159 return _("lseek failed while reading export data");
162 buf
= XNEWVEC (char, sec_length
);
166 return _("memory allocation failed while reading export data");
169 c
= read (fd
, buf
, sec_length
);
174 return _("read failed while reading export data");
180 return _("short read while reading export data");