/*
FUNCTION
- bfd_add_gnu_debuglink
+ bfd_create_gnu_debuglink_section
SYNOPSIS
- bfd_boolean bfd_add_gnu_debuglink (bfd * abfd, const char * filename);
+ struct sec * bfd_create_gnu_debuglink_section (bfd * abfd, const char * filename);
DESCRIPTION
- Takes a @var{BFD} and adds a .gnu_debuglink section containing a link
- to the specified @var{filename}. The filename should be relative to
- the current directory.
+ Takes a @var{BFD} and adds a .gnu_debuglink section to it. The section is sized
+ to be big enough to contain a link to the specified @var{filename}.
+
+RETURNS
+ A pointer to the new section is returned if all is ok. Otherwise <<NULL>> is
+ returned and bfd_error is set.
+*/
+
+asection *
+bfd_create_gnu_debuglink_section
+ (bfd * abfd,
+ const char * filename)
+{
+ asection * sect;
+ bfd_size_type debuglink_size;
+
+ if (abfd == NULL || filename == NULL)
+ {
+ bfd_set_error (bfd_error_invalid_operation);
+ return NULL;
+ }
+
+ /* Strip off any path components in filename. */
+ filename = lbasename (filename);
+
+ sect = bfd_get_section_by_name (abfd, GNU_DEBUGLINK);
+ if (sect)
+ {
+ /* Section already exists. */
+ bfd_set_error (bfd_error_invalid_operation);
+ return NULL;
+ }
+
+ sect = bfd_make_section (abfd, GNU_DEBUGLINK);
+ if (sect == NULL)
+ return NULL;
+
+ if (! bfd_set_section_flags (abfd, sect,
+ SEC_HAS_CONTENTS | SEC_READONLY | SEC_DEBUGGING))
+ /* XXX Should we delete the section from the bfd ? */
+ return NULL;
+
+
+ debuglink_size = strlen (filename) + 1;
+ debuglink_size += 3;
+ debuglink_size &= ~3;
+ debuglink_size += 4;
+
+ if (! bfd_set_section_size (abfd, sect, debuglink_size))
+ /* XXX Should we delete the section from the bfd ? */
+ return NULL;
+
+ return sect;
+}
+
+
+/*
+FUNCTION
+ bfd_fill_in_gnu_debuglink_section
+
+SYNOPSIS
+ bfd_boolean bfd_fill_in_gnu_debuglink_section (bfd * abfd, struct sec * sect, const char * filename);
+
+DESCRIPTION
+
+ Takes a @var{BFD} and containing a .gnu_debuglink section @var{SECT}
+ and fills in the contents of the section to contain a link to the
+ specified @var{filename}. The filename should be relative to the
+ current directory.
RETURNS
<<TRUE>> is returned if all is ok. Otherwise <<FALSE>> is returned
*/
bfd_boolean
-bfd_add_gnu_debuglink (abfd, filename)
- bfd *abfd;
- const char * filename;
+bfd_fill_in_gnu_debuglink_section
+ (bfd * abfd,
+ struct sec * sect,
+ const char * filename)
{
- asection * sect;
bfd_size_type debuglink_size;
unsigned long crc32;
char * contents;
static char buffer[8 * 1024];
size_t count;
- if (abfd == NULL || filename == NULL)
+ if (abfd == NULL || sect == NULL || filename == NULL)
{
bfd_set_error (bfd_error_invalid_operation);
return FALSE;
now that we no longer need them. */
filename = lbasename (filename);
- sect = bfd_get_section_by_name (abfd, GNU_DEBUGLINK);
- if (sect)
- {
- /* Section already exists. */
- bfd_set_error (bfd_error_invalid_operation);
- return FALSE;
- }
-
- sect = bfd_make_section (abfd, GNU_DEBUGLINK);
- if (sect == NULL)
- return FALSE;
-
- if (! bfd_set_section_flags (abfd, sect,
- SEC_HAS_CONTENTS | SEC_DEBUGGING))
- /* XXX Should we delete the section from the bfd ? */
- return FALSE;
-
-
debuglink_size = strlen (filename) + 1;
debuglink_size += 3;
debuglink_size &= ~3;
debuglink_size += 4;
- if (! bfd_set_section_size (abfd, sect, debuglink_size))
- /* XXX Should we delete the section from the bfd ? */
- return FALSE;
-
contents = malloc (debuglink_size);
if (contents == NULL)
{
bfd_vma start;
long symcount;
asection **osections = NULL;
+ asection * gnu_debuglink_section = NULL;
bfd_size_type *gaps = NULL;
bfd_size_type max_gap = 0;
long symsize;
if (gnu_debuglink_filename != NULL)
{
- if (! bfd_add_gnu_debuglink (obfd, gnu_debuglink_filename))
+ gnu_debuglink_section = bfd_create_gnu_debuglink_section (obfd, gnu_debuglink_filename);
+
+ if (gnu_debuglink_section == NULL)
+ {
+ fprintf (stderr, "UGG\n");
RETURN_NONFATAL (gnu_debuglink_filename);
+ }
}
if (gap_fill_set || pad_to_set)
}
}
+ if (gnu_debuglink_filename != NULL)
+ {
+ if (! bfd_fill_in_gnu_debuglink_section
+ (obfd, gnu_debuglink_section, gnu_debuglink_filename))
+ {
+ fprintf (stderr, "UGG 2\n");
+ RETURN_NONFATAL (gnu_debuglink_filename);
+ }
+ }
+
if (gap_fill_set || pad_to_set)
{
bfd_byte *buf;