binutils-gdb/include/simple-object.h

216 lines
8.3 KiB
C
Raw Normal View History

2010-11-02 23:20:47 +08:00
/* simple-object.h -- simple routines to read and write object files
Copyright (C) 2010-2023 Free Software Foundation, Inc.
2010-11-02 23:20:47 +08:00
Written by Ian Lance Taylor, Google.
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, or (at your option) any
later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, 51 Franklin Street - Fifth Floor,
Boston, MA 02110-1301, USA. */
#ifndef SIMPLE_OBJECT_H
#define SIMPLE_OBJECT_H
#include <stddef.h>
#include <sys/types.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef __cplusplus
extern "C" {
#endif
/* This header file provides four types with associated functions.
They are used to read and write object files. This is a minimal
interface, intended to support the needs of gcc without bringing in
all the power and complexity of BFD. */
/* The type simple_object_read * is used to read an existing object
file. */
typedef struct simple_object_read_struct simple_object_read;
/* Create an simple_object_read given DESCRIPTOR, an open file
descriptor, and OFFSET, an offset within the file. The offset is
for use with archives, and should be 0 for an ordinary object file.
The descriptor must remain open until done with the returned
simple_object_read. SEGMENT_NAME is used on Mach-O and is required
on that platform: it means to only look at sections within the
segment with that name. It is ignored for other object file
formats. On error, this function returns NULL, and sets *ERRMSG to
an error string and sets *ERR to an errno value or 0 if there is no
relevant errno. */
extern simple_object_read *
simple_object_start_read (int descriptor, off_t offset,
const char *segment_name, const char **errmsg,
int *err);
/* Call PFN for each section in SIMPLE_OBJECT, passing it the section
name, offset within the file of the section contents, and length of
the section contents. The offset within the file is relative to
the offset passed to simple_object_start_read. The DATA argument
to simple_object_find_sections is passed on to PFN. If PFN returns
0, the loop is stopped and simple_object_find_sections returns. If
PFN returns non-zero, the loop continues. On success this returns
NULL. On error it returns an error string, and sets *ERR to an
errno value or 0 if there is no relevant errno. */
extern const char *
simple_object_find_sections (simple_object_read *simple_object,
int (*pfn) (void *data, const char *,
off_t offset, off_t length),
void *data,
int *err);
/* Look for the section NAME in SIMPLE_OBJECT. This returns
information for the first section NAME in SIMPLE_OBJECT. Note that
calling this multiple times is inefficient; use
simple_object_find_sections instead.
If found, return 1 and set *OFFSET to the offset in the file of the
section contents and set *LENGTH to the length of the section
contents. *OFFSET will be relative to the offset passed to
simple_object_start_read.
If the section is not found, and no error occurs, return 0 and set
*ERRMSG to NULL.
If an error occurs, return 0, set *ERRMSG to an error message, and
set *ERR to an errno value or 0 if there is no relevant errno. */
extern int
simple_object_find_section (simple_object_read *simple_object,
const char *name, off_t *offset, off_t *length,
const char **errmsg, int *err);
/* Release all resources associated with SIMPLE_OBJECT. This does not
close the file descriptor. */
extern void
simple_object_release_read (simple_object_read *);
/* The type simple_object_attributes holds the attributes of an object
file that matter for creating a file or ensuring that two files are
compatible. This is a set of magic numbers. */
typedef struct simple_object_attributes_struct simple_object_attributes;
/* Fetch the attributes of SIMPLE_OBJECT. This information will
persist until simple_object_attributes_release is called, even if
SIMPLE_OBJECT is closed. On error this returns NULL, sets *ERRMSG
to an error message, and sets *ERR to an errno value or 0 if there
isn't one. */
extern simple_object_attributes *
simple_object_fetch_attributes (simple_object_read *simple_object,
const char **errmsg, int *err);
2010-11-17 10:03:43 +08:00
/* Merge the FROM attributes into TO. If two objects with these
attributes could be linked together without error, returns NULL.
Otherwise, returns an error message, and sets *ERR to an errno
value or 0 if there isn't one. */
2010-11-02 23:20:47 +08:00
extern const char *
2010-11-17 10:03:43 +08:00
simple_object_attributes_merge (simple_object_attributes *to,
simple_object_attributes *from,
int *err);
2010-11-02 23:20:47 +08:00
/* Release all resources associated with ATTRS. */
extern void
simple_object_release_attributes (simple_object_attributes *attrs);
/* The type simple_object_write is used to create a new object file. */
typedef struct simple_object_write_struct simple_object_write;
/* Start creating a new object file which is like ATTRS. You must
fetch attribute information from an existing object file before you
can create a new one. There is currently no support for creating
an object file de novo. The segment name is only used on Mach-O,
where it is required. It means that all sections are created
within that segment. It is ignored for other object file formats.
On error this function returns NULL, sets *ERRMSG to an error
message, and sets *ERR to an errno value or 0 if there isn't
one. */
extern simple_object_write *
simple_object_start_write (simple_object_attributes *attrs,
const char *segment_name,
const char **errmsg, int *err);
/* The type simple_object_write_section is a handle for a section
which is being written. */
typedef struct simple_object_write_section_struct simple_object_write_section;
/* Add a section to SIMPLE_OBJECT. NAME is the name of the new
section. ALIGN is the required alignment expressed as the number
of required low-order 0 bits (e.g., 2 for alignment to a 32-bit
boundary). The section is created as containing data, readable,
not writable, not executable, not loaded at runtime. On error this
returns NULL, sets *ERRMSG to an error message, and sets *ERR to an
errno value or 0 if there isn't one. */
extern simple_object_write_section *
simple_object_write_create_section (simple_object_write *simple_object,
const char *name, unsigned int align,
const char **errmsg, int *err);
/* Add data BUFFER/SIZE to SECTION in SIMPLE_OBJECT. If COPY is
non-zero, the data will be copied into memory if necessary. If
COPY is zero, BUFFER must persist until SIMPLE_OBJECT is released.
On success this returns NULL. On error this returns an error
message, and sets *ERR to an errno value or 0 if there isn't
one. */
extern const char *
simple_object_write_add_data (simple_object_write *simple_object,
simple_object_write_section *section,
const void *buffer, size_t size,
int copy, int *err);
/* Write the complete object file to DESCRIPTOR, an open file
descriptor. This returns NULL on success. On error this returns
an error message, and sets *ERR to an errno value or 0 if there
isn't one. */
extern const char *
simple_object_write_to_file (simple_object_write *simple_object,
int descriptor, int *err);
/* Release all resources associated with SIMPLE_OBJECT, including any
simple_object_write_section's that may have been created. */
extern void
simple_object_release_write (simple_object_write *);
Sync libiberty/ & include/ with GCC Note this brings in the interface files for libcc1/G++ as well, which we will be needing in GDB soon anyway. That commit renamed a method in the C interface and that required a small update to GDB's compile/ code, which I've included that in this patch to keep the tree building. include/ChangeLog: 2017-09-15 Pedro Alves <palves@redhat.com> * ansidecl.h (DISABLE_COPY_AND_ASSIGN): New macro. 2017-09-12 Jiong Wang <jiong.wang@arm.com> * dwarf2.def (DW_CFA_AARCH64_negate_ra_state): New DW_CFA_DUP. * dwarf2.h (DW_CFA_DUP): New define. 2017-08-21 Richard Biener <rguenther@suse.de> * simple-object.h (simple_object_copy_lto_debug_sections): New function. 2017-05-18 Martin Liska <mliska@suse.cz> * ansidecl.h: Define CONSTEXPR macro. 2017-05-24 Nathan Sidwell <nathan@acm.org> * libiberty.h (ASTRDUP): Adjust cast to avoid warning. 2017-01-30 Alexandre Oliva <aoliva@redhat.com> Introduce C++ support in libcc1. * gcc-c-fe.def (int_type_v0): Rename from... (int_type): ... this. Introduce new version. (float_type_v0): Rename from... (float_type): ... this. Introduce new version. (char_type): New. * gcc-c-interface.h (gcc_c_api_version): Add GCC_C_FE_VERSION_1. (gcc_type_array): Move... * gcc-interface.h: ... here. * gcc-cp-fe.def: New. * gcc-cp-interface.h: New. 2016-04-29 Oleg Endo <olegendo@gcc.gnu.org> * longlong.h (umul_ppmm): Remove SHMEDIA checks. (__umulsidi3, count_leading_zeros): Remove SHMEDIA implementations. 2017-09-15 Yao Qi <yao.qi@linaro.org> Pedro Alves <palves@redhat.com> * ansidecl.h (DISABLE_COPY_AND_ASSIGN): New macro. 2017-09-12 Jiong Wang <jiong.wang@arm.com> * dwarf2.def (DW_CFA_AARCH64_negate_ra_state): New DW_CFA_DUP. * dwarf2.h (DW_CFA_DUP): New define. 2017-08-21 Richard Biener <rguenther@suse.de> * simple-object.h (simple_object_copy_lto_debug_sections): New function. 2017-05-18 Martin Liska <mliska@suse.cz> * ansidecl.h: Define CONSTEXPR macro. 2017-05-24 Nathan Sidwell <nathan@acm.org> * libiberty.h (ASTRDUP): Adjust cast to avoid warning. 2017-01-30 Alexandre Oliva <aoliva@redhat.com> Introduce C++ support in libcc1. * gcc-c-fe.def (int_type_v0): Rename from... (int_type): ... this. Introduce new version. (float_type_v0): Rename from... (float_type): ... this. Introduce new version. (char_type): New. * gcc-c-interface.h (gcc_c_api_version): Add GCC_C_FE_VERSION_1. (gcc_type_array): Move... * gcc-interface.h: ... here. * gcc-cp-fe.def: New. * gcc-cp-interface.h: New. 2016-04-29 Oleg Endo <olegendo@gcc.gnu.org> * longlong.h (umul_ppmm): Remove SHMEDIA checks. (__umulsidi3, count_leading_zeros): Remove SHMEDIA implementations. libiberty/ChangeLog: 2017-09-15 Nathan Sidwell <nathan@acm.org> PR demangler/82195 * cp-demangle.c (d_name): Add 'toplevel' parm. Pass to ... (d_local_name): ... here. Parse trailing function args on nested local_name. (d_encoding, d_special_name, d_class_enum_type): Adjust d_name calls. * testsuite/demangle-expected: Add tests. 2017-09-15 Richard Biener <rguenther@suse.de> PR lto/81968 * simple-object-elf.c (simple_object_elf_copy_lto_debug_sections): Iterate marking dependent sections necessary. 2017-09-15 Nathan Sidwell <nathan@acm.org> * cp-demangle.c (is_fnqual_component_type): Reimplement using FNQUAL_COMPONENT_CASE. (d_encoding): Hold bare_function_type in local var. (d_local_name): Build name in both cases and build result once. Collapse switch-if to single conditional. (d_local_name): * testsuite/demangle-expected: Realign blank lines with tests. 2017-09-12 Jiong Wang <jiong.wang@arm.com> * dwarfnames.c (DW_CFA_DUP): New define. gdb/ChangeLog: 2017-09-15 Pedro Alves <palves@redhat.com> * compile/compile-c-types.c (convert_enum, convert_int) (convert_float): Adjust to refer to int_type_v0 and float_type_v0.
2017-09-16 00:40:33 +08:00
/* Copy LTO debug sections from SRC_OBJECT to DEST.
If RENAME is true, rename LTO debug section into debug section (i.e.
when producing final binary) and if it is false, keep the sections with
original names (when incrementally linking).
Sync libiberty/ & include/ with GCC Note this brings in the interface files for libcc1/G++ as well, which we will be needing in GDB soon anyway. That commit renamed a method in the C interface and that required a small update to GDB's compile/ code, which I've included that in this patch to keep the tree building. include/ChangeLog: 2017-09-15 Pedro Alves <palves@redhat.com> * ansidecl.h (DISABLE_COPY_AND_ASSIGN): New macro. 2017-09-12 Jiong Wang <jiong.wang@arm.com> * dwarf2.def (DW_CFA_AARCH64_negate_ra_state): New DW_CFA_DUP. * dwarf2.h (DW_CFA_DUP): New define. 2017-08-21 Richard Biener <rguenther@suse.de> * simple-object.h (simple_object_copy_lto_debug_sections): New function. 2017-05-18 Martin Liska <mliska@suse.cz> * ansidecl.h: Define CONSTEXPR macro. 2017-05-24 Nathan Sidwell <nathan@acm.org> * libiberty.h (ASTRDUP): Adjust cast to avoid warning. 2017-01-30 Alexandre Oliva <aoliva@redhat.com> Introduce C++ support in libcc1. * gcc-c-fe.def (int_type_v0): Rename from... (int_type): ... this. Introduce new version. (float_type_v0): Rename from... (float_type): ... this. Introduce new version. (char_type): New. * gcc-c-interface.h (gcc_c_api_version): Add GCC_C_FE_VERSION_1. (gcc_type_array): Move... * gcc-interface.h: ... here. * gcc-cp-fe.def: New. * gcc-cp-interface.h: New. 2016-04-29 Oleg Endo <olegendo@gcc.gnu.org> * longlong.h (umul_ppmm): Remove SHMEDIA checks. (__umulsidi3, count_leading_zeros): Remove SHMEDIA implementations. 2017-09-15 Yao Qi <yao.qi@linaro.org> Pedro Alves <palves@redhat.com> * ansidecl.h (DISABLE_COPY_AND_ASSIGN): New macro. 2017-09-12 Jiong Wang <jiong.wang@arm.com> * dwarf2.def (DW_CFA_AARCH64_negate_ra_state): New DW_CFA_DUP. * dwarf2.h (DW_CFA_DUP): New define. 2017-08-21 Richard Biener <rguenther@suse.de> * simple-object.h (simple_object_copy_lto_debug_sections): New function. 2017-05-18 Martin Liska <mliska@suse.cz> * ansidecl.h: Define CONSTEXPR macro. 2017-05-24 Nathan Sidwell <nathan@acm.org> * libiberty.h (ASTRDUP): Adjust cast to avoid warning. 2017-01-30 Alexandre Oliva <aoliva@redhat.com> Introduce C++ support in libcc1. * gcc-c-fe.def (int_type_v0): Rename from... (int_type): ... this. Introduce new version. (float_type_v0): Rename from... (float_type): ... this. Introduce new version. (char_type): New. * gcc-c-interface.h (gcc_c_api_version): Add GCC_C_FE_VERSION_1. (gcc_type_array): Move... * gcc-interface.h: ... here. * gcc-cp-fe.def: New. * gcc-cp-interface.h: New. 2016-04-29 Oleg Endo <olegendo@gcc.gnu.org> * longlong.h (umul_ppmm): Remove SHMEDIA checks. (__umulsidi3, count_leading_zeros): Remove SHMEDIA implementations. libiberty/ChangeLog: 2017-09-15 Nathan Sidwell <nathan@acm.org> PR demangler/82195 * cp-demangle.c (d_name): Add 'toplevel' parm. Pass to ... (d_local_name): ... here. Parse trailing function args on nested local_name. (d_encoding, d_special_name, d_class_enum_type): Adjust d_name calls. * testsuite/demangle-expected: Add tests. 2017-09-15 Richard Biener <rguenther@suse.de> PR lto/81968 * simple-object-elf.c (simple_object_elf_copy_lto_debug_sections): Iterate marking dependent sections necessary. 2017-09-15 Nathan Sidwell <nathan@acm.org> * cp-demangle.c (is_fnqual_component_type): Reimplement using FNQUAL_COMPONENT_CASE. (d_encoding): Hold bare_function_type in local var. (d_local_name): Build name in both cases and build result once. Collapse switch-if to single conditional. (d_local_name): * testsuite/demangle-expected: Realign blank lines with tests. 2017-09-12 Jiong Wang <jiong.wang@arm.com> * dwarfnames.c (DW_CFA_DUP): New define. gdb/ChangeLog: 2017-09-15 Pedro Alves <palves@redhat.com> * compile/compile-c-types.c (convert_enum, convert_int) (convert_float): Adjust to refer to int_type_v0 and float_type_v0.
2017-09-16 00:40:33 +08:00
If an error occurs, return the errno value in ERR and an error string. */
extern const char *
simple_object_copy_lto_debug_sections (simple_object_read *src_object,
const char *dest,
int *err, int rename);
Sync libiberty/ & include/ with GCC Note this brings in the interface files for libcc1/G++ as well, which we will be needing in GDB soon anyway. That commit renamed a method in the C interface and that required a small update to GDB's compile/ code, which I've included that in this patch to keep the tree building. include/ChangeLog: 2017-09-15 Pedro Alves <palves@redhat.com> * ansidecl.h (DISABLE_COPY_AND_ASSIGN): New macro. 2017-09-12 Jiong Wang <jiong.wang@arm.com> * dwarf2.def (DW_CFA_AARCH64_negate_ra_state): New DW_CFA_DUP. * dwarf2.h (DW_CFA_DUP): New define. 2017-08-21 Richard Biener <rguenther@suse.de> * simple-object.h (simple_object_copy_lto_debug_sections): New function. 2017-05-18 Martin Liska <mliska@suse.cz> * ansidecl.h: Define CONSTEXPR macro. 2017-05-24 Nathan Sidwell <nathan@acm.org> * libiberty.h (ASTRDUP): Adjust cast to avoid warning. 2017-01-30 Alexandre Oliva <aoliva@redhat.com> Introduce C++ support in libcc1. * gcc-c-fe.def (int_type_v0): Rename from... (int_type): ... this. Introduce new version. (float_type_v0): Rename from... (float_type): ... this. Introduce new version. (char_type): New. * gcc-c-interface.h (gcc_c_api_version): Add GCC_C_FE_VERSION_1. (gcc_type_array): Move... * gcc-interface.h: ... here. * gcc-cp-fe.def: New. * gcc-cp-interface.h: New. 2016-04-29 Oleg Endo <olegendo@gcc.gnu.org> * longlong.h (umul_ppmm): Remove SHMEDIA checks. (__umulsidi3, count_leading_zeros): Remove SHMEDIA implementations. 2017-09-15 Yao Qi <yao.qi@linaro.org> Pedro Alves <palves@redhat.com> * ansidecl.h (DISABLE_COPY_AND_ASSIGN): New macro. 2017-09-12 Jiong Wang <jiong.wang@arm.com> * dwarf2.def (DW_CFA_AARCH64_negate_ra_state): New DW_CFA_DUP. * dwarf2.h (DW_CFA_DUP): New define. 2017-08-21 Richard Biener <rguenther@suse.de> * simple-object.h (simple_object_copy_lto_debug_sections): New function. 2017-05-18 Martin Liska <mliska@suse.cz> * ansidecl.h: Define CONSTEXPR macro. 2017-05-24 Nathan Sidwell <nathan@acm.org> * libiberty.h (ASTRDUP): Adjust cast to avoid warning. 2017-01-30 Alexandre Oliva <aoliva@redhat.com> Introduce C++ support in libcc1. * gcc-c-fe.def (int_type_v0): Rename from... (int_type): ... this. Introduce new version. (float_type_v0): Rename from... (float_type): ... this. Introduce new version. (char_type): New. * gcc-c-interface.h (gcc_c_api_version): Add GCC_C_FE_VERSION_1. (gcc_type_array): Move... * gcc-interface.h: ... here. * gcc-cp-fe.def: New. * gcc-cp-interface.h: New. 2016-04-29 Oleg Endo <olegendo@gcc.gnu.org> * longlong.h (umul_ppmm): Remove SHMEDIA checks. (__umulsidi3, count_leading_zeros): Remove SHMEDIA implementations. libiberty/ChangeLog: 2017-09-15 Nathan Sidwell <nathan@acm.org> PR demangler/82195 * cp-demangle.c (d_name): Add 'toplevel' parm. Pass to ... (d_local_name): ... here. Parse trailing function args on nested local_name. (d_encoding, d_special_name, d_class_enum_type): Adjust d_name calls. * testsuite/demangle-expected: Add tests. 2017-09-15 Richard Biener <rguenther@suse.de> PR lto/81968 * simple-object-elf.c (simple_object_elf_copy_lto_debug_sections): Iterate marking dependent sections necessary. 2017-09-15 Nathan Sidwell <nathan@acm.org> * cp-demangle.c (is_fnqual_component_type): Reimplement using FNQUAL_COMPONENT_CASE. (d_encoding): Hold bare_function_type in local var. (d_local_name): Build name in both cases and build result once. Collapse switch-if to single conditional. (d_local_name): * testsuite/demangle-expected: Realign blank lines with tests. 2017-09-12 Jiong Wang <jiong.wang@arm.com> * dwarfnames.c (DW_CFA_DUP): New define. gdb/ChangeLog: 2017-09-15 Pedro Alves <palves@redhat.com> * compile/compile-c-types.c (convert_enum, convert_int) (convert_float): Adjust to refer to int_type_v0 and float_type_v0.
2017-09-16 00:40:33 +08:00
2010-11-02 23:20:47 +08:00
#ifdef __cplusplus
}
#endif
#endif