/* simple-object-common.h -- common structs for object file manipulation.
Copyright (C) 2010-2024 Free Software Foundation, Inc.
This file is part of the libiberty library.
Libiberty is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
Libiberty 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with libiberty; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
Boston, MA 02110-1301, USA. */
/* Forward reference. */
struct simple_object_functions;
/* An object file opened for reading. */
struct simple_object_read_struct
{
/* The file descriptor. */
int descriptor;
/* The offset within the file. */
off_t offset;
/* The functions which do the actual work. */
const struct simple_object_functions *functions;
/* Private data for the object file format. */
void *data;
};
/* Object file attributes. */
struct simple_object_attributes_struct
{
/* The functions which do the actual work. */
const struct simple_object_functions *functions;
/* Private data for the object file format. */
void *data;
};
/* An object file being created. */
struct simple_object_write_struct
{
/* The functions which do the actual work. */
const struct simple_object_functions *functions;
/* The segment_name argument from the user. */
char *segment_name;
/* The start of the list of sections. */
simple_object_write_section *sections;
/* The last entry in the list of sections. */
simple_object_write_section *last_section;
/* Private data for the object file format. */
void *data;
};
/* A section in an object file being created. */
struct simple_object_write_section_struct
{
/* Next in the list of sections attached to an
simple_object_write. */
simple_object_write_section *next;
/* The name of this section. */
char *name;
/* The required alignment. */
unsigned int align;
/* The first data attached to this section. */
struct simple_object_write_section_buffer *buffers;
/* The last data attached to this section. */
struct simple_object_write_section_buffer *last_buffer;
};
/* Data attached to a section. */
struct simple_object_write_section_buffer
{
/* The next data for this section. */
struct simple_object_write_section_buffer *next;
/* The size of the buffer. */
size_t size;
/* The actual bytes. */
const void *buffer;
/* A buffer to free, or NULL. */
void *free_buffer;
};
/* The number of bytes we read from the start of the file to pass to
the match function. */
#define SIMPLE_OBJECT_MATCH_HEADER_LEN (16)
/* Format-specific object file functions. */
struct simple_object_functions
{
/* If this file matches these functions, return a new value for the
private data for an simple_object_read. HEADER is the first 16
bytes of the file. DESCRIPTOR, OFFSET, SEGMENT_NAME, ERRMSG, and
ERR are as for simple_object_open_read. If this file does not
match, this function should return NULL with *ERRMSG set to
NULL. */
void *(*match) (unsigned char header[SIMPLE_OBJECT_MATCH_HEADER_LEN],
int descriptor, off_t offset, const char *segment_name,
const char **errmsg, int *err);
/* Return the private data for the attributes for SOBJ. */
void *(*fetch_attributes) (simple_object_read *sobj, const char **errmsg,
int *err);
/* Release the private data for an simple_object_read. */
void (*release_read) (void *);
/* Merge the private data for the attributes of two files. If they
could be linked together, return NULL. Otherwise return an error
message. */
const char *(*attributes_merge) (void *, void *, int *err);
/* Release the private data for an simple_object_attributes. */
void (*release_attributes) (void *);
/* Start creating an object file. */
void *(*start_write) (void *attributes_data, const char **errmsg,
int *err);
/* Write the complete object file. */
const char *(*write_to_file) (simple_object_write *sobj, int descriptor,
int *err);
/* Release the private data for an simple_object_write. */
void (*release_write) (void *);