aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bfd/ChangeLog17
-rw-r--r--bfd/bfd-in2.h4
-rw-r--r--bfd/bfd.c68
-rw-r--r--bfd/elf.c54
-rw-r--r--bfd/elf32-nds32.c10
-rw-r--r--bfd/elfxx-target.h2
-rw-r--r--gas/ChangeLog5
-rw-r--r--gas/config/obj-elf.c27
-rw-r--r--include/ChangeLog5
-rw-r--r--include/bfdlink.h6
-rw-r--r--ld/ChangeLog11
-rw-r--r--ld/emultempl/elf.em9
-rw-r--r--ld/emultempl/ppc32elf.em2
-rw-r--r--ld/ld.h6
-rw-r--r--ld/ldemul.c13
-rw-r--r--ld/ldexp.c8
16 files changed, 120 insertions, 127 deletions
diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 3acaa57..f88a565 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,5 +1,22 @@
2020-12-16 Alan Modra <amodra@gmail.com>
+ * elfxx-target.h (elfNN_bed): Constify.
+ * bfd.c (bfd_elf_set_pagesize): Delete.
+ (bfd_emul_set_maxpagesize, bfd_emul_set_commonpagesize): Delete.
+ * elf.c (get_program_header_size): Get commonpagesize from
+ link info.
+ (_bfd_elf_map_sections_to_segments): Get maxpagesize from link info.
+ (assign_file_positions_for_load_sections): Likewise.
+ (assign_file_positions_for_non_load_sections): Likewise.
+ (rewrite_elf_program_header): Add maxpagesize param. Set map_p_align.
+ (copy_private_bfd_data): Don't call bfd_elf_set_maxpagesize.
+ Instead pass maxpagesize to rewrite_elf_program_header.
+ * elf32-nds32.c (relax_range_measurement): Add link_info param.
+ Get maxpagesize from link_info. Adjust caller.
+ * bfd-in2.h: Regenerate.
+
+2020-12-16 Alan Modra <amodra@gmail.com>
+
* elflink.c (elf_flags_to_names): Constify.
2020-12-16 Alan Modra <amodra@gmail.com>
diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h
index 48e3d9b..f1bef57 100644
--- a/bfd/bfd-in2.h
+++ b/bfd/bfd-in2.h
@@ -7224,12 +7224,8 @@ bfd_boolean bfd_alt_mach_code (bfd *abfd, int alternative);
bfd_vma bfd_emul_get_maxpagesize (const char *);
-void bfd_emul_set_maxpagesize (const char *, bfd_vma);
-
bfd_vma bfd_emul_get_commonpagesize (const char *, bfd_boolean);
-void bfd_emul_set_commonpagesize (const char *, bfd_vma);
-
char *bfd_demangle (bfd *, const char *, int);
void bfd_update_compression_header
diff --git a/bfd/bfd.c b/bfd/bfd.c
index 449bcc6..81d074e 100644
--- a/bfd/bfd.c
+++ b/bfd/bfd.c
@@ -2335,49 +2335,6 @@ bfd_emul_get_maxpagesize (const char *emul)
return 0;
}
-static void
-bfd_elf_set_pagesize (const bfd_target *target, bfd_vma size,
- int offset, const bfd_target *orig_target)
-{
- if (target->flavour == bfd_target_elf_flavour)
- {
- const struct elf_backend_data *bed;
-
- bed = xvec_get_elf_backend_data (target);
- *((bfd_vma *) ((char *) bed + offset)) = size;
- }
-
- if (target->alternative_target
- && target->alternative_target != orig_target)
- bfd_elf_set_pagesize (target->alternative_target, size, offset,
- orig_target);
-}
-
-/*
-FUNCTION
- bfd_emul_set_maxpagesize
-
-SYNOPSIS
- void bfd_emul_set_maxpagesize (const char *, bfd_vma);
-
-DESCRIPTION
- For ELF, set the maximum page size for the emulation. It is
- a no-op for other formats.
-
-*/
-
-void
-bfd_emul_set_maxpagesize (const char *emul, bfd_vma size)
-{
- const bfd_target *target;
-
- target = bfd_find_target (emul, NULL);
- if (target)
- bfd_elf_set_pagesize (target, size,
- offsetof (struct elf_backend_data,
- maxpagesize), target);
-}
-
/*
FUNCTION
bfd_emul_get_commonpagesize
@@ -2415,31 +2372,6 @@ bfd_emul_get_commonpagesize (const char *emul, bfd_boolean relro)
/*
FUNCTION
- bfd_emul_set_commonpagesize
-
-SYNOPSIS
- void bfd_emul_set_commonpagesize (const char *, bfd_vma);
-
-DESCRIPTION
- For ELF, set the common page size for the emulation. It is
- a no-op for other formats.
-
-*/
-
-void
-bfd_emul_set_commonpagesize (const char *emul, bfd_vma size)
-{
- const bfd_target *target;
-
- target = bfd_find_target (emul, NULL);
- if (target)
- bfd_elf_set_pagesize (target, size,
- offsetof (struct elf_backend_data,
- commonpagesize), target);
-}
-
-/*
-FUNCTION
bfd_demangle
SYNOPSIS
diff --git a/bfd/elf.c b/bfd/elf.c
index 7f22376..9c82912 100644
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -4428,7 +4428,14 @@ get_program_header_size (bfd *abfd, struct bfd_link_info *info)
&& (elf_tdata (abfd)->has_gnu_osabi & elf_gnu_osabi_mbind) != 0)
{
/* Add a PT_GNU_MBIND segment for each mbind section. */
- unsigned int page_align_power = bfd_log2 (bed->commonpagesize);
+ bfd_vma commonpagesize;
+ unsigned int page_align_power;
+
+ if (info != NULL)
+ commonpagesize = info->commonpagesize;
+ else
+ commonpagesize = bed->commonpagesize;
+ page_align_power = bfd_log2 (commonpagesize);
for (s = abfd->sections; s != NULL; s = s->next)
if (elf_section_flags (s) & SHF_GNU_MBIND)
{
@@ -4672,7 +4679,10 @@ _bfd_elf_map_sections_to_segments (bfd *abfd, struct bfd_link_info *info)
phdr_size += bed->s->sizeof_ehdr;
/* phdr_size is compared to LMA values which are in bytes. */
phdr_size /= opb;
- maxpagesize = bed->maxpagesize;
+ if (info != NULL)
+ maxpagesize = info->maxpagesize;
+ else
+ maxpagesize = bed->maxpagesize;
if (maxpagesize == 0)
maxpagesize = 1;
phdr_in_segment = info != NULL && info->load_phdrs;
@@ -5475,7 +5485,12 @@ assign_file_positions_for_load_sections (bfd *abfd,
maxpagesize = 1;
if ((abfd->flags & D_PAGED) != 0)
- maxpagesize = bed->maxpagesize;
+ {
+ if (link_info != NULL)
+ maxpagesize = link_info->maxpagesize;
+ else
+ maxpagesize = bed->maxpagesize;
+ }
/* Sections must map to file offsets past the ELF file header. */
off = bed->s->sizeof_ehdr;
@@ -6056,7 +6071,12 @@ assign_file_positions_for_non_load_sections (bfd *abfd,
struct elf_segment_map *m;
file_ptr off;
unsigned int opb = bfd_octets_per_byte (abfd, NULL);
+ bfd_vma maxpagesize;
+ if (link_info != NULL)
+ maxpagesize = link_info->maxpagesize;
+ else
+ maxpagesize = bed->maxpagesize;
i_shdrpp = elf_elfsections (abfd);
end_hdrpp = i_shdrpp + elf_numsections (abfd);
off = elf_next_file_pos (abfd);
@@ -6089,7 +6109,7 @@ assign_file_positions_for_non_load_sections (bfd *abfd,
/* We don't need to page align empty sections. */
if ((abfd->flags & D_PAGED) != 0 && hdr->sh_size != 0)
off += vma_page_aligned_bias (hdr->sh_addr, off,
- bed->maxpagesize);
+ maxpagesize);
else
off += vma_page_aligned_bias (hdr->sh_addr, off,
hdr->sh_addralign);
@@ -6767,7 +6787,7 @@ _bfd_elf_symbol_from_bfd_symbol (bfd *abfd, asymbol **asym_ptr_ptr)
/* Rewrite program header information. */
static bfd_boolean
-rewrite_elf_program_header (bfd *ibfd, bfd *obfd)
+rewrite_elf_program_header (bfd *ibfd, bfd *obfd, bfd_vma maxpagesize)
{
Elf_Internal_Ehdr *iehdr;
struct elf_segment_map *map;
@@ -6779,7 +6799,6 @@ rewrite_elf_program_header (bfd *ibfd, bfd *obfd)
unsigned int num_segments;
bfd_boolean phdr_included = FALSE;
bfd_boolean p_paddr_valid;
- bfd_vma maxpagesize;
struct elf_segment_map *phdr_adjust_seg = NULL;
unsigned int phdr_adjust_num = 0;
const struct elf_backend_data *bed;
@@ -6792,7 +6811,6 @@ rewrite_elf_program_header (bfd *ibfd, bfd *obfd)
pointer_to_map = &map_first;
num_segments = elf_elfheader (ibfd)->e_phnum;
- maxpagesize = get_elf_backend_data (obfd)->maxpagesize;
/* Returns the end address of the segment + 1. */
#define SEGMENT_END(segment, start) \
@@ -7049,6 +7067,17 @@ rewrite_elf_program_header (bfd *ibfd, bfd *obfd)
map->p_flags = segment->p_flags;
map->p_flags_valid = 1;
+ if (map->p_type == PT_LOAD
+ && (ibfd->flags & D_PAGED) != 0
+ && maxpagesize > 1
+ && segment->p_align > 1)
+ {
+ map->p_align = segment->p_align;
+ if (segment->p_align > maxpagesize)
+ map->p_align = maxpagesize;
+ map->p_align_valid = 1;
+ }
+
/* If the first section in the input segment is removed, there is
no need to preserve segment physical address in the corresponding
output segment. */
@@ -7613,6 +7642,8 @@ copy_elf_program_header (bfd *ibfd, bfd *obfd)
static bfd_boolean
copy_private_bfd_data (bfd *ibfd, bfd *obfd)
{
+ bfd_vma maxpagesize;
+
if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
|| bfd_get_flavour (obfd) != bfd_target_elf_flavour)
return TRUE;
@@ -7697,6 +7728,7 @@ copy_private_bfd_data (bfd *ibfd, bfd *obfd)
}
rewrite:
+ maxpagesize = 0;
if (ibfd->xvec == obfd->xvec)
{
/* When rewriting program header, set the output maxpagesize to
@@ -7704,7 +7736,6 @@ copy_private_bfd_data (bfd *ibfd, bfd *obfd)
Elf_Internal_Phdr *segment;
unsigned int i;
unsigned int num_segments = elf_elfheader (ibfd)->e_phnum;
- bfd_vma maxpagesize = 0;
for (i = 0, segment = elf_tdata (ibfd)->phdr;
i < num_segments;
@@ -7721,12 +7752,11 @@ copy_private_bfd_data (bfd *ibfd, bfd *obfd)
else
maxpagesize = segment->p_align;
}
-
- if (maxpagesize != get_elf_backend_data (obfd)->maxpagesize)
- bfd_emul_set_maxpagesize (bfd_get_target (obfd), maxpagesize);
}
+ if (maxpagesize == 0)
+ maxpagesize = get_elf_backend_data (obfd)->maxpagesize;
- return rewrite_elf_program_header (ibfd, obfd);
+ return rewrite_elf_program_header (ibfd, obfd, maxpagesize);
}
/* Initialize private output section information from input section. */
diff --git a/bfd/elf32-nds32.c b/bfd/elf32-nds32.c
index 105d7f5..85bbd09 100644
--- a/bfd/elf32-nds32.c
+++ b/bfd/elf32-nds32.c
@@ -9514,11 +9514,11 @@ nds32_elf_insn_size (bfd *abfd ATTRIBUTE_UNUSED,
to do gp relaxation. */
static void
-relax_range_measurement (bfd *abfd)
+relax_range_measurement (bfd *abfd, struct bfd_link_info *link_info)
{
asection *sec_f, *sec_b;
/* For upper bound. */
- bfd_vma maxpgsz = get_elf_backend_data (abfd)->maxpagesize;
+ bfd_vma maxpgsz;
bfd_vma align;
static int decide_relax_range = 0;
int i;
@@ -9550,6 +9550,10 @@ relax_range_measurement (bfd *abfd)
sec_b = sec_b->next;
}
+ if (link_info != NULL)
+ maxpgsz = link_info->maxpagesize;
+ else
+ maxpgsz = get_elf_backend_data (abfd)->maxpagesize;
/* I guess we can not determine the section before
gp located section, so we assume the align is max page size. */
for (i = 0; i < range_number; i++)
@@ -12121,7 +12125,7 @@ nds32_elf_relax_section (bfd *abfd, asection *sec,
is_SDA_BASE_set = 1;
nds32_elf_final_sda_base (sec->output_section->owner, link_info,
&gp, FALSE);
- relax_range_measurement (abfd);
+ relax_range_measurement (abfd, link_info);
}
symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
diff --git a/bfd/elfxx-target.h b/bfd/elfxx-target.h
index a137c46..a0186fa 100644
--- a/bfd/elfxx-target.h
+++ b/bfd/elfxx-target.h
@@ -802,7 +802,7 @@
extern const struct elf_size_info _bfd_elfNN_size_info;
-static struct elf_backend_data elfNN_bed =
+static const struct elf_backend_data elfNN_bed =
{
ELF_ARCH, /* arch */
ELF_TARGET_ID, /* target_id */
diff --git a/gas/ChangeLog b/gas/ChangeLog
index 1a6c85a..2816395 100644
--- a/gas/ChangeLog
+++ b/gas/ChangeLog
@@ -1,3 +1,8 @@
+2020-12-16 Alan Modra <amodra@gmail.com>
+
+ * config/obj-elf.c (obj_elf_section): Don't set elf_osabi here.
+ (obj_elf_type): Likewise.
+
2020-12-15 Alan Modra <amodra@gmail.com>
PR 27071
diff --git a/gas/config/obj-elf.c b/gas/config/obj-elf.c
index bee95c3..d030b54 100644
--- a/gas/config/obj-elf.c
+++ b/gas/config/obj-elf.c
@@ -1425,13 +1425,13 @@ obj_elf_section (int push)
if ((gnu_attr & (SHF_GNU_MBIND | SHF_GNU_RETAIN)) != 0)
{
- struct elf_backend_data *bed;
+ const struct elf_backend_data *bed;
bfd_boolean mbind_p = (gnu_attr & SHF_GNU_MBIND) != 0;
if (mbind_p && (attr & SHF_ALLOC) == 0)
as_bad (_("SHF_ALLOC isn't set for GNU_MBIND section: %s"), name);
- bed = (struct elf_backend_data *) get_elf_backend_data (stdoutput);
+ bed = get_elf_backend_data (stdoutput);
if (bed->elf_osabi != ELFOSABI_GNU
&& bed->elf_osabi != ELFOSABI_FREEBSD
@@ -1440,9 +1440,6 @@ obj_elf_section (int push)
mbind_p ? "GNU_MBIND" : "GNU_RETAIN");
else
{
- if (bed->elf_osabi == ELFOSABI_NONE)
- bed->elf_osabi = ELFOSABI_GNU;
-
if (mbind_p)
elf_tdata (stdoutput)->has_gnu_osabi |= elf_gnu_osabi_mbind;
if ((gnu_attr & SHF_GNU_RETAIN) != 0)
@@ -2361,13 +2358,12 @@ obj_elf_type (int ignore ATTRIBUTE_UNUSED)
|| strcmp (type_name, "10") == 0
|| strcmp (type_name, "STT_GNU_IFUNC") == 0)
{
- struct elf_backend_data *bed;
+ const struct elf_backend_data *bed;
- bed = (struct elf_backend_data *) get_elf_backend_data (stdoutput);
- if (bed->elf_osabi == ELFOSABI_NONE)
- bed->elf_osabi = ELFOSABI_GNU;
- else if (bed->elf_osabi != ELFOSABI_GNU
- && bed->elf_osabi != ELFOSABI_FREEBSD)
+ bed = get_elf_backend_data (stdoutput);
+ if (bed->elf_osabi != ELFOSABI_NONE
+ && bed->elf_osabi != ELFOSABI_GNU
+ && bed->elf_osabi != ELFOSABI_FREEBSD)
as_bad (_("symbol type \"%s\" is supported only by GNU "
"and FreeBSD targets"), type_name);
/* MIPS targets do not support IFUNCS. */
@@ -2379,12 +2375,11 @@ obj_elf_type (int ignore ATTRIBUTE_UNUSED)
}
else if (strcmp (type_name, "gnu_unique_object") == 0)
{
- struct elf_backend_data *bed;
+ const struct elf_backend_data *bed;
- bed = (struct elf_backend_data *) get_elf_backend_data (stdoutput);
- if (bed->elf_osabi == ELFOSABI_NONE)
- bed->elf_osabi = ELFOSABI_GNU;
- else if (bed->elf_osabi != ELFOSABI_GNU)
+ bed = get_elf_backend_data (stdoutput);
+ if (bed->elf_osabi != ELFOSABI_NONE
+ && bed->elf_osabi != ELFOSABI_GNU)
as_bad (_("symbol type \"%s\" is supported only by GNU targets"),
type_name);
elf_tdata (stdoutput)->has_gnu_osabi |= elf_gnu_osabi_unique;
diff --git a/include/ChangeLog b/include/ChangeLog
index a4c5dd9..9c19b87 100644
--- a/include/ChangeLog
+++ b/include/ChangeLog
@@ -1,5 +1,10 @@
2020-12-16 Alan Modra <amodra@gmail.com>
+ * bfdlink.h (struct bfd_link_info): Add maxpagesize and
+ commonpagesize.
+
+2020-12-16 Alan Modra <amodra@gmail.com>
+
* xtensa-isa-internal.h (xtensa_format_internal),
(xtensa_slot_internal, xtensa_operand_internal),
(xtensa_arg_internal, xtensa_iclass_internal),
diff --git a/include/bfdlink.h b/include/bfdlink.h
index 3019033..6b179ec 100644
--- a/include/bfdlink.h
+++ b/include/bfdlink.h
@@ -661,6 +661,12 @@ struct bfd_link_info
/* May be used to set ELF visibility for __start_* / __stop_. */
unsigned int start_stop_visibility;
+ /* The maximum page size for ELF. */
+ bfd_vma maxpagesize;
+
+ /* The common page size for ELF. */
+ bfd_vma commonpagesize;
+
/* Start and end of RELRO region. */
bfd_vma relro_start, relro_end;
diff --git a/ld/ChangeLog b/ld/ChangeLog
index 9a0ff59..46acbd9 100644
--- a/ld/ChangeLog
+++ b/ld/ChangeLog
@@ -1,3 +1,14 @@
+2020-12-16 Alan Modra <amodra@gmail.com>
+
+ * ld.h (ld_config_type): Delete maxpagesize and commonpagesize.
+ * emultempl/elf.em: Use link_info rather than config
+ for maxpagesize and commonpagesize.
+ * emultempl/ppc32elf.em: Likewise.
+ * ldexp.c (fold_binary, fold_name): Likewise.
+ * ldemul.c (after_parse_default): Likewise.
+ (set_output_arch_default): Don't call bfd_emul_set_maxpagesize
+ or bfd_emul_set_commonpagesize.
+
2020-12-15 Vivek Das Mohapatra <vivek@collabora.com>
* emultempl/elf.em (gld${EMULATION_NAME}_handle_option):
diff --git a/ld/emultempl/elf.em b/ld/emultempl/elf.em
index aa40c78..b915ad5 100644
--- a/ld/emultempl/elf.em
+++ b/ld/emultempl/elf.em
@@ -716,17 +716,18 @@ fragment <<EOF
{
char *end;
- config.maxpagesize = strtoul (optarg + 14, &end, 0);
- if (*end || (config.maxpagesize & (config.maxpagesize - 1)) != 0)
+ link_info.maxpagesize = strtoul (optarg + 14, &end, 0);
+ if (*end
+ || (link_info.maxpagesize & (link_info.maxpagesize - 1)) != 0)
einfo (_("%F%P: invalid maximum page size \`%s'\n"),
optarg + 14);
}
else if (CONST_STRNEQ (optarg, "common-page-size="))
{
char *end;
- config.commonpagesize = strtoul (optarg + 17, &end, 0);
+ link_info.commonpagesize = strtoul (optarg + 17, &end, 0);
if (*end
- || (config.commonpagesize & (config.commonpagesize - 1)) != 0)
+ || (link_info.commonpagesize & (link_info.commonpagesize - 1)) != 0)
einfo (_("%F%P: invalid common page size \`%s'\n"),
optarg + 17);
}
diff --git a/ld/emultempl/ppc32elf.em b/ld/emultempl/ppc32elf.em
index 0402ffb..9d8e933 100644
--- a/ld/emultempl/ppc32elf.em
+++ b/ld/emultempl/ppc32elf.em
@@ -51,7 +51,7 @@ ppc_after_open_output (void)
params.emit_stub_syms = (link_info.emitrelocations
|| bfd_link_pic (&link_info));
if (params.pagesize == 0)
- params.pagesize = config.commonpagesize;
+ params.pagesize = link_info.commonpagesize;
ppc_elf_link_params (&link_info, &params);
}
diff --git a/ld/ld.h b/ld/ld.h
index 7f7d716..612d530 100644
--- a/ld/ld.h
+++ b/ld/ld.h
@@ -294,12 +294,6 @@ typedef struct
/* The size of the hash table to use. */
unsigned long hash_table_size;
- /* The maximum page size for ELF. */
- bfd_vma maxpagesize;
-
- /* The common page size for ELF. */
- bfd_vma commonpagesize;
-
/* If set, print discarded sections in map file output. */
bfd_boolean print_map_discarded;
diff --git a/ld/ldemul.c b/ld/ldemul.c
index 920afc8..fc51493 100644
--- a/ld/ldemul.c
+++ b/ld/ldemul.c
@@ -232,11 +232,11 @@ after_parse_default (void)
if (!is_vma)
ldlang_add_undef (entry_symbol.name, entry_from_cmdline);
}
- if (config.maxpagesize == 0)
- config.maxpagesize = bfd_emul_get_maxpagesize (default_target);
- if (config.commonpagesize == 0)
- config.commonpagesize = bfd_emul_get_commonpagesize (default_target,
- link_info.relro);
+ if (link_info.maxpagesize == 0)
+ link_info.maxpagesize = bfd_emul_get_maxpagesize (default_target);
+ if (link_info.commonpagesize == 0)
+ link_info.commonpagesize = bfd_emul_get_commonpagesize (default_target,
+ link_info.relro);
}
void
@@ -303,9 +303,6 @@ set_output_arch_default (void)
/* Set the output architecture and machine if possible. */
bfd_set_arch_mach (link_info.output_bfd,
ldfile_output_architecture, ldfile_output_machine);
-
- bfd_emul_set_maxpagesize (output_target, config.maxpagesize);
- bfd_emul_set_commonpagesize (output_target, config.commonpagesize);
}
void
diff --git a/ld/ldexp.c b/ld/ldexp.c
index b4e7c41..905055a 100644
--- a/ld/ldexp.c
+++ b/ld/ldexp.c
@@ -547,8 +547,8 @@ fold_binary (etree_type *tree)
{
if (!seg->used
&& config.magic_demand_paged
- && config.maxpagesize != 0
- && (seg->value % config.maxpagesize) != 0)
+ && link_info.maxpagesize != 0
+ && (seg->value % link_info.maxpagesize) != 0)
einfo (_("%P: warning: address of `%s' "
"isn't multiple of maximum page size\n"),
segment_name);
@@ -898,9 +898,9 @@ fold_name (etree_type *tree)
case CONSTANT:
if (strcmp (tree->name.name, "MAXPAGESIZE") == 0)
- new_number (config.maxpagesize);
+ new_number (link_info.maxpagesize);
else if (strcmp (tree->name.name, "COMMONPAGESIZE") == 0)
- new_number (config.commonpagesize);
+ new_number (link_info.commonpagesize);
else
einfo (_("%F%P:%pS: unknown constant `%s' referenced in expression\n"),
tree, tree->name.name);