/* COFF specific linker code.
- Copyright (C) 1994-2018 Free Software Foundation, Inc.
+ Copyright (C) 1994-2021 Free Software Foundation, Inc.
Written by Ian Lance Taylor, Cygnus Support.
This file is part of BFD, the Binary File Descriptor library.
#include "libcoff.h"
#include "safe-ctype.h"
-static bfd_boolean coff_link_add_object_symbols (bfd *, struct bfd_link_info *);
-static bfd_boolean coff_link_check_archive_element
+static bool coff_link_add_object_symbols (bfd *, struct bfd_link_info *);
+static bool coff_link_check_archive_element
(bfd *, struct bfd_link_info *, struct bfd_link_hash_entry *, const char *,
- bfd_boolean *);
-static bfd_boolean coff_link_add_symbols (bfd *, struct bfd_link_info *);
+ bool *);
+static bool coff_link_add_symbols (bfd *, struct bfd_link_info *);
/* Return TRUE if SYM is a weak, external symbol. */
#define IS_WEAK_EXTERNAL(abfd, sym) \
/* Initialize a COFF linker hash table. */
-bfd_boolean
+bool
_bfd_coff_link_hash_table_init (struct coff_link_hash_table *table,
bfd *abfd,
struct bfd_hash_entry *(*newfunc) (struct bfd_hash_entry *,
_bfd_coff_link_hash_table_create (bfd *abfd)
{
struct coff_link_hash_table *ret;
- bfd_size_type amt = sizeof (struct coff_link_hash_table);
+ size_t amt = sizeof (struct coff_link_hash_table);
ret = (struct coff_link_hash_table *) bfd_malloc (amt);
if (ret == NULL)
/* Given a COFF BFD, add symbols to the global hash table as
appropriate. */
-bfd_boolean
+bool
_bfd_coff_link_add_symbols (bfd *abfd, struct bfd_link_info *info)
{
switch (bfd_get_format (abfd))
(abfd, info, coff_link_check_archive_element);
default:
bfd_set_error (bfd_error_wrong_format);
- return FALSE;
+ return false;
}
}
/* Add symbols from a COFF object file. */
-static bfd_boolean
+static bool
coff_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
{
if (! _bfd_coff_get_external_symbols (abfd))
- return FALSE;
+ return false;
if (! coff_link_add_symbols (abfd, info))
- return FALSE;
+ return false;
if (! info->keep_memory
&& ! _bfd_coff_free_symbols (abfd))
- return FALSE;
+ return false;
- return TRUE;
+ return true;
}
/* Check a single archive element to see if we need to include it in
needed in the link or not. This is called via
_bfd_generic_link_add_archive_symbols. */
-static bfd_boolean
+static bool
coff_link_check_archive_element (bfd *abfd,
struct bfd_link_info *info,
struct bfd_link_hash_entry *h,
const char *name,
- bfd_boolean *pneeded)
+ bool *pneeded)
{
- *pneeded = FALSE;
+ *pneeded = false;
+
+ /* PR 22369 - Skip non COFF objects in the archive. */
+ if (! bfd_family_coff (abfd))
+ return true;
/* We are only interested in symbols that are currently undefined.
If a symbol is currently known to be common, COFF linkers do not
bring in an object file which defines it. */
if (h->type != bfd_link_hash_undefined)
- return TRUE;
+ return true;
- /* PR 22369 - Skip non COFF objects in the archive. */
- if (! bfd_family_coff (abfd))
- return TRUE;
+ /* If the archive element has already been loaded then one
+ of the symbols defined by that element might have been
+ made undefined due to being in a discarded section. */
+ if (((struct coff_link_hash_entry *) h)->indx == -3)
+ return true;
/* Include this element? */
if (!(*info->callbacks->add_archive_element) (info, abfd, name, &abfd))
- return TRUE;
- *pneeded = TRUE;
+ return true;
+ *pneeded = true;
- return coff_link_add_object_symbols (abfd, info);
+ return bfd_link_add_symbols (abfd, info);
}
/* Add all the symbols from an object file to the hash table. */
-static bfd_boolean
+static bool
coff_link_add_symbols (bfd *abfd,
struct bfd_link_info *info)
{
unsigned int n_tmask = coff_data (abfd)->local_n_tmask;
unsigned int n_btshft = coff_data (abfd)->local_n_btshft;
unsigned int n_btmask = coff_data (abfd)->local_n_btmask;
- bfd_boolean keep_syms;
- bfd_boolean default_copy;
+ bool keep_syms;
+ bool default_copy;
bfd_size_type symcount;
struct coff_link_hash_entry **sym_hash;
bfd_size_type symesz;
symcount = obj_raw_syment_count (abfd);
if (symcount == 0)
- return TRUE; /* Nothing to do. */
+ return true; /* Nothing to do. */
/* Keep the symbols during this function, in case the linker needs
to read the generic symbols in order to report an error message. */
keep_syms = obj_coff_keep_syms (abfd);
- obj_coff_keep_syms (abfd) = TRUE;
+ obj_coff_keep_syms (abfd) = true;
if (info->keep_memory)
- default_copy = FALSE;
+ default_copy = false;
else
- default_copy = TRUE;
+ default_copy = true;
/* We keep a list of the linker hash table entries that correspond
to particular symbols. */
{
struct internal_syment sym;
enum coff_symbol_classification classification;
- bfd_boolean copy;
+ bool copy;
bfd_coff_swap_sym_in (abfd, esym, &sym);
flagword flags;
asection *section;
bfd_vma value;
- bfd_boolean addit;
+ bool addit;
+ bool discarded = false;
/* This symbol is externally visible. */
copy = default_copy;
if (sym._n._n_n._n_zeroes != 0
|| sym._n._n_n._n_offset == 0)
- copy = TRUE;
+ copy = true;
value = sym.n_value;
case COFF_SYMBOL_GLOBAL:
flags = BSF_EXPORT | BSF_GLOBAL;
section = coff_section_from_bfd_index (abfd, sym.n_scnum);
- if (! obj_pe (abfd))
+ if (discarded_section (section))
+ {
+ discarded = true;
+ section = bfd_und_section_ptr;
+ }
+ else if (! obj_pe (abfd))
value -= section->vma;
break;
case COFF_SYMBOL_PE_SECTION:
flags = BSF_SECTION_SYM | BSF_GLOBAL;
section = coff_section_from_bfd_index (abfd, sym.n_scnum);
+ if (discarded_section (section))
+ section = bfd_und_section_ptr;
break;
}
if (IS_WEAK_EXTERNAL (abfd, sym))
flags = BSF_WEAK;
- addit = TRUE;
+ addit = true;
/* In the PE format, section symbols actually refer to the
start of the output section. We handle them specially
if (obj_pe (abfd) && (flags & BSF_SECTION_SYM) != 0)
{
*sym_hash = coff_link_hash_lookup (coff_hash_table (info),
- name, FALSE, copy, FALSE);
+ name, false, copy, false);
if (*sym_hash != NULL)
{
if (((*sym_hash)->coff_link_hash_flags
(_("warning: symbol `%s' is both section and non-section"),
name);
- addit = FALSE;
+ addit = false;
}
}
|| classification == COFF_SYMBOL_PE_SECTION)
&& coff_section_data (abfd, section) != NULL
&& coff_section_data (abfd, section)->comdat != NULL
- && CONST_STRNEQ (name, "??_")
+ && startswith (name, "??_")
&& strcmp (name, coff_section_data (abfd, section)->comdat->name) == 0)
{
if (*sym_hash == NULL)
*sym_hash = coff_link_hash_lookup (coff_hash_table (info),
- name, FALSE, copy, FALSE);
+ name, false, copy, false);
if (*sym_hash != NULL
&& (*sym_hash)->root.type == bfd_link_hash_defined
&& coff_section_data (abfd, (*sym_hash)->root.u.def.section)->comdat != NULL
&& strcmp (coff_section_data (abfd, (*sym_hash)->root.u.def.section)->comdat->name,
coff_section_data (abfd, section)->comdat->name) == 0)
- addit = FALSE;
+ addit = false;
}
if (addit)
{
if (! (bfd_coff_link_add_one_symbol
(info, abfd, name, flags, section, value,
- (const char *) NULL, copy, FALSE,
+ (const char *) NULL, copy, false,
(struct bfd_link_hash_entry **) sym_hash)))
goto error_return;
+
+ if (discarded)
+ (*sym_hash)->indx = -3;
}
if (obj_pe (abfd) && (flags & BSF_SECTION_SYM) != 0)
asection *stab;
for (stab = abfd->sections; stab; stab = stab->next)
- if (CONST_STRNEQ (stab->name, ".stab")
+ if (startswith (stab->name, ".stab")
&& (!stab->name[5]
|| (stab->name[5] == '.' && ISDIGIT (stab->name[6]))))
{
obj_coff_keep_syms (abfd) = keep_syms;
- return TRUE;
+ return true;
error_return:
obj_coff_keep_syms (abfd) = keep_syms;
- return FALSE;
+ return false;
}
\f
/* Do the final link step. */
-bfd_boolean
+bool
_bfd_coff_final_link (bfd *abfd,
struct bfd_link_info *info)
{
bfd_size_type symesz;
struct coff_final_link_info flaginfo;
- bfd_boolean debug_merge_allocated;
- bfd_boolean long_section_names;
+ bool debug_merge_allocated;
+ bool long_section_names;
asection *o;
struct bfd_link_order *p;
bfd_size_type max_sym_count;
flaginfo.contents = NULL;
flaginfo.external_relocs = NULL;
flaginfo.internal_relocs = NULL;
- flaginfo.global_to_static = FALSE;
- debug_merge_allocated = FALSE;
+ flaginfo.global_to_static = false;
+ debug_merge_allocated = false;
coff_data (abfd)->link_info = info;
if (! coff_debug_merge_hash_table_init (&flaginfo.debug_merge))
goto error_return;
- debug_merge_allocated = TRUE;
+ debug_merge_allocated = true;
/* Compute the file positions for all the sections. */
if (! abfd->output_has_begun)
max_lineno_count = 0;
max_reloc_count = 0;
- long_section_names = FALSE;
+ long_section_names = false;
for (o = abfd->sections; o != NULL; o = o->next)
{
o->reloc_count = 0;
link. This will normally be every section. We need
to do this so that we can identify any sections which
the linker has decided to not include. */
- sec->linker_mark = TRUE;
+ sec->linker_mark = true;
if (info->strip == strip_none
|| info->strip == strip_some)
rel_filepos += o->reloc_count * relsz;
/* In PE COFF, if there are at least 0xffff relocations an
extra relocation will be written out to encode the count. */
- if (obj_pe (abfd) && o->reloc_count >= 0xffff)
+ if ((obj_pe (abfd) || obj_go32 (abfd)) && o->reloc_count >= 0xffff)
rel_filepos += relsz;
}
coff_write_object_contents which puts the string index
into the s_name field of the section header. That is why
we pass hash as FALSE. */
- if (_bfd_stringtab_add (flaginfo.strtab, o->name, FALSE, FALSE)
+ if (_bfd_stringtab_add (flaginfo.strtab, o->name, false, false)
== (bfd_size_type) -1)
goto error_return;
- long_section_names = TRUE;
+ long_section_names = true;
}
}
{
size_t sz;
- sub->output_has_begun = FALSE;
+ sub->output_has_begun = false;
sz = bfd_family_coff (sub) ? obj_raw_syment_count (sub) : 2;
if (sz > max_sym_count)
max_sym_count = sz;
{
if (! _bfd_coff_link_input_bfd (&flaginfo, sub))
goto error_return;
- sub->output_has_begun = TRUE;
+ sub->output_has_begun = true;
}
}
else if (p->type == bfd_section_reloc_link_order
union internal_auxent iaux;
bfd_size_type string_size = 0, indx;
bfd_vma written = 0;
- bfd_boolean rewrite = FALSE, hash;
+ bool rewrite = false, hash;
if (! (sym->flags & BSF_LOCAL)
|| (sym->flags & (BSF_SECTION_SYM | BSF_DEBUGGING_RELOC
/* See if we are discarding symbols with this name. */
if ((flaginfo.info->strip == strip_some
&& (bfd_hash_lookup (flaginfo.info->keep_hash,
- bfd_asymbol_name(sym), FALSE, FALSE)
+ bfd_asymbol_name(sym), false, false)
== NULL))
|| (((flaginfo.info->discard == discard_sec_merge
- && (bfd_get_section (sym)->flags & SEC_MERGE)
+ && (bfd_asymbol_section (sym)->flags & SEC_MERGE)
&& ! bfd_link_relocatable (flaginfo.info))
|| flaginfo.info->discard == discard_l)
&& bfd_is_local_label_name (sub, bfd_asymbol_name(sym))))
&& ! isym._n._n_n._n_zeroes && isym.n_numaux)
{
indx = _bfd_stringtab_add (flaginfo.strtab, ".file", hash,
- FALSE);
+ false);
if (indx == (bfd_size_type) -1)
goto error_return;
isym._n._n_n._n_offset = STRING_SIZE_SIZE + indx;
{
indx = _bfd_stringtab_add (flaginfo.strtab,
bfd_asymbol_name (sym), hash,
- FALSE);
+ false);
if (indx == (bfd_size_type) -1)
goto error_return;
if (isym.n_sclass != C_FILE)
{
isym._n._n_n._n_offset = STRING_SIZE_SIZE + indx;
bfd_coff_swap_sym_out (abfd, &isym, flaginfo.outsyms);
- rewrite = TRUE;
+ rewrite = true;
}
else
{
flaginfo.outsyms);
pos = obj_sym_filepos (abfd) + flaginfo.last_file_index
* symesz;
- rewrite = TRUE;
+ rewrite = true;
}
flaginfo.last_file_index = obj_raw_syment_count (abfd);
flaginfo.last_file = isym;
/* Free up the buffers used by _bfd_coff_link_input_bfd. */
coff_debug_merge_hash_table_free (&flaginfo.debug_merge);
- debug_merge_allocated = FALSE;
+ debug_merge_allocated = false;
- if (flaginfo.internal_syms != NULL)
- {
- free (flaginfo.internal_syms);
- flaginfo.internal_syms = NULL;
- }
- if (flaginfo.sec_ptrs != NULL)
- {
- free (flaginfo.sec_ptrs);
- flaginfo.sec_ptrs = NULL;
- }
- if (flaginfo.sym_indices != NULL)
- {
- free (flaginfo.sym_indices);
- flaginfo.sym_indices = NULL;
- }
- if (flaginfo.linenos != NULL)
- {
- free (flaginfo.linenos);
- flaginfo.linenos = NULL;
- }
- if (flaginfo.contents != NULL)
- {
- free (flaginfo.contents);
- flaginfo.contents = NULL;
- }
- if (flaginfo.external_relocs != NULL)
- {
- free (flaginfo.external_relocs);
- flaginfo.external_relocs = NULL;
- }
- if (flaginfo.internal_relocs != NULL)
- {
- free (flaginfo.internal_relocs);
- flaginfo.internal_relocs = NULL;
- }
+ free (flaginfo.internal_syms);
+ flaginfo.internal_syms = NULL;
+ free (flaginfo.sec_ptrs);
+ flaginfo.sec_ptrs = NULL;
+ free (flaginfo.sym_indices);
+ flaginfo.sym_indices = NULL;
+ free (flaginfo.linenos);
+ flaginfo.linenos = NULL;
+ free (flaginfo.contents);
+ flaginfo.contents = NULL;
+ free (flaginfo.external_relocs);
+ flaginfo.external_relocs = NULL;
+ free (flaginfo.internal_relocs);
+ flaginfo.internal_relocs = NULL;
/* The value of the last C_FILE symbol is supposed to be the symbol
index of the first external symbol. Write it out again if
pos = obj_sym_filepos (abfd) + flaginfo.last_file_index * symesz;
if (bfd_seek (abfd, pos, SEEK_SET) != 0
|| bfd_bwrite (flaginfo.outsyms, symesz, abfd) != symesz)
- return FALSE;
+ return false;
}
/* If doing task linking (ld --task-link) then make a pass through the
static. */
if (info->task_link)
{
- flaginfo.failed = FALSE;
+ flaginfo.failed = false;
coff_link_hash_traverse (coff_hash_table (info),
_bfd_coff_write_task_globals, &flaginfo);
if (flaginfo.failed)
}
/* Write out the global symbols. */
- flaginfo.failed = FALSE;
+ flaginfo.failed = false;
bfd_hash_traverse (&info->hash->table, _bfd_coff_write_global_sym, &flaginfo);
if (flaginfo.failed)
goto error_return;
/* The outsyms buffer is used by _bfd_coff_write_global_sym. */
- if (flaginfo.outsyms != NULL)
- {
- free (flaginfo.outsyms);
- flaginfo.outsyms = NULL;
- }
+ free (flaginfo.outsyms);
+ flaginfo.outsyms = NULL;
if (bfd_link_relocatable (info) && max_output_reloc_count > 0)
{
if (bfd_seek (abfd, o->rel_filepos, SEEK_SET) != 0)
goto error_return;
- if (obj_pe (abfd) && o->reloc_count >= 0xffff)
+ if ((obj_pe (abfd) || obj_go32 (abfd)) && o->reloc_count >= 0xffff)
{
/* In PE COFF, write the count of relocs as the first
reloc. The header overflow bit will be set
for (i = 0; i < abfd->section_count; i++)
{
- if (flaginfo.section_info[i].relocs != NULL)
- free (flaginfo.section_info[i].relocs);
- if (flaginfo.section_info[i].rel_hashes != NULL)
- free (flaginfo.section_info[i].rel_hashes);
+ free (flaginfo.section_info[i].relocs);
+ free (flaginfo.section_info[i].rel_hashes);
}
free (flaginfo.section_info);
flaginfo.section_info = NULL;
if (coff_hash_table (info)->stab_info.stabstr != NULL)
{
if (! _bfd_write_stab_strings (abfd, &coff_hash_table (info)->stab_info))
- return FALSE;
+ return false;
}
/* Write out the string table. */
pos = obj_sym_filepos (abfd) + obj_raw_syment_count (abfd) * symesz;
if (bfd_seek (abfd, pos, SEEK_SET) != 0)
- return FALSE;
+ return false;
#if STRING_SIZE_SIZE == 4
H_PUT_32 (abfd,
if (bfd_bwrite (strbuf, (bfd_size_type) STRING_SIZE_SIZE, abfd)
!= STRING_SIZE_SIZE)
- return FALSE;
+ return false;
if (! _bfd_stringtab_emit (abfd, flaginfo.strtab))
- return FALSE;
+ return false;
- obj_coff_strings_written (abfd) = TRUE;
+ obj_coff_strings_written (abfd) = true;
}
_bfd_stringtab_free (flaginfo.strtab);
- /* Setting bfd_get_symcount to 0 will cause write_object_contents to
+ /* Setting symcount to 0 will cause write_object_contents to
not try to write out the symbols. */
- bfd_get_symcount (abfd) = 0;
+ abfd->symcount = 0;
- return TRUE;
+ return true;
error_return:
if (debug_merge_allocated)
for (i = 0; i < abfd->section_count; i++)
{
- if (flaginfo.section_info[i].relocs != NULL)
- free (flaginfo.section_info[i].relocs);
- if (flaginfo.section_info[i].rel_hashes != NULL)
- free (flaginfo.section_info[i].rel_hashes);
+ free (flaginfo.section_info[i].relocs);
+ free (flaginfo.section_info[i].rel_hashes);
}
free (flaginfo.section_info);
}
- if (flaginfo.internal_syms != NULL)
- free (flaginfo.internal_syms);
- if (flaginfo.sec_ptrs != NULL)
- free (flaginfo.sec_ptrs);
- if (flaginfo.sym_indices != NULL)
- free (flaginfo.sym_indices);
- if (flaginfo.outsyms != NULL)
- free (flaginfo.outsyms);
- if (flaginfo.linenos != NULL)
- free (flaginfo.linenos);
- if (flaginfo.contents != NULL)
- free (flaginfo.contents);
- if (flaginfo.external_relocs != NULL)
- free (flaginfo.external_relocs);
- if (flaginfo.internal_relocs != NULL)
- free (flaginfo.internal_relocs);
- if (external_relocs != NULL)
- free (external_relocs);
- return FALSE;
+ free (flaginfo.internal_syms);
+ free (flaginfo.sec_ptrs);
+ free (flaginfo.sym_indices);
+ free (flaginfo.outsyms);
+ free (flaginfo.linenos);
+ free (flaginfo.contents);
+ free (flaginfo.external_relocs);
+ free (flaginfo.internal_relocs);
+ free (external_relocs);
+ return false;
}
/* Parse out a -heap <reserved>,<commit> line. */
if (!bfd_malloc_and_get_section (abfd, sec, ©))
{
- if (copy != NULL)
- free (copy);
+ free (copy);
return 0;
}
e = (char *) copy + sec->size;
s++;
continue;
}
- if (CONST_STRNEQ (s, "-attr"))
+ if (startswith (s, "-attr"))
{
char *name;
char *attribs;
asec->flags |= SEC_READONLY;
}
}
- else if (CONST_STRNEQ (s, "-heap"))
+ else if (startswith (s, "-heap"))
s = dores_com (s + 5, output_bfd, 1);
- else if (CONST_STRNEQ (s, "-stack"))
+ else if (startswith (s, "-stack"))
s = dores_com (s + 6, output_bfd, 0);
/* GNU extension for aligned commons. */
- else if (CONST_STRNEQ (s, "-aligncomm:"))
+ else if (startswith (s, "-aligncomm:"))
{
/* Common symbols must be aligned on reading, as it
is too late to do anything here, after they have
/* Read in the relocs. */
internal_relocs = _bfd_coff_read_internal_relocs
- (input_bfd, a, FALSE,
+ (input_bfd, a, false,
flaginfo->external_relocs,
bfd_link_relocatable (flaginfo->info),
(bfd_link_relocatable (flaginfo->info)
/* Link an input file into the linker output file. This function
handles all the sections and relocations of the input file at once. */
-bfd_boolean
+bool
_bfd_coff_link_input_bfd (struct coff_final_link_info *flaginfo, bfd *input_bfd)
{
unsigned int n_tmask = coff_data (input_bfd)->local_n_tmask;
unsigned int n_btshft = coff_data (input_bfd)->local_n_btshft;
- bfd_boolean (*adjust_symndx)
+ bool (*adjust_symndx)
(bfd *, struct bfd_link_info *, bfd *, asection *,
- struct internal_reloc *, bfd_boolean *);
+ struct internal_reloc *, bool *);
bfd *output_bfd;
const char *strings;
bfd_size_type syment_base;
- bfd_boolean copy, hash;
+ bool copy, hash;
bfd_size_type isymesz;
bfd_size_type osymesz;
bfd_size_type linesz;
linesz = bfd_coff_linesz (input_bfd);
BFD_ASSERT (linesz == bfd_coff_linesz (output_bfd));
- copy = FALSE;
+ copy = false;
if (! flaginfo->info->keep_memory)
- copy = TRUE;
- hash = TRUE;
+ copy = true;
+ hash = true;
if (flaginfo->info->traditional_format)
- hash = FALSE;
+ hash = false;
if (! _bfd_coff_get_external_symbols (input_bfd))
- return FALSE;
+ return false;
esym = (bfd_byte *) obj_coff_external_syms (input_bfd);
esym_end = esym + obj_raw_syment_count (input_bfd) * isymesz;
if (coff_data (output_bfd)->pe
&& ! process_embedded_commands (output_bfd, flaginfo->info, input_bfd))
- return FALSE;
+ return false;
/* If we are going to perform relocations and also strip/discard some
symbols then we must make sure that we do not strip/discard those
{
struct internal_syment isym;
enum coff_symbol_classification classification;
- bfd_boolean skip;
- bfd_boolean global;
- bfd_boolean dont_skip_symbol;
+ bool skip;
+ bool global;
+ bool dont_skip_symbol;
int add;
bfd_coff_swap_sym_in (input_bfd, esym, isymp);
&& bfd_link_relocatable (flaginfo->info))
dont_skip_symbol = *indexp;
else
- dont_skip_symbol = FALSE;
+ dont_skip_symbol = false;
*indexp = -1;
- skip = FALSE;
- global = FALSE;
+ skip = false;
+ global = false;
add = 1 + isym.n_numaux;
/* If we are stripping all symbols, we want to skip this one. */
if (flaginfo->info->strip == strip_all && ! dont_skip_symbol)
- skip = TRUE;
+ skip = true;
if (! skip)
{
end of the symbol table, so skip them for now.
Locally defined function symbols, however, are an
exception, and are not moved to the end. */
- global = TRUE;
+ global = true;
if (! ISFCN (isym.n_type))
- skip = TRUE;
+ skip = true;
break;
case COFF_SYMBOL_UNDEFINED:
/* Undefined symbols are left for the end. */
- global = TRUE;
- skip = TRUE;
+ global = true;
+ skip = true;
break;
case COFF_SYMBOL_LOCAL:
/* This is a local symbol. Skip it if we are discarding
local symbols. */
if (flaginfo->info->discard == discard_all && ! dont_skip_symbol)
- skip = TRUE;
+ skip = true;
break;
}
}
&& ((*secpp)->output_section == bfd_abs_section_ptr
|| bfd_section_removed_from_list (output_bfd,
(*secpp)->output_section)))
- skip = TRUE;
+ skip = true;
#endif
/* If we stripping debugging symbols, and this is a debugging
|| isym.n_sclass == C_REGPARM
|| isym.n_sclass == C_FIELD
|| isym.n_sclass == C_EOS))))
- skip = TRUE;
+ skip = true;
/* If some symbols are stripped based on the name, work out the
name and decide whether to skip this symbol. */
name = _bfd_coff_internal_syment_name (input_bfd, &isym, buf);
if (name == NULL)
- return FALSE;
+ return false;
if (! dont_skip_symbol
&& ((flaginfo->info->strip == strip_some
- && (bfd_hash_lookup (flaginfo->info->keep_hash, name, FALSE,
- FALSE) == NULL))
+ && (bfd_hash_lookup (flaginfo->info->keep_hash, name, false,
+ false) == NULL))
|| (! global
&& flaginfo->info->discard == discard_l
&& bfd_is_local_label_name (input_bfd, name))))
- skip = TRUE;
+ skip = true;
}
/* If this is an enum, struct, or union tag, see if we have
struct coff_debug_merge_element **epp;
bfd_byte *esl, *eslend;
struct internal_syment *islp;
- bfd_size_type amt;
+ size_t amt;
name = _bfd_coff_internal_syment_name (input_bfd, &isym, buf);
if (name == NULL)
- return FALSE;
+ return false;
/* Ignore fake names invented by compiler; treat them all as
the same name. */
name = "";
mh = coff_debug_merge_hash_lookup (&flaginfo->debug_merge, name,
- TRUE, TRUE);
+ true, true);
if (mh == NULL)
- return FALSE;
+ return false;
/* Allocate memory to hold type information. If this turns
out to be a duplicate, we pass this address to
amt = sizeof (struct coff_debug_merge_type);
mt = (struct coff_debug_merge_type *) bfd_alloc (input_bfd, amt);
if (mt == NULL)
- return FALSE;
+ return false;
mt->type_class = isym.n_sclass;
/* Pick up the aux entry, which points to the end of the tag
*epp = (struct coff_debug_merge_element *)
bfd_alloc (input_bfd, amt);
if (*epp == NULL)
- return FALSE;
+ return false;
elename = _bfd_coff_internal_syment_name (input_bfd, islp,
elebuf);
if (elename == NULL)
- return FALSE;
+ return false;
amt = strlen (elename) + 1;
name_copy = (char *) bfd_alloc (input_bfd, amt);
if (name_copy == NULL)
- return FALSE;
+ return false;
strcpy (name_copy, elename);
(*epp)->name = name_copy;
bfd_release (input_bfd, mt);
*indexp = mtl->indx;
add = (eslend - esym) / isymesz;
- skip = TRUE;
+ skip = true;
}
}
}
anyhow. */
name = _bfd_coff_internal_syment_name (input_bfd, &isym, NULL);
if (name == NULL)
- return FALSE;
+ return false;
indx = _bfd_stringtab_add (flaginfo->strtab, name, hash, copy);
if (indx == (bfd_size_type) -1)
- return FALSE;
+ return false;
isym._n._n_n._n_offset = STRING_SIZE_SIZE + indx;
}
case C_FCN:
if (obj_pe (input_bfd)
- && strncmp (isym.n_name, ".bf", sizeof isym.n_name) != 0
+ && memcmp (isym.n_name, ".bf", sizeof ".bf") != 0
&& isym.n_scnum > 0)
{
/* For PE, .lf and .ef get their value left alone,
pos += flaginfo->last_file_index * osymesz;
if (bfd_seek (output_bfd, pos, SEEK_SET) != 0
|| bfd_bwrite (outsym, osymesz, output_bfd) != osymesz)
- return FALSE;
+ return false;
}
}
/* This can happen if there were errors earlier in
the link. */
bfd_set_error (bfd_error_bad_value);
- return FALSE;
+ return false;
}
h->indx = output_index;
}
{
strings = _bfd_coff_read_string_table (input_bfd);
if (strings == NULL)
- return FALSE;
+ return false;
}
if ((bfd_size_type) auxp->x_file.x_n.x_offset >= obj_coff_strings_len (input_bfd))
filename = _("<corrupt>");
indx = _bfd_stringtab_add (flaginfo->strtab, filename,
hash, copy);
if (indx == (bfd_size_type) -1)
- return FALSE;
+ return false;
auxp->x_file.x_n.x_offset = STRING_SIZE_SIZE + indx;
}
}
if (bfd_seek (output_bfd, pos, SEEK_SET) != 0
|| (bfd_bwrite (outsym, osymesz, output_bfd)
!= osymesz))
- return FALSE;
+ return false;
}
}
bfd_byte *eline;
bfd_byte *elineend;
bfd_byte *oeline;
- bfd_boolean skipping;
+ bool skipping;
file_ptr pos;
bfd_size_type amt;
if (bfd_seek (input_bfd, o->line_filepos, SEEK_SET) != 0
|| bfd_bread (flaginfo->linenos, linesz * o->lineno_count,
input_bfd) != linesz * o->lineno_count)
- return FALSE;
+ return false;
offset = o->output_section->vma + o->output_offset - o->vma;
eline = flaginfo->linenos;
oeline = flaginfo->linenos;
elineend = eline + linesz * o->lineno_count;
- skipping = FALSE;
+ skipping = false;
for (; eline < elineend; eline += linesz)
{
struct internal_lineno iline;
with symbol #0) will fail. We can't regain
the space in the output file, but at least
they're dense. */
- skipping = TRUE;
+ skipping = true;
}
else
{
is.n_numaux, auxptr);
}
- skipping = FALSE;
+ skipping = false;
}
iline.l_addr.l_symndx = indx;
amt = oeline - flaginfo->linenos;
if (bfd_seek (output_bfd, pos, SEEK_SET) != 0
|| bfd_bwrite (flaginfo->linenos, amt, output_bfd) != amt)
- return FALSE;
+ return false;
o->output_section->lineno_count += amt / linesz;
}
amt = outsym - flaginfo->outsyms;
if (bfd_seek (output_bfd, pos, SEEK_SET) != 0
|| bfd_bwrite (flaginfo->outsyms, amt, output_bfd) != amt)
- return FALSE;
+ return false;
BFD_ASSERT ((obj_raw_syment_count (output_bfd)
+ (outsym - flaginfo->outsyms) / osymesz)
(_("%pB: relocs in section `%pA', but it has no contents"),
input_bfd, o);
bfd_set_error (bfd_error_no_contents);
- return FALSE;
+ return false;
}
continue;
{
contents = flaginfo->contents;
if (! bfd_get_full_section_contents (input_bfd, o, &contents))
- return FALSE;
+ return false;
}
if ((o->flags & SEC_RELOC) != 0)
/* Read in the relocs. */
target_index = o->output_section->target_index;
internal_relocs = (_bfd_coff_read_internal_relocs
- (input_bfd, o, FALSE, flaginfo->external_relocs,
+ (input_bfd, o, false, flaginfo->external_relocs,
bfd_link_relocatable (flaginfo->info),
(bfd_link_relocatable (flaginfo->info)
? (flaginfo->section_info[target_index].relocs
: flaginfo->internal_relocs)));
if (internal_relocs == NULL
&& o->reloc_count > 0)
- return FALSE;
+ return false;
/* Run through the relocs looking for relocs against symbols
coming from discarded sections and complain about them. */
internal_relocs,
flaginfo->internal_syms,
flaginfo->sec_ptrs))
- return FALSE;
+ return false;
if (bfd_link_relocatable (flaginfo->info))
{
for (; irel < irelend; irel++, rel_hash++)
{
struct coff_link_hash_entry *h;
- bfd_boolean adjusted;
+ bool adjusted;
*rel_hash = NULL;
if (! (*adjust_symndx) (output_bfd, flaginfo->info,
input_bfd, o, irel,
&adjusted))
- return FALSE;
+ return false;
if (adjusted)
continue;
}
name = (_bfd_coff_internal_syment_name
(input_bfd, is, buf));
if (name == NULL)
- return FALSE;
+ return false;
(*flaginfo->info->callbacks->unattached_reloc)
(flaginfo->info, name, input_bfd, o, irel->r_vaddr);
/* Write out the modified section contents. */
if (secdata == NULL || secdata->stab_info == NULL)
{
- file_ptr loc = o->output_offset * bfd_octets_per_byte (output_bfd);
+ file_ptr loc = (o->output_offset
+ * bfd_octets_per_byte (output_bfd, o));
if (! bfd_set_section_contents (output_bfd, o->output_section,
contents, loc, o->size))
- return FALSE;
+ return false;
}
else
{
if (! (_bfd_write_section_stabs
(output_bfd, &coff_hash_table (flaginfo->info)->stab_info,
o, &secdata->stab_info, contents)))
- return FALSE;
+ return false;
}
}
if (! flaginfo->info->keep_memory
&& ! _bfd_coff_free_symbols (input_bfd))
- return FALSE;
+ return false;
- return TRUE;
+ return true;
}
/* Write out a global symbol. Called via bfd_hash_traverse. */
-bfd_boolean
+bool
_bfd_coff_write_global_sym (struct bfd_hash_entry *bh, void *data)
{
struct coff_link_hash_entry *h = (struct coff_link_hash_entry *) bh;
{
h = (struct coff_link_hash_entry *) h->root.u.i.link;
if (h->root.type == bfd_link_hash_new)
- return TRUE;
+ return true;
}
if (h->indx >= 0)
- return TRUE;
+ return true;
if (h->indx != -2
&& (flaginfo->info->strip == strip_all
|| (flaginfo->info->strip == strip_some
&& (bfd_hash_lookup (flaginfo->info->keep_hash,
- h->root.root.string, FALSE, FALSE)
+ h->root.root.string, false, false)
== NULL))))
- return TRUE;
+ return true;
switch (h->root.type)
{
case bfd_link_hash_new:
case bfd_link_hash_warning:
abort ();
- return FALSE;
+ return false;
case bfd_link_hash_undefined:
+ if (h->indx == -3)
+ return true;
+ /* Fall through. */
case bfd_link_hash_undefweak:
isym.n_scnum = N_UNDEF;
isym.n_value = 0;
+ h->root.u.def.section->output_offset);
if (! obj_pe (flaginfo->output_bfd))
isym.n_value += sec->vma;
+#ifdef BFD64
+ if (isym.n_value > (bfd_vma) 0xffffffff)
+ {
+ if (! h->root.linker_def)
+ _bfd_error_handler
+ (_("%pB: stripping non-representable symbol '%s' (value "
+ "%" BFD_VMA_FMT "x)"),
+ output_bfd, h->root.root.string, isym.n_value);
+ return true;
+ }
+#endif
}
break;
case bfd_link_hash_indirect:
/* Just ignore these. They can't be handled anyhow. */
- return TRUE;
+ return true;
}
if (strlen (h->root.root.string) <= SYMNMLEN)
strncpy (isym._n._n_name, h->root.root.string, SYMNMLEN);
else
{
- bfd_boolean hash;
+ bool hash;
bfd_size_type indx;
- hash = TRUE;
+ hash = true;
if (flaginfo->info->traditional_format)
- hash = FALSE;
+ hash = false;
indx = _bfd_stringtab_add (flaginfo->strtab, h->root.root.string, hash,
- FALSE);
+ false);
if (indx == (bfd_size_type) -1)
{
- flaginfo->failed = TRUE;
- return FALSE;
+ flaginfo->failed = true;
+ return false;
}
isym._n._n_n._n_zeroes = 0;
isym._n._n_n._n_offset = STRING_SIZE_SIZE + indx;
if (flaginfo->global_to_static)
{
if (! IS_EXTERNAL (output_bfd, isym))
- return TRUE;
+ return true;
isym.n_sclass = C_STAT;
}
if (bfd_seek (output_bfd, pos, SEEK_SET) != 0
|| bfd_bwrite (flaginfo->outsyms, symesz, output_bfd) != symesz)
{
- flaginfo->failed = TRUE;
- return FALSE;
+ flaginfo->failed = true;
+ return false;
}
h->indx = obj_raw_syment_count (output_bfd);
flaginfo->outsyms);
if (bfd_bwrite (flaginfo->outsyms, symesz, output_bfd) != symesz)
{
- flaginfo->failed = TRUE;
- return FALSE;
+ flaginfo->failed = true;
+ return false;
}
++obj_raw_syment_count (output_bfd);
}
- return TRUE;
+ return true;
}
/* Write out task global symbols, converting them to statics. Called
via coff_link_hash_traverse. Calls bfd_coff_write_global_sym to do
the dirty work, if the symbol we are processing needs conversion. */
-bfd_boolean
+bool
_bfd_coff_write_task_globals (struct coff_link_hash_entry *h, void *data)
{
struct coff_final_link_info *flaginfo = (struct coff_final_link_info *) data;
- bfd_boolean rtnval = TRUE;
- bfd_boolean save_global_to_static;
+ bool rtnval = true;
+ bool save_global_to_static;
if (h->root.type == bfd_link_hash_warning)
h = (struct coff_link_hash_entry *) h->root.u.i.link;
case bfd_link_hash_defined:
case bfd_link_hash_defweak:
save_global_to_static = flaginfo->global_to_static;
- flaginfo->global_to_static = TRUE;
+ flaginfo->global_to_static = true;
rtnval = _bfd_coff_write_global_sym (&h->root.root, data);
flaginfo->global_to_static = save_global_to_static;
break;
/* Handle a link order which is supposed to generate a reloc. */
-bfd_boolean
+bool
_bfd_coff_reloc_link_order (bfd *output_bfd,
struct coff_final_link_info *flaginfo,
asection *output_section,
if (howto == NULL)
{
bfd_set_error (bfd_error_bad_value);
- return FALSE;
+ return false;
}
if (link_order->u.reloc.p->addend != 0)
bfd_size_type size;
bfd_byte *buf;
bfd_reloc_status_type rstat;
- bfd_boolean ok;
+ bool ok;
file_ptr loc;
size = bfd_get_reloc_size (howto);
buf = (bfd_byte *) bfd_zmalloc (size);
if (buf == NULL && size != 0)
- return FALSE;
+ return false;
rstat = _bfd_relocate_contents (howto, output_bfd,
- (bfd_vma) link_order->u.reloc.p->addend,\
+ (bfd_vma) link_order->u.reloc.p->addend,
buf);
switch (rstat)
{
(*flaginfo->info->callbacks->reloc_overflow)
(flaginfo->info, NULL,
(link_order->type == bfd_section_reloc_link_order
- ? bfd_section_name (output_bfd,
- link_order->u.reloc.p->u.section)
+ ? bfd_section_name (link_order->u.reloc.p->u.section)
: link_order->u.reloc.p->u.name),
howto->name, link_order->u.reloc.p->addend,
(bfd *) NULL, (asection *) NULL, (bfd_vma) 0);
break;
}
- loc = link_order->offset * bfd_octets_per_byte (output_bfd);
+ loc = link_order->offset * bfd_octets_per_byte (output_bfd,
+ output_section);
ok = bfd_set_section_contents (output_bfd, output_section, buf,
loc, size);
free (buf);
if (! ok)
- return FALSE;
+ return false;
}
/* Store the reloc information in the right place. It will get
h = ((struct coff_link_hash_entry *)
bfd_wrapped_link_hash_lookup (output_bfd, flaginfo->info,
link_order->u.reloc.p->u.name,
- FALSE, FALSE, TRUE));
+ false, false, true));
if (h != NULL)
{
if (h->indx >= 0)
/* FIXME: What is the right value for r_offset? Is zero OK? */
++output_section->reloc_count;
- return TRUE;
+ return true;
}
/* A basic reloc handling routine which may be used by processors with
simple relocs. */
-bfd_boolean
+bool
_bfd_coff_generic_relocate_section (bfd *output_bfd,
struct bfd_link_info *info,
bfd *input_bfd,
_bfd_error_handler
/* xgettext: c-format */
(_("%pB: illegal symbol index %ld in relocs"), input_bfd, symndx);
- return FALSE;
+ return false;
}
else
{
howto = bfd_coff_rtype_to_howto (input_bfd, input_section, rel, h,
sym, &addend);
if (howto == NULL)
- return FALSE;
+ return false;
/* If we are doing a relocatable link, then we can just ignore
a PC relative reloc that is pcrel_offset. It will already
}
else if (! bfd_link_relocatable (info))
- (*info->callbacks->undefined_symbol)
- (info, h->root.root.string, input_bfd, input_section,
- rel->r_vaddr - input_section->vma, TRUE);
+ {
+ (*info->callbacks->undefined_symbol)
+ (info, h->root.root.string, input_bfd, input_section,
+ rel->r_vaddr - input_section->vma, true);
+ /* Stop the linker from issueing errors about truncated relocs
+ referencing this undefined symbol by giving it an address
+ that should be in range. */
+ val = input_section->output_section->vma;
+ }
}
/* If the input section defining the symbol has been discarded
if (sec != NULL && discarded_section (sec))
{
_bfd_clear_contents (howto, input_bfd, input_section,
- contents + (rel->r_vaddr - input_section->vma));
+ contents, rel->r_vaddr - input_section->vma);
continue;
}
!= sizeof (bfd_vma))
{
bfd_set_error (bfd_error_system_call);
- return FALSE;
+ return false;
}
}
}
/* xgettext: c-format */
(_("%pB: bad reloc address %#" PRIx64 " in section `%pA'"),
input_bfd, (uint64_t) rel->r_vaddr, input_section);
- return FALSE;
+ return false;
case bfd_reloc_overflow:
{
+
+ /* Ignore any weak undef symbols that may have overflowed. Due to
+ PR ld/19011 the base address is now in the upper 64-bit address
+ range. This means that when _bfd_final_link_relocate calculates
+ the overlow it takes the distance between the symbol and the VMA
+ which will now always overflow as 0 - 64-bit addr > 32-bit range
+ of the relocation. This ends up creating PR ld/26659. */
+ if (val == 0
+ /* Reverse the hack where 4 is subtracted from the addend. */
+ && (addend + 4) == 0
+ && sym->n_sclass == C_NT_WEAK
+ && bfd_coff_classify_symbol (output_bfd, sym)
+ == COFF_SYMBOL_UNDEFINED)
+ break;
+
const char *name;
char buf[SYMNMLEN + 1];
{
name = _bfd_coff_internal_syment_name (input_bfd, sym, buf);
if (name == NULL)
- return FALSE;
+ return false;
}
(*info->callbacks->reloc_overflow)
}
}
}
- return TRUE;
+ return true;
}