1999-05-03 09:29:11 +02:00
|
|
|
|
/* rescoff.c -- read and write resources in Windows COFF files.
|
2019-01-01 11:31:27 +01:00
|
|
|
|
Copyright (C) 1997-2019 Free Software Foundation, Inc.
|
1999-05-03 09:29:11 +02:00
|
|
|
|
Written by Ian Lance Taylor, Cygnus Support.
|
2007-05-23 10:48:29 +02:00
|
|
|
|
Rewritten by Kai Tietz, Onevision.
|
1999-05-03 09:29:11 +02:00
|
|
|
|
|
|
|
|
|
This file is part of GNU Binutils.
|
|
|
|
|
|
|
|
|
|
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
|
2007-07-05 18:54:46 +02:00
|
|
|
|
the Free Software Foundation; either version 3 of the License, or
|
1999-05-03 09:29:11 +02:00
|
|
|
|
(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
|
2005-05-08 16:17:41 +02:00
|
|
|
|
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
|
|
|
|
|
02110-1301, USA. */
|
1999-05-03 09:29:11 +02:00
|
|
|
|
|
|
|
|
|
/* This file contains function that read and write Windows resources
|
|
|
|
|
in COFF files. */
|
|
|
|
|
|
2007-04-26 16:47:00 +02:00
|
|
|
|
#include "sysdep.h"
|
1999-05-03 09:29:11 +02:00
|
|
|
|
#include "bfd.h"
|
2007-04-26 16:47:00 +02:00
|
|
|
|
#include "bucomm.h"
|
2007-05-23 10:48:29 +02:00
|
|
|
|
#include "libiberty.h"
|
1999-05-03 09:29:11 +02:00
|
|
|
|
#include "windres.h"
|
|
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
|
|
/* In order to use the address of a resource data entry, we need to
|
|
|
|
|
get the image base of the file. Right now we extract it from
|
|
|
|
|
internal BFD information. FIXME. */
|
|
|
|
|
|
|
|
|
|
#include "coff/internal.h"
|
|
|
|
|
#include "libcoff.h"
|
|
|
|
|
|
|
|
|
|
/* Information we extract from the file. */
|
|
|
|
|
|
|
|
|
|
struct coff_file_info
|
|
|
|
|
{
|
|
|
|
|
/* File name. */
|
|
|
|
|
const char *filename;
|
|
|
|
|
/* Data read from the file. */
|
|
|
|
|
const bfd_byte *data;
|
|
|
|
|
/* End of data read from file. */
|
|
|
|
|
const bfd_byte *data_end;
|
|
|
|
|
/* Address of the resource section minus the image base of the file. */
|
2007-05-23 10:48:29 +02:00
|
|
|
|
rc_uint_type secaddr;
|
1999-05-03 09:29:11 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* A resource directory table in a COFF file. */
|
|
|
|
|
|
2007-05-23 10:48:29 +02:00
|
|
|
|
struct __attribute__ ((__packed__)) extern_res_directory
|
1999-05-03 09:29:11 +02:00
|
|
|
|
{
|
|
|
|
|
/* Characteristics. */
|
|
|
|
|
bfd_byte characteristics[4];
|
|
|
|
|
/* Time stamp. */
|
|
|
|
|
bfd_byte time[4];
|
|
|
|
|
/* Major version number. */
|
|
|
|
|
bfd_byte major[2];
|
|
|
|
|
/* Minor version number. */
|
|
|
|
|
bfd_byte minor[2];
|
|
|
|
|
/* Number of named directory entries. */
|
|
|
|
|
bfd_byte name_count[2];
|
|
|
|
|
/* Number of directory entries with IDs. */
|
|
|
|
|
bfd_byte id_count[2];
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* A resource directory entry in a COFF file. */
|
|
|
|
|
|
|
|
|
|
struct extern_res_entry
|
|
|
|
|
{
|
|
|
|
|
/* Name or ID. */
|
|
|
|
|
bfd_byte name[4];
|
|
|
|
|
/* Address of resource entry or subdirectory. */
|
|
|
|
|
bfd_byte rva[4];
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* A resource data entry in a COFF file. */
|
|
|
|
|
|
|
|
|
|
struct extern_res_data
|
|
|
|
|
{
|
|
|
|
|
/* Address of resource data. This is apparently a file relative
|
|
|
|
|
address, rather than a section offset. */
|
|
|
|
|
bfd_byte rva[4];
|
|
|
|
|
/* Size of resource data. */
|
|
|
|
|
bfd_byte size[4];
|
|
|
|
|
/* Code page. */
|
|
|
|
|
bfd_byte codepage[4];
|
|
|
|
|
/* Reserved. */
|
|
|
|
|
bfd_byte reserved[4];
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* Local functions. */
|
|
|
|
|
|
2003-09-14 14:20:17 +02:00
|
|
|
|
static void overrun (const struct coff_file_info *, const char *);
|
2007-05-23 10:48:29 +02:00
|
|
|
|
static rc_res_directory *read_coff_res_dir (windres_bfd *, const bfd_byte *,
|
|
|
|
|
const struct coff_file_info *,
|
|
|
|
|
const rc_res_id *, int);
|
|
|
|
|
static rc_res_resource *read_coff_data_entry (windres_bfd *, const bfd_byte *,
|
|
|
|
|
const struct coff_file_info *,
|
|
|
|
|
const rc_res_id *);
|
1999-05-03 09:29:11 +02:00
|
|
|
|
|
|
|
|
|
/* Read the resources in a COFF file. */
|
|
|
|
|
|
2007-05-23 10:48:29 +02:00
|
|
|
|
rc_res_directory *
|
2003-09-14 14:20:17 +02:00
|
|
|
|
read_coff_rsrc (const char *filename, const char *target)
|
1999-05-03 09:29:11 +02:00
|
|
|
|
{
|
2007-05-23 10:48:29 +02:00
|
|
|
|
rc_res_directory *ret;
|
1999-05-03 09:29:11 +02:00
|
|
|
|
bfd *abfd;
|
2007-05-23 10:48:29 +02:00
|
|
|
|
windres_bfd wrbfd;
|
1999-05-03 09:29:11 +02:00
|
|
|
|
char **matching;
|
|
|
|
|
asection *sec;
|
|
|
|
|
bfd_size_type size;
|
|
|
|
|
bfd_byte *data;
|
2012-05-01 18:07:36 +02:00
|
|
|
|
struct coff_file_info flaginfo;
|
1999-05-03 09:29:11 +02:00
|
|
|
|
|
|
|
|
|
if (filename == NULL)
|
|
|
|
|
fatal (_("filename required for COFF input"));
|
|
|
|
|
|
|
|
|
|
abfd = bfd_openr (filename, target);
|
|
|
|
|
if (abfd == NULL)
|
|
|
|
|
bfd_fatal (filename);
|
|
|
|
|
|
|
|
|
|
if (! bfd_check_format_matches (abfd, bfd_object, &matching))
|
|
|
|
|
{
|
|
|
|
|
bfd_nonfatal (bfd_get_filename (abfd));
|
|
|
|
|
if (bfd_get_error () == bfd_error_file_ambiguously_recognized)
|
|
|
|
|
list_matching_formats (matching);
|
|
|
|
|
xexit (1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sec = bfd_get_section_by_name (abfd, ".rsrc");
|
|
|
|
|
if (sec == NULL)
|
|
|
|
|
{
|
2000-04-07 06:34:50 +02:00
|
|
|
|
fatal (_("%s: no resource section"), filename);
|
1999-05-03 09:29:11 +02:00
|
|
|
|
}
|
|
|
|
|
|
2007-05-23 10:48:29 +02:00
|
|
|
|
set_windres_bfd (&wrbfd, abfd, sec, WR_KIND_BFD);
|
bfd_section_* macros
This large patch removes the unnecessary bfd parameter from various
bfd section macros and functions. The bfd is hardly ever used and if
needed for the bfd_set_section_* or bfd_rename_section functions can
be found via section->owner except for the com, und, abs, and ind
std_section special sections. Those sections shouldn't be modified
anyway.
The patch also removes various bfd_get_section_<field> macros,
replacing their use with bfd_section_<field>, and adds
bfd_set_section_lma. I've also fixed a minor bug in gas where
compressed section renaming was done directly rather than calling
bfd_rename_section. This would have broken bfd_get_section_by_name
and similar functions, but that hardly mattered at such a late stage
in gas processing.
bfd/
* bfd-in.h (bfd_get_section_name, bfd_get_section_vma),
(bfd_get_section_lma, bfd_get_section_alignment),
(bfd_get_section_size, bfd_get_section_flags),
(bfd_get_section_userdata): Delete.
(bfd_section_name, bfd_section_size, bfd_section_vma),
(bfd_section_lma, bfd_section_alignment): Lose bfd parameter.
(bfd_section_flags, bfd_section_userdata): New.
(bfd_is_com_section): Rename parameter.
* section.c (bfd_set_section_userdata, bfd_set_section_vma),
(bfd_set_section_alignment, bfd_set_section_flags, bfd_rename_section),
(bfd_set_section_size): Delete bfd parameter, rename section parameter.
(bfd_set_section_lma): New.
* bfd-in2.h: Regenerate.
* mach-o.c (bfd_mach_o_init_section_from_mach_o): Delete bfd param,
update callers.
* aoutx.h, * bfd.c, * coff-alpha.c, * coff-arm.c, * coff-mips.c,
* coff64-rs6000.c, * coffcode.h, * coffgen.c, * cofflink.c,
* compress.c, * ecoff.c, * elf-eh-frame.c, * elf-hppa.h,
* elf-ifunc.c, * elf-m10200.c, * elf-m10300.c, * elf-properties.c,
* elf-s390-common.c, * elf-vxworks.c, * elf.c, * elf32-arc.c,
* elf32-arm.c, * elf32-avr.c, * elf32-bfin.c, * elf32-cr16.c,
* elf32-cr16c.c, * elf32-cris.c, * elf32-crx.c, * elf32-csky.c,
* elf32-d10v.c, * elf32-epiphany.c, * elf32-fr30.c, * elf32-frv.c,
* elf32-ft32.c, * elf32-h8300.c, * elf32-hppa.c, * elf32-i386.c,
* elf32-ip2k.c, * elf32-iq2000.c, * elf32-lm32.c, * elf32-m32c.c,
* elf32-m32r.c, * elf32-m68hc1x.c, * elf32-m68k.c, * elf32-mcore.c,
* elf32-mep.c, * elf32-metag.c, * elf32-microblaze.c,
* elf32-moxie.c, * elf32-msp430.c, * elf32-mt.c, * elf32-nds32.c,
* elf32-nios2.c, * elf32-or1k.c, * elf32-ppc.c, * elf32-pru.c,
* elf32-rl78.c, * elf32-rx.c, * elf32-s390.c, * elf32-score.c,
* elf32-score7.c, * elf32-sh.c, * elf32-spu.c, * elf32-tic6x.c,
* elf32-tilepro.c, * elf32-v850.c, * elf32-vax.c, * elf32-visium.c,
* elf32-xstormy16.c, * elf32-xtensa.c, * elf64-alpha.c,
* elf64-bpf.c, * elf64-hppa.c, * elf64-ia64-vms.c, * elf64-mmix.c,
* elf64-ppc.c, * elf64-s390.c, * elf64-sparc.c, * elf64-x86-64.c,
* elflink.c, * elfnn-aarch64.c, * elfnn-ia64.c, * elfnn-riscv.c,
* elfxx-aarch64.c, * elfxx-mips.c, * elfxx-sparc.c,
* elfxx-tilegx.c, * elfxx-x86.c, * i386msdos.c, * linker.c,
* mach-o.c, * mmo.c, * opncls.c, * pdp11.c, * pei-x86_64.c,
* peicode.h, * reloc.c, * section.c, * syms.c, * vms-alpha.c,
* xcofflink.c: Update throughout for bfd section macro and function
changes.
binutils/
* addr2line.c, * bucomm.c, * coffgrok.c, * dlltool.c, * nm.c,
* objcopy.c, * objdump.c, * od-elf32_avr.c, * od-macho.c,
* od-xcoff.c, * prdbg.c, * rdcoff.c, * rddbg.c, * rescoff.c,
* resres.c, * size.c, * srconv.c, * strings.c, * windmc.c: Update
throughout for bfd section macro and function changes.
gas/
* as.c, * as.h, * dw2gencfi.c, * dwarf2dbg.c, * ecoff.c,
* read.c, * stabs.c, * subsegs.c, * subsegs.h, * write.c,
* config/obj-coff-seh.c, * config/obj-coff.c, * config/obj-ecoff.c,
* config/obj-elf.c, * config/obj-macho.c, * config/obj-som.c,
* config/tc-aarch64.c, * config/tc-alpha.c, * config/tc-arc.c,
* config/tc-arm.c, * config/tc-avr.c, * config/tc-bfin.c,
* config/tc-bpf.c, * config/tc-d10v.c, * config/tc-d30v.c,
* config/tc-epiphany.c, * config/tc-fr30.c, * config/tc-frv.c,
* config/tc-h8300.c, * config/tc-hppa.c, * config/tc-i386.c,
* config/tc-ia64.c, * config/tc-ip2k.c, * config/tc-iq2000.c,
* config/tc-lm32.c, * config/tc-m32c.c, * config/tc-m32r.c,
* config/tc-m68hc11.c, * config/tc-mep.c, * config/tc-microblaze.c,
* config/tc-mips.c, * config/tc-mmix.c, * config/tc-mn10200.c,
* config/tc-mn10300.c, * config/tc-msp430.c, * config/tc-mt.c,
* config/tc-nds32.c, * config/tc-or1k.c, * config/tc-ppc.c,
* config/tc-pru.c, * config/tc-rl78.c, * config/tc-rx.c,
* config/tc-s12z.c, * config/tc-s390.c, * config/tc-score.c,
* config/tc-score7.c, * config/tc-sh.c, * config/tc-sparc.c,
* config/tc-spu.c, * config/tc-tic4x.c, * config/tc-tic54x.c,
* config/tc-tic6x.c, * config/tc-tilegx.c, * config/tc-tilepro.c,
* config/tc-v850.c, * config/tc-visium.c, * config/tc-wasm32.c,
* config/tc-xc16x.c, * config/tc-xgate.c, * config/tc-xstormy16.c,
* config/tc-xtensa.c, * config/tc-z8k.c: Update throughout for
bfd section macro and function changes.
* write.c (compress_debug): Use bfd_rename_section.
gdb/
* aarch64-linux-tdep.c, * arm-tdep.c, * auto-load.c,
* coff-pe-read.c, * coffread.c, * corelow.c, * dbxread.c,
* dicos-tdep.c, * dwarf2-frame.c, * dwarf2read.c, * elfread.c,
* exec.c, * fbsd-tdep.c, * gcore.c, * gdb_bfd.c, * gdb_bfd.h,
* hppa-tdep.c, * i386-cygwin-tdep.c, * i386-fbsd-tdep.c,
* i386-linux-tdep.c, * jit.c, * linux-tdep.c, * machoread.c,
* maint.c, * mdebugread.c, * minidebug.c, * mips-linux-tdep.c,
* mips-sde-tdep.c, * mips-tdep.c, * mipsread.c, * nto-tdep.c,
* objfiles.c, * objfiles.h, * osabi.c, * ppc-linux-tdep.c,
* ppc64-tdep.c, * record-btrace.c, * record-full.c, * remote.c,
* rs6000-aix-tdep.c, * rs6000-tdep.c, * s390-linux-tdep.c,
* s390-tdep.c, * solib-aix.c, * solib-dsbt.c, * solib-frv.c,
* solib-spu.c, * solib-svr4.c, * solib-target.c,
* spu-linux-nat.c, * spu-tdep.c, * symfile-mem.c, * symfile.c,
* symmisc.c, * symtab.c, * target.c, * windows-nat.c,
* xcoffread.c, * cli/cli-dump.c, * compile/compile-object-load.c,
* mi/mi-interp.c: Update throughout for bfd section macro and
function changes.
* gcore (gcore_create_callback): Use bfd_set_section_lma.
* spu-tdep.c (spu_overlay_new_objfile): Likewise.
gprof/
* corefile.c, * symtab.c: Update throughout for bfd section
macro and function changes.
ld/
* ldcref.c, * ldctor.c, * ldelf.c, * ldlang.c, * pe-dll.c,
* emultempl/aarch64elf.em, * emultempl/aix.em,
* emultempl/armcoff.em, * emultempl/armelf.em,
* emultempl/cr16elf.em, * emultempl/cskyelf.em,
* emultempl/m68hc1xelf.em, * emultempl/m68kelf.em,
* emultempl/mipself.em, * emultempl/mmix-elfnmmo.em,
* emultempl/mmo.em, * emultempl/msp430.em,
* emultempl/nios2elf.em, * emultempl/pe.em, * emultempl/pep.em,
* emultempl/ppc64elf.em, * emultempl/xtensaelf.em: Update
throughout for bfd section macro and function changes.
libctf/
* ctf-open-bfd.c: Update throughout for bfd section macro changes.
opcodes/
* arc-ext.c: Update throughout for bfd section macro changes.
sim/
* common/sim-load.c, * common/sim-utils.c, * cris/sim-if.c,
* erc32/func.c, * lm32/sim-if.c, * m32c/load.c, * m32c/trace.c,
* m68hc11/interp.c, * ppc/hw_htab.c, * ppc/hw_init.c,
* rl78/load.c, * rl78/trace.c, * rx/gdb-if.c, * rx/load.c,
* rx/trace.c: Update throughout for bfd section macro changes.
2019-09-16 12:55:17 +02:00
|
|
|
|
size = bfd_section_size (sec);
|
2015-01-27 18:32:23 +01:00
|
|
|
|
/* PR 17512: file: 1b25ba5d
|
|
|
|
|
The call to get_file_size here may be expensive
|
|
|
|
|
but there is no other way to determine if the section size
|
|
|
|
|
is reasonable. */
|
|
|
|
|
if (size > (bfd_size_type) get_file_size (filename))
|
|
|
|
|
fatal (_("%s: .rsrc section is bigger than the file!"), filename);
|
1999-05-03 09:29:11 +02:00
|
|
|
|
|
2015-01-27 18:32:23 +01:00
|
|
|
|
data = (bfd_byte *) res_alloc (size);
|
2007-05-23 10:48:29 +02:00
|
|
|
|
get_windres_bfd_content (&wrbfd, data, 0, size);
|
1999-05-03 09:29:11 +02:00
|
|
|
|
|
2012-05-01 18:07:36 +02:00
|
|
|
|
flaginfo.filename = filename;
|
|
|
|
|
flaginfo.data = data;
|
|
|
|
|
flaginfo.data_end = data + size;
|
bfd_section_* macros
This large patch removes the unnecessary bfd parameter from various
bfd section macros and functions. The bfd is hardly ever used and if
needed for the bfd_set_section_* or bfd_rename_section functions can
be found via section->owner except for the com, und, abs, and ind
std_section special sections. Those sections shouldn't be modified
anyway.
The patch also removes various bfd_get_section_<field> macros,
replacing their use with bfd_section_<field>, and adds
bfd_set_section_lma. I've also fixed a minor bug in gas where
compressed section renaming was done directly rather than calling
bfd_rename_section. This would have broken bfd_get_section_by_name
and similar functions, but that hardly mattered at such a late stage
in gas processing.
bfd/
* bfd-in.h (bfd_get_section_name, bfd_get_section_vma),
(bfd_get_section_lma, bfd_get_section_alignment),
(bfd_get_section_size, bfd_get_section_flags),
(bfd_get_section_userdata): Delete.
(bfd_section_name, bfd_section_size, bfd_section_vma),
(bfd_section_lma, bfd_section_alignment): Lose bfd parameter.
(bfd_section_flags, bfd_section_userdata): New.
(bfd_is_com_section): Rename parameter.
* section.c (bfd_set_section_userdata, bfd_set_section_vma),
(bfd_set_section_alignment, bfd_set_section_flags, bfd_rename_section),
(bfd_set_section_size): Delete bfd parameter, rename section parameter.
(bfd_set_section_lma): New.
* bfd-in2.h: Regenerate.
* mach-o.c (bfd_mach_o_init_section_from_mach_o): Delete bfd param,
update callers.
* aoutx.h, * bfd.c, * coff-alpha.c, * coff-arm.c, * coff-mips.c,
* coff64-rs6000.c, * coffcode.h, * coffgen.c, * cofflink.c,
* compress.c, * ecoff.c, * elf-eh-frame.c, * elf-hppa.h,
* elf-ifunc.c, * elf-m10200.c, * elf-m10300.c, * elf-properties.c,
* elf-s390-common.c, * elf-vxworks.c, * elf.c, * elf32-arc.c,
* elf32-arm.c, * elf32-avr.c, * elf32-bfin.c, * elf32-cr16.c,
* elf32-cr16c.c, * elf32-cris.c, * elf32-crx.c, * elf32-csky.c,
* elf32-d10v.c, * elf32-epiphany.c, * elf32-fr30.c, * elf32-frv.c,
* elf32-ft32.c, * elf32-h8300.c, * elf32-hppa.c, * elf32-i386.c,
* elf32-ip2k.c, * elf32-iq2000.c, * elf32-lm32.c, * elf32-m32c.c,
* elf32-m32r.c, * elf32-m68hc1x.c, * elf32-m68k.c, * elf32-mcore.c,
* elf32-mep.c, * elf32-metag.c, * elf32-microblaze.c,
* elf32-moxie.c, * elf32-msp430.c, * elf32-mt.c, * elf32-nds32.c,
* elf32-nios2.c, * elf32-or1k.c, * elf32-ppc.c, * elf32-pru.c,
* elf32-rl78.c, * elf32-rx.c, * elf32-s390.c, * elf32-score.c,
* elf32-score7.c, * elf32-sh.c, * elf32-spu.c, * elf32-tic6x.c,
* elf32-tilepro.c, * elf32-v850.c, * elf32-vax.c, * elf32-visium.c,
* elf32-xstormy16.c, * elf32-xtensa.c, * elf64-alpha.c,
* elf64-bpf.c, * elf64-hppa.c, * elf64-ia64-vms.c, * elf64-mmix.c,
* elf64-ppc.c, * elf64-s390.c, * elf64-sparc.c, * elf64-x86-64.c,
* elflink.c, * elfnn-aarch64.c, * elfnn-ia64.c, * elfnn-riscv.c,
* elfxx-aarch64.c, * elfxx-mips.c, * elfxx-sparc.c,
* elfxx-tilegx.c, * elfxx-x86.c, * i386msdos.c, * linker.c,
* mach-o.c, * mmo.c, * opncls.c, * pdp11.c, * pei-x86_64.c,
* peicode.h, * reloc.c, * section.c, * syms.c, * vms-alpha.c,
* xcofflink.c: Update throughout for bfd section macro and function
changes.
binutils/
* addr2line.c, * bucomm.c, * coffgrok.c, * dlltool.c, * nm.c,
* objcopy.c, * objdump.c, * od-elf32_avr.c, * od-macho.c,
* od-xcoff.c, * prdbg.c, * rdcoff.c, * rddbg.c, * rescoff.c,
* resres.c, * size.c, * srconv.c, * strings.c, * windmc.c: Update
throughout for bfd section macro and function changes.
gas/
* as.c, * as.h, * dw2gencfi.c, * dwarf2dbg.c, * ecoff.c,
* read.c, * stabs.c, * subsegs.c, * subsegs.h, * write.c,
* config/obj-coff-seh.c, * config/obj-coff.c, * config/obj-ecoff.c,
* config/obj-elf.c, * config/obj-macho.c, * config/obj-som.c,
* config/tc-aarch64.c, * config/tc-alpha.c, * config/tc-arc.c,
* config/tc-arm.c, * config/tc-avr.c, * config/tc-bfin.c,
* config/tc-bpf.c, * config/tc-d10v.c, * config/tc-d30v.c,
* config/tc-epiphany.c, * config/tc-fr30.c, * config/tc-frv.c,
* config/tc-h8300.c, * config/tc-hppa.c, * config/tc-i386.c,
* config/tc-ia64.c, * config/tc-ip2k.c, * config/tc-iq2000.c,
* config/tc-lm32.c, * config/tc-m32c.c, * config/tc-m32r.c,
* config/tc-m68hc11.c, * config/tc-mep.c, * config/tc-microblaze.c,
* config/tc-mips.c, * config/tc-mmix.c, * config/tc-mn10200.c,
* config/tc-mn10300.c, * config/tc-msp430.c, * config/tc-mt.c,
* config/tc-nds32.c, * config/tc-or1k.c, * config/tc-ppc.c,
* config/tc-pru.c, * config/tc-rl78.c, * config/tc-rx.c,
* config/tc-s12z.c, * config/tc-s390.c, * config/tc-score.c,
* config/tc-score7.c, * config/tc-sh.c, * config/tc-sparc.c,
* config/tc-spu.c, * config/tc-tic4x.c, * config/tc-tic54x.c,
* config/tc-tic6x.c, * config/tc-tilegx.c, * config/tc-tilepro.c,
* config/tc-v850.c, * config/tc-visium.c, * config/tc-wasm32.c,
* config/tc-xc16x.c, * config/tc-xgate.c, * config/tc-xstormy16.c,
* config/tc-xtensa.c, * config/tc-z8k.c: Update throughout for
bfd section macro and function changes.
* write.c (compress_debug): Use bfd_rename_section.
gdb/
* aarch64-linux-tdep.c, * arm-tdep.c, * auto-load.c,
* coff-pe-read.c, * coffread.c, * corelow.c, * dbxread.c,
* dicos-tdep.c, * dwarf2-frame.c, * dwarf2read.c, * elfread.c,
* exec.c, * fbsd-tdep.c, * gcore.c, * gdb_bfd.c, * gdb_bfd.h,
* hppa-tdep.c, * i386-cygwin-tdep.c, * i386-fbsd-tdep.c,
* i386-linux-tdep.c, * jit.c, * linux-tdep.c, * machoread.c,
* maint.c, * mdebugread.c, * minidebug.c, * mips-linux-tdep.c,
* mips-sde-tdep.c, * mips-tdep.c, * mipsread.c, * nto-tdep.c,
* objfiles.c, * objfiles.h, * osabi.c, * ppc-linux-tdep.c,
* ppc64-tdep.c, * record-btrace.c, * record-full.c, * remote.c,
* rs6000-aix-tdep.c, * rs6000-tdep.c, * s390-linux-tdep.c,
* s390-tdep.c, * solib-aix.c, * solib-dsbt.c, * solib-frv.c,
* solib-spu.c, * solib-svr4.c, * solib-target.c,
* spu-linux-nat.c, * spu-tdep.c, * symfile-mem.c, * symfile.c,
* symmisc.c, * symtab.c, * target.c, * windows-nat.c,
* xcoffread.c, * cli/cli-dump.c, * compile/compile-object-load.c,
* mi/mi-interp.c: Update throughout for bfd section macro and
function changes.
* gcore (gcore_create_callback): Use bfd_set_section_lma.
* spu-tdep.c (spu_overlay_new_objfile): Likewise.
gprof/
* corefile.c, * symtab.c: Update throughout for bfd section
macro and function changes.
ld/
* ldcref.c, * ldctor.c, * ldelf.c, * ldlang.c, * pe-dll.c,
* emultempl/aarch64elf.em, * emultempl/aix.em,
* emultempl/armcoff.em, * emultempl/armelf.em,
* emultempl/cr16elf.em, * emultempl/cskyelf.em,
* emultempl/m68hc1xelf.em, * emultempl/m68kelf.em,
* emultempl/mipself.em, * emultempl/mmix-elfnmmo.em,
* emultempl/mmo.em, * emultempl/msp430.em,
* emultempl/nios2elf.em, * emultempl/pe.em, * emultempl/pep.em,
* emultempl/ppc64elf.em, * emultempl/xtensaelf.em: Update
throughout for bfd section macro and function changes.
libctf/
* ctf-open-bfd.c: Update throughout for bfd section macro changes.
opcodes/
* arc-ext.c: Update throughout for bfd section macro changes.
sim/
* common/sim-load.c, * common/sim-utils.c, * cris/sim-if.c,
* erc32/func.c, * lm32/sim-if.c, * m32c/load.c, * m32c/trace.c,
* m68hc11/interp.c, * ppc/hw_htab.c, * ppc/hw_init.c,
* rl78/load.c, * rl78/trace.c, * rx/gdb-if.c, * rx/load.c,
* rx/trace.c: Update throughout for bfd section macro changes.
2019-09-16 12:55:17 +02:00
|
|
|
|
flaginfo.secaddr = (bfd_section_vma (sec)
|
|
|
|
|
- pe_data (abfd)->pe_opthdr.ImageBase);
|
1999-05-03 09:29:11 +02:00
|
|
|
|
|
|
|
|
|
/* Now just read in the top level resource directory. Note that we
|
|
|
|
|
don't free data, since we create resource entries that point into
|
|
|
|
|
it. If we ever want to free up the resource information we read,
|
|
|
|
|
this will have to be cleaned up. */
|
|
|
|
|
|
2012-05-01 18:07:36 +02:00
|
|
|
|
ret = read_coff_res_dir (&wrbfd, data, &flaginfo, (const rc_res_id *) NULL, 0);
|
2015-08-12 13:42:37 +02:00
|
|
|
|
|
2007-05-23 10:48:29 +02:00
|
|
|
|
bfd_close (abfd);
|
|
|
|
|
|
|
|
|
|
return ret;
|
1999-05-03 09:29:11 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Give an error if we are out of bounds. */
|
|
|
|
|
|
|
|
|
|
static void
|
2012-05-01 18:07:36 +02:00
|
|
|
|
overrun (const struct coff_file_info *flaginfo, const char *msg)
|
1999-05-03 09:29:11 +02:00
|
|
|
|
{
|
2012-05-01 18:07:36 +02:00
|
|
|
|
fatal (_("%s: %s: address out of bounds"), flaginfo->filename, msg);
|
1999-05-03 09:29:11 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Read a resource directory. */
|
|
|
|
|
|
2007-05-23 10:48:29 +02:00
|
|
|
|
static rc_res_directory *
|
|
|
|
|
read_coff_res_dir (windres_bfd *wrbfd, const bfd_byte *data,
|
2012-05-01 18:07:36 +02:00
|
|
|
|
const struct coff_file_info *flaginfo,
|
2007-05-23 10:48:29 +02:00
|
|
|
|
const rc_res_id *type, int level)
|
1999-05-03 09:29:11 +02:00
|
|
|
|
{
|
|
|
|
|
const struct extern_res_directory *erd;
|
2007-05-23 10:48:29 +02:00
|
|
|
|
rc_res_directory *rd;
|
1999-05-03 09:29:11 +02:00
|
|
|
|
int name_count, id_count, i;
|
2007-05-23 10:48:29 +02:00
|
|
|
|
rc_res_entry **pp;
|
1999-05-03 09:29:11 +02:00
|
|
|
|
const struct extern_res_entry *ere;
|
|
|
|
|
|
2015-01-27 18:32:23 +01:00
|
|
|
|
/* PR 17512: file: 09d80f53.
|
|
|
|
|
Whilst in theory resources can nest to any level, in practice
|
|
|
|
|
Microsoft only defines 3 levels. Corrupt files however might
|
|
|
|
|
claim to use more. */
|
|
|
|
|
if (level > 4)
|
|
|
|
|
overrun (flaginfo, _("Resources nest too deep"));
|
|
|
|
|
|
2012-05-01 18:07:36 +02:00
|
|
|
|
if ((size_t) (flaginfo->data_end - data) < sizeof (struct extern_res_directory))
|
|
|
|
|
overrun (flaginfo, _("directory"));
|
1999-05-03 09:29:11 +02:00
|
|
|
|
|
|
|
|
|
erd = (const struct extern_res_directory *) data;
|
|
|
|
|
|
2007-05-23 10:48:29 +02:00
|
|
|
|
rd = (rc_res_directory *) res_alloc (sizeof (rc_res_directory));
|
|
|
|
|
rd->characteristics = windres_get_32 (wrbfd, erd->characteristics, 4);
|
|
|
|
|
rd->time = windres_get_32 (wrbfd, erd->time, 4);
|
|
|
|
|
rd->major = windres_get_16 (wrbfd, erd->major, 2);
|
|
|
|
|
rd->minor = windres_get_16 (wrbfd, erd->minor, 2);
|
1999-05-03 09:29:11 +02:00
|
|
|
|
rd->entries = NULL;
|
|
|
|
|
|
2007-05-23 10:48:29 +02:00
|
|
|
|
name_count = windres_get_16 (wrbfd, erd->name_count, 2);
|
|
|
|
|
id_count = windres_get_16 (wrbfd, erd->id_count, 2);
|
1999-05-03 09:29:11 +02:00
|
|
|
|
|
|
|
|
|
pp = &rd->entries;
|
|
|
|
|
|
|
|
|
|
/* The resource directory entries immediately follow the directory
|
|
|
|
|
table. */
|
|
|
|
|
ere = (const struct extern_res_entry *) (erd + 1);
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < name_count; i++, ere++)
|
|
|
|
|
{
|
2007-05-23 10:48:29 +02:00
|
|
|
|
rc_uint_type name, rva;
|
|
|
|
|
rc_res_entry *re;
|
1999-05-03 09:29:11 +02:00
|
|
|
|
const bfd_byte *ers;
|
|
|
|
|
int length, j;
|
|
|
|
|
|
2012-05-01 18:07:36 +02:00
|
|
|
|
if ((const bfd_byte *) ere >= flaginfo->data_end)
|
|
|
|
|
overrun (flaginfo, _("named directory entry"));
|
1999-05-03 09:29:11 +02:00
|
|
|
|
|
2007-05-23 10:48:29 +02:00
|
|
|
|
name = windres_get_32 (wrbfd, ere->name, 4);
|
|
|
|
|
rva = windres_get_32 (wrbfd, ere->rva, 4);
|
1999-05-03 09:29:11 +02:00
|
|
|
|
|
|
|
|
|
/* For some reason the high bit in NAME is set. */
|
|
|
|
|
name &=~ 0x80000000;
|
|
|
|
|
|
2012-05-01 18:07:36 +02:00
|
|
|
|
if (name > (rc_uint_type) (flaginfo->data_end - flaginfo->data))
|
|
|
|
|
overrun (flaginfo, _("directory entry name"));
|
1999-05-03 09:29:11 +02:00
|
|
|
|
|
2012-05-01 18:07:36 +02:00
|
|
|
|
ers = flaginfo->data + name;
|
1999-05-03 09:29:11 +02:00
|
|
|
|
|
2007-05-23 10:48:29 +02:00
|
|
|
|
re = (rc_res_entry *) res_alloc (sizeof *re);
|
1999-05-03 09:29:11 +02:00
|
|
|
|
re->next = NULL;
|
|
|
|
|
re->id.named = 1;
|
2007-05-23 10:48:29 +02:00
|
|
|
|
length = windres_get_16 (wrbfd, ers, 2);
|
1999-05-03 09:29:11 +02:00
|
|
|
|
re->id.u.n.length = length;
|
|
|
|
|
re->id.u.n.name = (unichar *) res_alloc (length * sizeof (unichar));
|
|
|
|
|
for (j = 0; j < length; j++)
|
2015-01-27 18:32:23 +01:00
|
|
|
|
{
|
|
|
|
|
/* PR 17512: file: 05dc4a16. */
|
2016-07-28 16:37:16 +02:00
|
|
|
|
if (length < 0 || ers >= flaginfo->data_end || ers + j * 2 + 4 >= flaginfo->data_end)
|
2015-01-27 18:32:23 +01:00
|
|
|
|
overrun (flaginfo, _("resource name"));
|
|
|
|
|
re->id.u.n.name[j] = windres_get_16 (wrbfd, ers + j * 2 + 2, 2);
|
|
|
|
|
}
|
1999-05-03 09:29:11 +02:00
|
|
|
|
|
|
|
|
|
if (level == 0)
|
|
|
|
|
type = &re->id;
|
|
|
|
|
|
|
|
|
|
if ((rva & 0x80000000) != 0)
|
|
|
|
|
{
|
|
|
|
|
rva &=~ 0x80000000;
|
2012-05-01 18:07:36 +02:00
|
|
|
|
if (rva >= (rc_uint_type) (flaginfo->data_end - flaginfo->data))
|
|
|
|
|
overrun (flaginfo, _("named subdirectory"));
|
1999-05-03 09:29:11 +02:00
|
|
|
|
re->subdir = 1;
|
2012-05-01 18:07:36 +02:00
|
|
|
|
re->u.dir = read_coff_res_dir (wrbfd, flaginfo->data + rva, flaginfo, type,
|
1999-05-03 09:29:11 +02:00
|
|
|
|
level + 1);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2012-05-01 18:07:36 +02:00
|
|
|
|
if (rva >= (rc_uint_type) (flaginfo->data_end - flaginfo->data))
|
|
|
|
|
overrun (flaginfo, _("named resource"));
|
1999-05-03 09:29:11 +02:00
|
|
|
|
re->subdir = 0;
|
2012-05-01 18:07:36 +02:00
|
|
|
|
re->u.res = read_coff_data_entry (wrbfd, flaginfo->data + rva, flaginfo, type);
|
1999-05-03 09:29:11 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*pp = re;
|
|
|
|
|
pp = &re->next;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < id_count; i++, ere++)
|
|
|
|
|
{
|
|
|
|
|
unsigned long name, rva;
|
2007-05-23 10:48:29 +02:00
|
|
|
|
rc_res_entry *re;
|
1999-05-03 09:29:11 +02:00
|
|
|
|
|
2012-05-01 18:07:36 +02:00
|
|
|
|
if ((const bfd_byte *) ere >= flaginfo->data_end)
|
|
|
|
|
overrun (flaginfo, _("ID directory entry"));
|
1999-05-03 09:29:11 +02:00
|
|
|
|
|
2007-05-23 10:48:29 +02:00
|
|
|
|
name = windres_get_32 (wrbfd, ere->name, 4);
|
|
|
|
|
rva = windres_get_32 (wrbfd, ere->rva, 4);
|
1999-05-03 09:29:11 +02:00
|
|
|
|
|
2007-05-23 10:48:29 +02:00
|
|
|
|
re = (rc_res_entry *) res_alloc (sizeof *re);
|
1999-05-03 09:29:11 +02:00
|
|
|
|
re->next = NULL;
|
|
|
|
|
re->id.named = 0;
|
|
|
|
|
re->id.u.id = name;
|
|
|
|
|
|
|
|
|
|
if (level == 0)
|
|
|
|
|
type = &re->id;
|
|
|
|
|
|
|
|
|
|
if ((rva & 0x80000000) != 0)
|
|
|
|
|
{
|
|
|
|
|
rva &=~ 0x80000000;
|
2012-05-01 18:07:36 +02:00
|
|
|
|
if (rva >= (rc_uint_type) (flaginfo->data_end - flaginfo->data))
|
|
|
|
|
overrun (flaginfo, _("ID subdirectory"));
|
1999-05-03 09:29:11 +02:00
|
|
|
|
re->subdir = 1;
|
2012-05-01 18:07:36 +02:00
|
|
|
|
re->u.dir = read_coff_res_dir (wrbfd, flaginfo->data + rva, flaginfo, type,
|
1999-05-03 09:29:11 +02:00
|
|
|
|
level + 1);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2012-05-01 18:07:36 +02:00
|
|
|
|
if (rva >= (rc_uint_type) (flaginfo->data_end - flaginfo->data))
|
|
|
|
|
overrun (flaginfo, _("ID resource"));
|
1999-05-03 09:29:11 +02:00
|
|
|
|
re->subdir = 0;
|
2012-05-01 18:07:36 +02:00
|
|
|
|
re->u.res = read_coff_data_entry (wrbfd, flaginfo->data + rva, flaginfo, type);
|
1999-05-03 09:29:11 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*pp = re;
|
|
|
|
|
pp = &re->next;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return rd;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Read a resource data entry. */
|
|
|
|
|
|
2007-05-23 10:48:29 +02:00
|
|
|
|
static rc_res_resource *
|
|
|
|
|
read_coff_data_entry (windres_bfd *wrbfd, const bfd_byte *data,
|
2012-05-01 18:07:36 +02:00
|
|
|
|
const struct coff_file_info *flaginfo,
|
2007-05-23 10:48:29 +02:00
|
|
|
|
const rc_res_id *type)
|
1999-05-03 09:29:11 +02:00
|
|
|
|
{
|
|
|
|
|
const struct extern_res_data *erd;
|
2007-05-23 10:48:29 +02:00
|
|
|
|
rc_res_resource *r;
|
|
|
|
|
rc_uint_type size, rva;
|
1999-05-03 09:29:11 +02:00
|
|
|
|
const bfd_byte *resdata;
|
|
|
|
|
|
|
|
|
|
if (type == NULL)
|
|
|
|
|
fatal (_("resource type unknown"));
|
|
|
|
|
|
2012-05-01 18:07:36 +02:00
|
|
|
|
if ((size_t) (flaginfo->data_end - data) < sizeof (struct extern_res_data))
|
|
|
|
|
overrun (flaginfo, _("data entry"));
|
1999-05-03 09:29:11 +02:00
|
|
|
|
|
|
|
|
|
erd = (const struct extern_res_data *) data;
|
|
|
|
|
|
2007-05-23 10:48:29 +02:00
|
|
|
|
size = windres_get_32 (wrbfd, erd->size, 4);
|
|
|
|
|
rva = windres_get_32 (wrbfd, erd->rva, 4);
|
2012-05-01 18:07:36 +02:00
|
|
|
|
if (rva < flaginfo->secaddr
|
|
|
|
|
|| rva - flaginfo->secaddr >= (rc_uint_type) (flaginfo->data_end - flaginfo->data))
|
|
|
|
|
overrun (flaginfo, _("resource data"));
|
1999-05-03 09:29:11 +02:00
|
|
|
|
|
2012-05-01 18:07:36 +02:00
|
|
|
|
resdata = flaginfo->data + (rva - flaginfo->secaddr);
|
1999-05-03 09:29:11 +02:00
|
|
|
|
|
2012-05-01 18:07:36 +02:00
|
|
|
|
if (size > (rc_uint_type) (flaginfo->data_end - resdata))
|
|
|
|
|
overrun (flaginfo, _("resource data size"));
|
1999-05-03 09:29:11 +02:00
|
|
|
|
|
2007-05-23 10:48:29 +02:00
|
|
|
|
r = bin_to_res (wrbfd, *type, resdata, size);
|
1999-05-03 09:29:11 +02:00
|
|
|
|
|
2007-05-23 10:48:29 +02:00
|
|
|
|
memset (&r->res_info, 0, sizeof (rc_res_res_info));
|
|
|
|
|
r->coff_info.codepage = windres_get_32 (wrbfd, erd->codepage, 4);
|
|
|
|
|
r->coff_info.reserved = windres_get_32 (wrbfd, erd->reserved, 4);
|
1999-05-03 09:29:11 +02:00
|
|
|
|
|
|
|
|
|
return r;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* This structure is used to build a list of bindata structures. */
|
|
|
|
|
|
|
|
|
|
struct bindata_build
|
|
|
|
|
{
|
|
|
|
|
/* The data. */
|
2007-05-23 10:48:29 +02:00
|
|
|
|
bindata *d;
|
1999-05-03 09:29:11 +02:00
|
|
|
|
/* The last structure we have added to the list. */
|
2007-05-23 10:48:29 +02:00
|
|
|
|
bindata *last;
|
|
|
|
|
/* The size of the list as a whole. */
|
|
|
|
|
unsigned long length;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct coff_res_data_build
|
|
|
|
|
{
|
|
|
|
|
/* The data. */
|
|
|
|
|
coff_res_data *d;
|
|
|
|
|
/* The last structure we have added to the list. */
|
|
|
|
|
coff_res_data *last;
|
1999-05-03 09:29:11 +02:00
|
|
|
|
/* The size of the list as a whole. */
|
|
|
|
|
unsigned long length;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* This structure keeps track of information as we build the directory
|
|
|
|
|
tree. */
|
|
|
|
|
|
|
|
|
|
struct coff_write_info
|
|
|
|
|
{
|
|
|
|
|
/* These fields are based on the BFD. */
|
|
|
|
|
/* The BFD itself. */
|
2007-05-23 10:48:29 +02:00
|
|
|
|
windres_bfd *wrbfd;
|
1999-05-03 09:29:11 +02:00
|
|
|
|
/* Pointer to section symbol used to build RVA relocs. */
|
|
|
|
|
asymbol **sympp;
|
|
|
|
|
|
|
|
|
|
/* These fields are computed initially, and then not changed. */
|
|
|
|
|
/* Length of directory tables and entries. */
|
|
|
|
|
unsigned long dirsize;
|
|
|
|
|
/* Length of directory entry strings. */
|
|
|
|
|
unsigned long dirstrsize;
|
|
|
|
|
/* Length of resource data entries. */
|
|
|
|
|
unsigned long dataentsize;
|
|
|
|
|
|
|
|
|
|
/* These fields are updated as we add data. */
|
|
|
|
|
/* Directory tables and entries. */
|
|
|
|
|
struct bindata_build dirs;
|
|
|
|
|
/* Directory entry strings. */
|
|
|
|
|
struct bindata_build dirstrs;
|
|
|
|
|
/* Resource data entries. */
|
|
|
|
|
struct bindata_build dataents;
|
|
|
|
|
/* Actual resource data. */
|
2007-05-23 10:48:29 +02:00
|
|
|
|
struct coff_res_data_build resources;
|
1999-05-03 09:29:11 +02:00
|
|
|
|
/* Relocations. */
|
|
|
|
|
arelent **relocs;
|
|
|
|
|
/* Number of relocations. */
|
|
|
|
|
unsigned int reloc_count;
|
|
|
|
|
};
|
|
|
|
|
|
2007-05-23 10:48:29 +02:00
|
|
|
|
static void coff_bin_sizes (const rc_res_directory *, struct coff_write_info *);
|
|
|
|
|
static bfd_byte *coff_alloc (struct bindata_build *, rc_uint_type);
|
1999-05-03 09:29:11 +02:00
|
|
|
|
static void coff_to_bin
|
2007-05-23 10:48:29 +02:00
|
|
|
|
(const rc_res_directory *, struct coff_write_info *);
|
1999-05-03 09:29:11 +02:00
|
|
|
|
static void coff_res_to_bin
|
2007-05-23 10:48:29 +02:00
|
|
|
|
(const rc_res_resource *, struct coff_write_info *);
|
1999-05-03 09:29:11 +02:00
|
|
|
|
|
|
|
|
|
/* Write resources to a COFF file. RESOURCES should already be
|
|
|
|
|
sorted.
|
|
|
|
|
|
|
|
|
|
Right now we always create a new file. Someday we should also
|
|
|
|
|
offer the ability to merge resources into an existing file. This
|
|
|
|
|
would require doing the basic work of objcopy, just modifying or
|
|
|
|
|
adding the .rsrc section. */
|
|
|
|
|
|
|
|
|
|
void
|
2003-09-14 14:20:17 +02:00
|
|
|
|
write_coff_file (const char *filename, const char *target,
|
2007-05-23 10:48:29 +02:00
|
|
|
|
const rc_res_directory *resources)
|
1999-05-03 09:29:11 +02:00
|
|
|
|
{
|
|
|
|
|
bfd *abfd;
|
|
|
|
|
asection *sec;
|
|
|
|
|
struct coff_write_info cwi;
|
2007-05-23 10:48:29 +02:00
|
|
|
|
windres_bfd wrbfd;
|
|
|
|
|
bindata *d;
|
|
|
|
|
coff_res_data *rd;
|
1999-05-03 09:29:11 +02:00
|
|
|
|
unsigned long length, offset;
|
|
|
|
|
|
|
|
|
|
if (filename == NULL)
|
|
|
|
|
fatal (_("filename required for COFF output"));
|
|
|
|
|
|
|
|
|
|
abfd = bfd_openw (filename, target);
|
|
|
|
|
if (abfd == NULL)
|
|
|
|
|
bfd_fatal (filename);
|
|
|
|
|
|
|
|
|
|
if (! bfd_set_format (abfd, bfd_object))
|
|
|
|
|
bfd_fatal ("bfd_set_format");
|
|
|
|
|
|
2000-02-24 20:37:32 +01:00
|
|
|
|
#if defined DLLTOOL_SH
|
|
|
|
|
if (! bfd_set_arch_mach (abfd, bfd_arch_sh, 0))
|
|
|
|
|
bfd_fatal ("bfd_set_arch_mach(sh)");
|
|
|
|
|
#elif defined DLLTOOL_MIPS
|
|
|
|
|
if (! bfd_set_arch_mach (abfd, bfd_arch_mips, 0))
|
|
|
|
|
bfd_fatal ("bfd_set_arch_mach(mips)");
|
|
|
|
|
#elif defined DLLTOOL_ARM
|
1999-05-11 23:06:16 +02:00
|
|
|
|
if (! bfd_set_arch_mach (abfd, bfd_arch_arm, 0))
|
|
|
|
|
bfd_fatal ("bfd_set_arch_mach(arm)");
|
|
|
|
|
#else
|
1999-05-03 09:29:11 +02:00
|
|
|
|
/* FIXME: This is obviously i386 specific. */
|
|
|
|
|
if (! bfd_set_arch_mach (abfd, bfd_arch_i386, 0))
|
1999-05-11 23:06:16 +02:00
|
|
|
|
bfd_fatal ("bfd_set_arch_mach(i386)");
|
2000-02-24 20:37:32 +01:00
|
|
|
|
#endif
|
1999-05-03 09:29:11 +02:00
|
|
|
|
|
|
|
|
|
if (! bfd_set_file_flags (abfd, HAS_SYMS | HAS_RELOC))
|
|
|
|
|
bfd_fatal ("bfd_set_file_flags");
|
|
|
|
|
|
2008-07-07 02:44:41 +02:00
|
|
|
|
sec = bfd_make_section_with_flags (abfd, ".rsrc",
|
|
|
|
|
(SEC_HAS_CONTENTS | SEC_ALLOC
|
|
|
|
|
| SEC_LOAD | SEC_DATA));
|
1999-05-03 09:29:11 +02:00
|
|
|
|
if (sec == NULL)
|
|
|
|
|
bfd_fatal ("bfd_make_section");
|
|
|
|
|
|
|
|
|
|
if (! bfd_set_symtab (abfd, sec->symbol_ptr_ptr, 1))
|
|
|
|
|
bfd_fatal ("bfd_set_symtab");
|
|
|
|
|
|
|
|
|
|
/* Requiring this is probably a bug in BFD. */
|
|
|
|
|
sec->output_section = sec;
|
|
|
|
|
|
|
|
|
|
/* The order of data in the .rsrc section is
|
|
|
|
|
resource directory tables and entries
|
|
|
|
|
resource directory strings
|
|
|
|
|
resource data entries
|
|
|
|
|
actual resource data
|
|
|
|
|
|
|
|
|
|
We build these different types of data in different lists. */
|
|
|
|
|
|
2007-05-23 10:48:29 +02:00
|
|
|
|
set_windres_bfd (&wrbfd, abfd, sec, WR_KIND_BFD);
|
|
|
|
|
|
|
|
|
|
cwi.wrbfd = &wrbfd;
|
1999-05-03 09:29:11 +02:00
|
|
|
|
cwi.sympp = sec->symbol_ptr_ptr;
|
|
|
|
|
cwi.dirsize = 0;
|
|
|
|
|
cwi.dirstrsize = 0;
|
|
|
|
|
cwi.dataentsize = 0;
|
|
|
|
|
cwi.dirs.d = NULL;
|
|
|
|
|
cwi.dirs.last = NULL;
|
|
|
|
|
cwi.dirs.length = 0;
|
|
|
|
|
cwi.dirstrs.d = NULL;
|
|
|
|
|
cwi.dirstrs.last = NULL;
|
|
|
|
|
cwi.dirstrs.length = 0;
|
|
|
|
|
cwi.dataents.d = NULL;
|
|
|
|
|
cwi.dataents.last = NULL;
|
|
|
|
|
cwi.dataents.length = 0;
|
|
|
|
|
cwi.resources.d = NULL;
|
|
|
|
|
cwi.resources.last = NULL;
|
|
|
|
|
cwi.resources.length = 0;
|
|
|
|
|
cwi.relocs = NULL;
|
|
|
|
|
cwi.reloc_count = 0;
|
|
|
|
|
|
|
|
|
|
/* Work out the sizes of the resource directory entries, so that we
|
|
|
|
|
know the various offsets we will need. */
|
|
|
|
|
coff_bin_sizes (resources, &cwi);
|
|
|
|
|
|
2013-11-13 13:54:29 +01:00
|
|
|
|
/* Force the directory strings to be 64 bit aligned. Every other
|
|
|
|
|
structure is 64 bit aligned anyhow. */
|
|
|
|
|
cwi.dirstrsize = (cwi.dirstrsize + 7) & ~7;
|
1999-05-03 09:29:11 +02:00
|
|
|
|
|
|
|
|
|
/* Actually convert the resources to binary. */
|
|
|
|
|
coff_to_bin (resources, &cwi);
|
|
|
|
|
|
2013-11-13 13:54:29 +01:00
|
|
|
|
/* Add another few bytes to the directory strings if needed for
|
1999-05-03 09:29:11 +02:00
|
|
|
|
alignment. */
|
2013-11-13 13:54:29 +01:00
|
|
|
|
if ((cwi.dirstrs.length & 7) != 0)
|
1999-05-03 09:29:11 +02:00
|
|
|
|
{
|
2013-11-13 13:54:29 +01:00
|
|
|
|
rc_uint_type pad = 8 - (cwi.dirstrs.length & 7);
|
2007-05-23 10:48:29 +02:00
|
|
|
|
bfd_byte *ex;
|
1999-05-03 09:29:11 +02:00
|
|
|
|
|
2013-11-13 13:54:29 +01:00
|
|
|
|
ex = coff_alloc (& cwi.dirstrs, pad);
|
|
|
|
|
memset (ex, 0, pad);
|
1999-05-03 09:29:11 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Make sure that the data we built came out to the same size as we
|
|
|
|
|
calculated initially. */
|
|
|
|
|
assert (cwi.dirs.length == cwi.dirsize);
|
|
|
|
|
assert (cwi.dirstrs.length == cwi.dirstrsize);
|
|
|
|
|
assert (cwi.dataents.length == cwi.dataentsize);
|
|
|
|
|
|
|
|
|
|
length = (cwi.dirsize
|
|
|
|
|
+ cwi.dirstrsize
|
|
|
|
|
+ cwi.dataentsize
|
|
|
|
|
+ cwi.resources.length);
|
|
|
|
|
|
bfd_section_* macros
This large patch removes the unnecessary bfd parameter from various
bfd section macros and functions. The bfd is hardly ever used and if
needed for the bfd_set_section_* or bfd_rename_section functions can
be found via section->owner except for the com, und, abs, and ind
std_section special sections. Those sections shouldn't be modified
anyway.
The patch also removes various bfd_get_section_<field> macros,
replacing their use with bfd_section_<field>, and adds
bfd_set_section_lma. I've also fixed a minor bug in gas where
compressed section renaming was done directly rather than calling
bfd_rename_section. This would have broken bfd_get_section_by_name
and similar functions, but that hardly mattered at such a late stage
in gas processing.
bfd/
* bfd-in.h (bfd_get_section_name, bfd_get_section_vma),
(bfd_get_section_lma, bfd_get_section_alignment),
(bfd_get_section_size, bfd_get_section_flags),
(bfd_get_section_userdata): Delete.
(bfd_section_name, bfd_section_size, bfd_section_vma),
(bfd_section_lma, bfd_section_alignment): Lose bfd parameter.
(bfd_section_flags, bfd_section_userdata): New.
(bfd_is_com_section): Rename parameter.
* section.c (bfd_set_section_userdata, bfd_set_section_vma),
(bfd_set_section_alignment, bfd_set_section_flags, bfd_rename_section),
(bfd_set_section_size): Delete bfd parameter, rename section parameter.
(bfd_set_section_lma): New.
* bfd-in2.h: Regenerate.
* mach-o.c (bfd_mach_o_init_section_from_mach_o): Delete bfd param,
update callers.
* aoutx.h, * bfd.c, * coff-alpha.c, * coff-arm.c, * coff-mips.c,
* coff64-rs6000.c, * coffcode.h, * coffgen.c, * cofflink.c,
* compress.c, * ecoff.c, * elf-eh-frame.c, * elf-hppa.h,
* elf-ifunc.c, * elf-m10200.c, * elf-m10300.c, * elf-properties.c,
* elf-s390-common.c, * elf-vxworks.c, * elf.c, * elf32-arc.c,
* elf32-arm.c, * elf32-avr.c, * elf32-bfin.c, * elf32-cr16.c,
* elf32-cr16c.c, * elf32-cris.c, * elf32-crx.c, * elf32-csky.c,
* elf32-d10v.c, * elf32-epiphany.c, * elf32-fr30.c, * elf32-frv.c,
* elf32-ft32.c, * elf32-h8300.c, * elf32-hppa.c, * elf32-i386.c,
* elf32-ip2k.c, * elf32-iq2000.c, * elf32-lm32.c, * elf32-m32c.c,
* elf32-m32r.c, * elf32-m68hc1x.c, * elf32-m68k.c, * elf32-mcore.c,
* elf32-mep.c, * elf32-metag.c, * elf32-microblaze.c,
* elf32-moxie.c, * elf32-msp430.c, * elf32-mt.c, * elf32-nds32.c,
* elf32-nios2.c, * elf32-or1k.c, * elf32-ppc.c, * elf32-pru.c,
* elf32-rl78.c, * elf32-rx.c, * elf32-s390.c, * elf32-score.c,
* elf32-score7.c, * elf32-sh.c, * elf32-spu.c, * elf32-tic6x.c,
* elf32-tilepro.c, * elf32-v850.c, * elf32-vax.c, * elf32-visium.c,
* elf32-xstormy16.c, * elf32-xtensa.c, * elf64-alpha.c,
* elf64-bpf.c, * elf64-hppa.c, * elf64-ia64-vms.c, * elf64-mmix.c,
* elf64-ppc.c, * elf64-s390.c, * elf64-sparc.c, * elf64-x86-64.c,
* elflink.c, * elfnn-aarch64.c, * elfnn-ia64.c, * elfnn-riscv.c,
* elfxx-aarch64.c, * elfxx-mips.c, * elfxx-sparc.c,
* elfxx-tilegx.c, * elfxx-x86.c, * i386msdos.c, * linker.c,
* mach-o.c, * mmo.c, * opncls.c, * pdp11.c, * pei-x86_64.c,
* peicode.h, * reloc.c, * section.c, * syms.c, * vms-alpha.c,
* xcofflink.c: Update throughout for bfd section macro and function
changes.
binutils/
* addr2line.c, * bucomm.c, * coffgrok.c, * dlltool.c, * nm.c,
* objcopy.c, * objdump.c, * od-elf32_avr.c, * od-macho.c,
* od-xcoff.c, * prdbg.c, * rdcoff.c, * rddbg.c, * rescoff.c,
* resres.c, * size.c, * srconv.c, * strings.c, * windmc.c: Update
throughout for bfd section macro and function changes.
gas/
* as.c, * as.h, * dw2gencfi.c, * dwarf2dbg.c, * ecoff.c,
* read.c, * stabs.c, * subsegs.c, * subsegs.h, * write.c,
* config/obj-coff-seh.c, * config/obj-coff.c, * config/obj-ecoff.c,
* config/obj-elf.c, * config/obj-macho.c, * config/obj-som.c,
* config/tc-aarch64.c, * config/tc-alpha.c, * config/tc-arc.c,
* config/tc-arm.c, * config/tc-avr.c, * config/tc-bfin.c,
* config/tc-bpf.c, * config/tc-d10v.c, * config/tc-d30v.c,
* config/tc-epiphany.c, * config/tc-fr30.c, * config/tc-frv.c,
* config/tc-h8300.c, * config/tc-hppa.c, * config/tc-i386.c,
* config/tc-ia64.c, * config/tc-ip2k.c, * config/tc-iq2000.c,
* config/tc-lm32.c, * config/tc-m32c.c, * config/tc-m32r.c,
* config/tc-m68hc11.c, * config/tc-mep.c, * config/tc-microblaze.c,
* config/tc-mips.c, * config/tc-mmix.c, * config/tc-mn10200.c,
* config/tc-mn10300.c, * config/tc-msp430.c, * config/tc-mt.c,
* config/tc-nds32.c, * config/tc-or1k.c, * config/tc-ppc.c,
* config/tc-pru.c, * config/tc-rl78.c, * config/tc-rx.c,
* config/tc-s12z.c, * config/tc-s390.c, * config/tc-score.c,
* config/tc-score7.c, * config/tc-sh.c, * config/tc-sparc.c,
* config/tc-spu.c, * config/tc-tic4x.c, * config/tc-tic54x.c,
* config/tc-tic6x.c, * config/tc-tilegx.c, * config/tc-tilepro.c,
* config/tc-v850.c, * config/tc-visium.c, * config/tc-wasm32.c,
* config/tc-xc16x.c, * config/tc-xgate.c, * config/tc-xstormy16.c,
* config/tc-xtensa.c, * config/tc-z8k.c: Update throughout for
bfd section macro and function changes.
* write.c (compress_debug): Use bfd_rename_section.
gdb/
* aarch64-linux-tdep.c, * arm-tdep.c, * auto-load.c,
* coff-pe-read.c, * coffread.c, * corelow.c, * dbxread.c,
* dicos-tdep.c, * dwarf2-frame.c, * dwarf2read.c, * elfread.c,
* exec.c, * fbsd-tdep.c, * gcore.c, * gdb_bfd.c, * gdb_bfd.h,
* hppa-tdep.c, * i386-cygwin-tdep.c, * i386-fbsd-tdep.c,
* i386-linux-tdep.c, * jit.c, * linux-tdep.c, * machoread.c,
* maint.c, * mdebugread.c, * minidebug.c, * mips-linux-tdep.c,
* mips-sde-tdep.c, * mips-tdep.c, * mipsread.c, * nto-tdep.c,
* objfiles.c, * objfiles.h, * osabi.c, * ppc-linux-tdep.c,
* ppc64-tdep.c, * record-btrace.c, * record-full.c, * remote.c,
* rs6000-aix-tdep.c, * rs6000-tdep.c, * s390-linux-tdep.c,
* s390-tdep.c, * solib-aix.c, * solib-dsbt.c, * solib-frv.c,
* solib-spu.c, * solib-svr4.c, * solib-target.c,
* spu-linux-nat.c, * spu-tdep.c, * symfile-mem.c, * symfile.c,
* symmisc.c, * symtab.c, * target.c, * windows-nat.c,
* xcoffread.c, * cli/cli-dump.c, * compile/compile-object-load.c,
* mi/mi-interp.c: Update throughout for bfd section macro and
function changes.
* gcore (gcore_create_callback): Use bfd_set_section_lma.
* spu-tdep.c (spu_overlay_new_objfile): Likewise.
gprof/
* corefile.c, * symtab.c: Update throughout for bfd section
macro and function changes.
ld/
* ldcref.c, * ldctor.c, * ldelf.c, * ldlang.c, * pe-dll.c,
* emultempl/aarch64elf.em, * emultempl/aix.em,
* emultempl/armcoff.em, * emultempl/armelf.em,
* emultempl/cr16elf.em, * emultempl/cskyelf.em,
* emultempl/m68hc1xelf.em, * emultempl/m68kelf.em,
* emultempl/mipself.em, * emultempl/mmix-elfnmmo.em,
* emultempl/mmo.em, * emultempl/msp430.em,
* emultempl/nios2elf.em, * emultempl/pe.em, * emultempl/pep.em,
* emultempl/ppc64elf.em, * emultempl/xtensaelf.em: Update
throughout for bfd section macro and function changes.
libctf/
* ctf-open-bfd.c: Update throughout for bfd section macro changes.
opcodes/
* arc-ext.c: Update throughout for bfd section macro changes.
sim/
* common/sim-load.c, * common/sim-utils.c, * cris/sim-if.c,
* erc32/func.c, * lm32/sim-if.c, * m32c/load.c, * m32c/trace.c,
* m68hc11/interp.c, * ppc/hw_htab.c, * ppc/hw_init.c,
* rl78/load.c, * rl78/trace.c, * rx/gdb-if.c, * rx/load.c,
* rx/trace.c: Update throughout for bfd section macro changes.
2019-09-16 12:55:17 +02:00
|
|
|
|
if (!bfd_set_section_size (sec, length))
|
1999-05-03 09:29:11 +02:00
|
|
|
|
bfd_fatal ("bfd_set_section_size");
|
|
|
|
|
|
|
|
|
|
bfd_set_reloc (abfd, sec, cwi.relocs, cwi.reloc_count);
|
|
|
|
|
|
|
|
|
|
offset = 0;
|
|
|
|
|
for (d = cwi.dirs.d; d != NULL; d = d->next)
|
|
|
|
|
{
|
|
|
|
|
if (! bfd_set_section_contents (abfd, sec, d->data, offset, d->length))
|
|
|
|
|
bfd_fatal ("bfd_set_section_contents");
|
|
|
|
|
offset += d->length;
|
|
|
|
|
}
|
|
|
|
|
for (d = cwi.dirstrs.d; d != NULL; d = d->next)
|
|
|
|
|
{
|
2007-05-23 10:48:29 +02:00
|
|
|
|
set_windres_bfd_content (&wrbfd, d->data, offset, d->length);
|
1999-05-03 09:29:11 +02:00
|
|
|
|
offset += d->length;
|
|
|
|
|
}
|
|
|
|
|
for (d = cwi.dataents.d; d != NULL; d = d->next)
|
|
|
|
|
{
|
2007-05-23 10:48:29 +02:00
|
|
|
|
set_windres_bfd_content (&wrbfd, d->data, offset, d->length);
|
1999-05-03 09:29:11 +02:00
|
|
|
|
offset += d->length;
|
|
|
|
|
}
|
2007-05-23 10:48:29 +02:00
|
|
|
|
for (rd = cwi.resources.d; rd != NULL; rd = rd->next)
|
1999-05-03 09:29:11 +02:00
|
|
|
|
{
|
2007-05-23 10:48:29 +02:00
|
|
|
|
res_to_bin (cwi.wrbfd, (rc_uint_type) offset, rd->res);
|
|
|
|
|
offset += rd->length;
|
1999-05-03 09:29:11 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
assert (offset == length);
|
|
|
|
|
|
|
|
|
|
if (! bfd_close (abfd))
|
|
|
|
|
bfd_fatal ("bfd_close");
|
|
|
|
|
|
|
|
|
|
/* We allocated the relocs array using malloc. */
|
|
|
|
|
free (cwi.relocs);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Work out the sizes of the various fixed size resource directory
|
|
|
|
|
entries. This updates fields in CWI. */
|
|
|
|
|
|
|
|
|
|
static void
|
2007-05-23 10:48:29 +02:00
|
|
|
|
coff_bin_sizes (const rc_res_directory *resdir,
|
2003-09-14 14:20:17 +02:00
|
|
|
|
struct coff_write_info *cwi)
|
1999-05-03 09:29:11 +02:00
|
|
|
|
{
|
2007-05-23 10:48:29 +02:00
|
|
|
|
const rc_res_entry *re;
|
1999-05-03 09:29:11 +02:00
|
|
|
|
|
|
|
|
|
cwi->dirsize += sizeof (struct extern_res_directory);
|
|
|
|
|
|
|
|
|
|
for (re = resdir->entries; re != NULL; re = re->next)
|
|
|
|
|
{
|
|
|
|
|
cwi->dirsize += sizeof (struct extern_res_entry);
|
|
|
|
|
|
|
|
|
|
if (re->id.named)
|
|
|
|
|
cwi->dirstrsize += re->id.u.n.length * 2 + 2;
|
|
|
|
|
|
|
|
|
|
if (re->subdir)
|
|
|
|
|
coff_bin_sizes (re->u.dir, cwi);
|
|
|
|
|
else
|
|
|
|
|
cwi->dataentsize += sizeof (struct extern_res_data);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Allocate data for a particular list. */
|
|
|
|
|
|
2007-05-23 10:48:29 +02:00
|
|
|
|
static bfd_byte *
|
|
|
|
|
coff_alloc (struct bindata_build *bb, rc_uint_type size)
|
1999-05-03 09:29:11 +02:00
|
|
|
|
{
|
2007-05-23 10:48:29 +02:00
|
|
|
|
bindata *d;
|
1999-05-03 09:29:11 +02:00
|
|
|
|
|
2007-05-23 10:48:29 +02:00
|
|
|
|
d = (bindata *) reswr_alloc (sizeof (bindata));
|
1999-05-03 09:29:11 +02:00
|
|
|
|
|
|
|
|
|
d->next = NULL;
|
2007-05-23 10:48:29 +02:00
|
|
|
|
d->data = (bfd_byte *) reswr_alloc (size);
|
1999-05-03 09:29:11 +02:00
|
|
|
|
d->length = size;
|
|
|
|
|
|
|
|
|
|
if (bb->d == NULL)
|
|
|
|
|
bb->d = d;
|
|
|
|
|
else
|
|
|
|
|
bb->last->next = d;
|
|
|
|
|
bb->last = d;
|
|
|
|
|
bb->length += size;
|
|
|
|
|
|
|
|
|
|
return d->data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Convert the resource directory RESDIR to binary. */
|
|
|
|
|
|
|
|
|
|
static void
|
2007-05-23 10:48:29 +02:00
|
|
|
|
coff_to_bin (const rc_res_directory *resdir, struct coff_write_info *cwi)
|
1999-05-03 09:29:11 +02:00
|
|
|
|
{
|
|
|
|
|
struct extern_res_directory *erd;
|
|
|
|
|
int ci, cn;
|
2007-05-23 10:48:29 +02:00
|
|
|
|
const rc_res_entry *e;
|
1999-05-03 09:29:11 +02:00
|
|
|
|
struct extern_res_entry *ere;
|
|
|
|
|
|
|
|
|
|
/* Write out the directory table. */
|
|
|
|
|
|
|
|
|
|
erd = ((struct extern_res_directory *)
|
|
|
|
|
coff_alloc (&cwi->dirs, sizeof (*erd)));
|
|
|
|
|
|
2007-05-23 10:48:29 +02:00
|
|
|
|
windres_put_32 (cwi->wrbfd, erd->characteristics, resdir->characteristics);
|
|
|
|
|
windres_put_32 (cwi->wrbfd, erd->time, resdir->time);
|
|
|
|
|
windres_put_16 (cwi->wrbfd, erd->major, resdir->major);
|
|
|
|
|
windres_put_16 (cwi->wrbfd, erd->minor, resdir->minor);
|
1999-05-03 09:29:11 +02:00
|
|
|
|
|
|
|
|
|
ci = 0;
|
|
|
|
|
cn = 0;
|
|
|
|
|
for (e = resdir->entries; e != NULL; e = e->next)
|
|
|
|
|
{
|
|
|
|
|
if (e->id.named)
|
|
|
|
|
++cn;
|
|
|
|
|
else
|
|
|
|
|
++ci;
|
|
|
|
|
}
|
|
|
|
|
|
2007-05-23 10:48:29 +02:00
|
|
|
|
windres_put_16 (cwi->wrbfd, erd->name_count, cn);
|
|
|
|
|
windres_put_16 (cwi->wrbfd, erd->id_count, ci);
|
1999-05-03 09:29:11 +02:00
|
|
|
|
|
|
|
|
|
/* Write out the data entries. Note that we allocate space for all
|
|
|
|
|
the entries before writing them out. That permits a recursive
|
|
|
|
|
call to work correctly when writing out subdirectories. */
|
|
|
|
|
|
|
|
|
|
ere = ((struct extern_res_entry *)
|
|
|
|
|
coff_alloc (&cwi->dirs, (ci + cn) * sizeof (*ere)));
|
|
|
|
|
for (e = resdir->entries; e != NULL; e = e->next, ere++)
|
|
|
|
|
{
|
|
|
|
|
if (! e->id.named)
|
2007-05-23 10:48:29 +02:00
|
|
|
|
windres_put_32 (cwi->wrbfd, ere->name, e->id.u.id);
|
1999-05-03 09:29:11 +02:00
|
|
|
|
else
|
|
|
|
|
{
|
2007-05-23 10:48:29 +02:00
|
|
|
|
bfd_byte *str;
|
|
|
|
|
rc_uint_type i;
|
1999-05-03 09:29:11 +02:00
|
|
|
|
|
|
|
|
|
/* For some reason existing files seem to have the high bit
|
|
|
|
|
set on the address of the name, although that is not
|
|
|
|
|
documented. */
|
2007-05-23 10:48:29 +02:00
|
|
|
|
windres_put_32 (cwi->wrbfd, ere->name,
|
|
|
|
|
0x80000000 | (cwi->dirsize + cwi->dirstrs.length));
|
1999-05-03 09:29:11 +02:00
|
|
|
|
|
|
|
|
|
str = coff_alloc (&cwi->dirstrs, e->id.u.n.length * 2 + 2);
|
2007-05-23 10:48:29 +02:00
|
|
|
|
windres_put_16 (cwi->wrbfd, str, e->id.u.n.length);
|
1999-05-03 09:29:11 +02:00
|
|
|
|
for (i = 0; i < e->id.u.n.length; i++)
|
2007-05-23 10:48:29 +02:00
|
|
|
|
windres_put_16 (cwi->wrbfd, str + (i + 1) * sizeof (unichar), e->id.u.n.name[i]);
|
1999-05-03 09:29:11 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (e->subdir)
|
|
|
|
|
{
|
2007-05-23 10:48:29 +02:00
|
|
|
|
windres_put_32 (cwi->wrbfd, ere->rva, 0x80000000 | cwi->dirs.length);
|
1999-05-03 09:29:11 +02:00
|
|
|
|
coff_to_bin (e->u.dir, cwi);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2007-05-23 10:48:29 +02:00
|
|
|
|
windres_put_32 (cwi->wrbfd, ere->rva,
|
|
|
|
|
cwi->dirsize + cwi->dirstrsize + cwi->dataents.length);
|
1999-05-03 09:29:11 +02:00
|
|
|
|
|
|
|
|
|
coff_res_to_bin (e->u.res, cwi);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Convert the resource RES to binary. */
|
|
|
|
|
|
|
|
|
|
static void
|
2007-05-23 10:48:29 +02:00
|
|
|
|
coff_res_to_bin (const rc_res_resource *res, struct coff_write_info *cwi)
|
1999-05-03 09:29:11 +02:00
|
|
|
|
{
|
|
|
|
|
arelent *r;
|
|
|
|
|
struct extern_res_data *erd;
|
2007-05-23 10:48:29 +02:00
|
|
|
|
coff_res_data *d;
|
1999-05-03 09:29:11 +02:00
|
|
|
|
|
|
|
|
|
/* For some reason, although every other address is a section
|
|
|
|
|
offset, the address of the resource data itself is an RVA. That
|
|
|
|
|
means that we need to generate a relocation for it. We allocate
|
|
|
|
|
the relocs array using malloc so that we can use realloc. FIXME:
|
|
|
|
|
This relocation handling is correct for the i386, but probably
|
|
|
|
|
not for any other target. */
|
|
|
|
|
|
|
|
|
|
r = (arelent *) reswr_alloc (sizeof (arelent));
|
|
|
|
|
r->sym_ptr_ptr = cwi->sympp;
|
|
|
|
|
r->address = cwi->dirsize + cwi->dirstrsize + cwi->dataents.length;
|
|
|
|
|
r->addend = 0;
|
2007-05-23 10:48:29 +02:00
|
|
|
|
r->howto = bfd_reloc_type_lookup (WR_BFD (cwi->wrbfd), BFD_RELOC_RVA);
|
1999-05-03 09:29:11 +02:00
|
|
|
|
if (r->howto == NULL)
|
|
|
|
|
bfd_fatal (_("can't get BFD_RELOC_RVA relocation type"));
|
|
|
|
|
|
|
|
|
|
cwi->relocs = xrealloc (cwi->relocs,
|
|
|
|
|
(cwi->reloc_count + 2) * sizeof (arelent *));
|
|
|
|
|
cwi->relocs[cwi->reloc_count] = r;
|
|
|
|
|
cwi->relocs[cwi->reloc_count + 1] = NULL;
|
|
|
|
|
++cwi->reloc_count;
|
|
|
|
|
|
|
|
|
|
erd = (struct extern_res_data *) coff_alloc (&cwi->dataents, sizeof (*erd));
|
|
|
|
|
|
2007-05-23 10:48:29 +02:00
|
|
|
|
windres_put_32 (cwi->wrbfd, erd->rva,
|
1999-05-03 09:29:11 +02:00
|
|
|
|
(cwi->dirsize
|
|
|
|
|
+ cwi->dirstrsize
|
|
|
|
|
+ cwi->dataentsize
|
2007-05-23 10:48:29 +02:00
|
|
|
|
+ cwi->resources.length));
|
|
|
|
|
windres_put_32 (cwi->wrbfd, erd->codepage, res->coff_info.codepage);
|
|
|
|
|
windres_put_32 (cwi->wrbfd, erd->reserved, res->coff_info.reserved);
|
1999-05-03 09:29:11 +02:00
|
|
|
|
|
2007-05-23 10:48:29 +02:00
|
|
|
|
d = (coff_res_data *) reswr_alloc (sizeof (coff_res_data));
|
|
|
|
|
d->length = res_to_bin (NULL, (rc_uint_type) 0, res);
|
|
|
|
|
d->res = res;
|
|
|
|
|
d->next = NULL;
|
1999-05-03 09:29:11 +02:00
|
|
|
|
|
|
|
|
|
if (cwi->resources.d == NULL)
|
|
|
|
|
cwi->resources.d = d;
|
|
|
|
|
else
|
|
|
|
|
cwi->resources.last->next = d;
|
|
|
|
|
|
|
|
|
|
cwi->resources.last = d;
|
2013-11-13 13:54:29 +01:00
|
|
|
|
cwi->resources.length += (d->length + 7) & ~7;
|
1999-05-03 09:29:11 +02:00
|
|
|
|
|
2007-05-23 10:48:29 +02:00
|
|
|
|
windres_put_32 (cwi->wrbfd, erd->size, d->length);
|
1999-05-03 09:29:11 +02:00
|
|
|
|
|
2013-11-13 13:54:29 +01:00
|
|
|
|
/* Force the next resource to have 64 bit alignment. */
|
|
|
|
|
d->length = (d->length + 7) & ~7;
|
1999-05-03 09:29:11 +02:00
|
|
|
|
}
|