Age | Commit message (Collapse) | Author | Files | Lines |
|
Don't overload bfd_reloc_outofrange with what is really a domain error
(target at odd address), or an overflow.
PR 11290
* reloc.c (bfd_reloc_other): Correct comment.
* elf32-avr.c (avr_final_link_relocate): Return bfd_reloc_other
for unaligned reloc target values. Return bfd_reloc_overflow
when stubs are too far away and when R_AVR_LDS_STS_16,
R_AVR_PORT6, or R_AVR_PORT5 overflow.
(elf32_avr_relocate_section): Report more descriptive relocation
errors.
* bfd-in2.h: Regenerate.
|
|
|
|
Fix the bug that can not generate func@plt
when linking a undefined function with cmodel=medium.
Add testcase.
bfd/
* elfnn-loongarch.c
ld/testsuite/ld-loongarch-elf/
* cmodel-libjirl.dd
* cmodel.exp
* libjirl.s
|
|
|
|
I don't think it makes any sense for a SHT_RELR section to specify a
symbol table with sh_link. SHT_RELR relocations don't use symbols.
There is no real need to specify sh_info either, SHT_RELR is not for
relocatable object files. Anyway, fuzzers of course don't restrict
themselves to even half-sensible objects. So they found a hole in
objcopy using a non-alloc SHT_RELR in an ET_EXEC. In that case BFD
set up the SHT_RELR section as if it were a SHT_REL against the
sh_info target section. When it came to reading in the target section
relocs, the count was horribly wrong which caused a buffer overflow.
* elf.c (bfd_section_from_shdr <SHT_RELR>): Always just make a
normal section, don't treat it as a reloc section.
|
|
Further to commit 7744e3278b9f.
* elf.c (bfd_elf_set_group_contents): Restrict loc in loop writing
contents, and add another assertion.
|
|
|
|
* config.bfd (aarch64-*-openbsd*): Add target.
|
|
|
|
|
|
If symbols are provided by the caller of this function they are
passed on to bfd_get_relocated_section_contents. No surprises there.
It gets a little weird if they are not provided. In that case they
are read from the bfd by _bfd_generic_link_add_symbols, and global
symbols are added to the generic linker hash table. Global symbols
are not added to the linker hash table if symbols *are* provided. Now
the linker hash table symbols are not used by the generic
bfd_get_relocated_section_conents, and also not by most target
versions when called from bfd_simple_get_relocated_section_contents
except for symbols like "_gp". So it mostly doesn't matter whether
symbols are in the linker hash table, but it's odd that there is a
difference. We could always add them, but I'm inclined to think that
is unnecessary work so this patch always leaves them out.
Also, symbols are canonicalized and written into a malloc'd buffer.
The buffer isn't freed, see commit 8e16317ca5eb. I don't know whether
that matters any more, but in any case I can't see why we need another
copy of the symbols when _bfd_generic_link_read_symbols has already
cached symbols.
* simple.c (bfd_simple_get_relocated_section_contents): If not
provided, read symbols via bfd_generic_link_read_symbols. Do
not create another copy of symbols. Tidy failure exits.
Minor tidy of bfd_get_relocated_section_contents and
bfd_get_full_section_contents arguments.
|
|
|
|
Like commit a9c09a3667cc, but for loongarch64.
* coff-loongarch64.c (SWAP_IN_RELOC_OFFSET): Define.
(SWAP_OUT_RELOC_OFFSET): Define.
|
|
|
|
|
|
objcopy of broken SHT_GROUP sections shouldn't write garbage.
* elf.c (bfd_elf_set_group_contents): If number of entries is
unexpected, fill out section with zeros.
|
|
Fix mmo_get_byte to return a fail-safe value, not just on the first
call with a read error but on subsequent calls too.
* mmo.c (mmo_get_byte): Return the fail-safe value on every
call after a read error.
|
|
* mmo.c (mmo_make_section): Alloc name using bfd_alloc. Use
bfd_error_no_memory.
(mmo_decide_section): Check for NULL return from mmo_make_section.
|
|
mmo_get_loc needs to handle arbitrary vma and size chunks. Fuzzers
found that it wasn't working so well when the end of chunks were
getting close to address wrap-around.
* mmo.c (mmo_get_loc): Make "size" unsigned. Avoid arithmetic
overflow when calculating whether range hits an existing chunk.
|
|
Swap params of is_note, so they are section, segment like others used
in rewrite_elf_program_header. Whitespace fixes, plus wrapping of
overlong lines.
|
|
|
|
In commit 68e80d96a84282d547f3b3c1234c99009521630c, the usage of
___lc_codepage_func was introduced to determine the current encoding.
Prior to version 9.0 of MinGW-w64, the function prototype for
___lc_codepage_func was missing and trying to build BFD caused the
following error:
error: implicit declaration of function ‘___lc_codepage_func’
This changeset adds a conditonal definition of
___lc_codepage_func to allow a sucessful build with MinGW-w64.
Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@foss.st.com>
|
|
This patch, in order of significance:
1) Replaces some macros with inline functions.
2) Those inline functions catch and avoid arithmetic overflows when
comparing addresses.
3) When assigning sections to segments (IS_SECTION_IN_INPUT_SEGMENT)
use bed->want_p_paddr_set_to_zero to decide whether lma vs p_paddr
or vma vs p_vaddr should be tested. When remapping, use the same
test, and use is_note rather than the more restrictive
IS_COREFILE_NOTE.
It's important that the later tests not be more restrictive. If they
are it can lead to the situation triggered by the testcases, where a
section seemingly didn't fit and thus needed a new mapping. It didn't
fit the new mapping either, and this repeated until memory exhausted.
PR 29495
* elf.c (SEGMENT_END, SECTION_SIZE, IS_CONTAINED_BY_VMA): Delete.
(IS_CONTAINED_BY_LMA, IS_NOTE, IS_COREFILE_NOTE): Delete.
(segment_size, segment_end, section_size): New inline function.
(is_contained_by, is_note): Likewise.
(rewrite_elf_program_header): Use new functions.
|
|
|
|
I know this target is just a skeleton, but let's not write out relocs
with uninitialised garbage.
* coff-aarch64.c (SWAP_IN_RELOC_OFFSET): Define.
(SWAP_OUT_RELOC_OFFSET): Define.
|
|
|
|
|
|
PR 29482
* coffcode.h (coff_set_section_contents): Sanity check _LIB.
|
|
* elf32-spu.c (spu_elf_object_p): Don't dereference NULL
shdr->bfd_section.
|
|
* libhppa.h (sign_extend): Avoid undefined behaviour.
|
|
* som.c (som_set_reloc_info): Ignore non-existent previous
fixup references.
|
|
|
|
|
|
They were legacy relocation types copied from other ports. The related
-fvtable-gc was removed from GCC in 2003.
The associated assembler directives (.vtable_inherit and .vtable_entry)
have never been supported by the RISC-V port. Remove related ld code.
Link: https://github.com/riscv-non-isa/riscv-elf-psabi-doc/pull/323
|
|
|
|
|
|
This adds support for efi-loongarch64 by virtue of adding a new PEI target
pei-loongarch64. This is not a full target and only exists to support EFI at
this time.
This means that this target does not support relocation processing and is mostly
a container format. This format has been added to elf based loongarch64 targets
such that efi images can be made natively on Linux.
However this target is not valid for use with gas but only with objcopy.
We should't limit addresses to 32-bits for 64-bit vma, otherwise there will be
"RVA truncated" error when using objcopy on loongarch64.
With these changes the resulting file is recognized as an efi image.
Any magic number is based on the Microsoft PE specification [1].
The test results are as follows:
$ make check-binutils RUNTESTFLAGS='loongarch64.exp'
PASS: Check if efi app format is recognized
$ objdump -h -f tmpdir/loongarch64copy.o
tmpdir/loongarch64copy.o: file format pei-loongarch64
architecture: Loongarch64, flags 0x00000132:
EXEC_P, HAS_SYMS, HAS_LOCALS, D_PAGED
start address 0x0000000000000000
Sections:
Idx Name Size VMA LMA File off Algn
0 .text 0000003c 00000000200000b0 00000000200000b0 00000200 2**2
CONTENTS, ALLOC, LOAD, READONLY, CODE
[1] https://docs.microsoft.com/en-us/windows/win32/debug/pe-format
bfd:
* .gitignore (pe-loongarch64igen.c): New.
* Makefile.am (pei-loongarch64.lo, pe-loongarch64igen.lo, pei-loongarch64.c,
pe-loongarch64igen.c): Add support.
* Makefile.in: Likewise.
* bfd.c (bfd_get_sign_extend_vma): Add pei-loongarch64.
* coff-loongarch64.c: New file.
* coffcode.h (coff_set_arch_mach_hook, coff_set_flags,
coff_write_object_contents) Add loongarch64 (loongarch64_pei_vec) support.
* config.bfd: Likewise.
* configure: Likewise.
* configure.ac: Likewise.
* libpei.h (GET_OPTHDR_IMAGE_BASE, PUT_OPTHDR_IMAGE_BASE,
GET_OPTHDR_SIZE_OF_STACK_RESERVE, PUT_OPTHDR_SIZE_OF_STACK_RESERVE,
GET_OPTHDR_SIZE_OF_STACK_COMMIT, PUT_OPTHDR_SIZE_OF_STACK_COMMIT,
GET_OPTHDR_SIZE_OF_HEAP_RESERVE, PUT_OPTHDR_SIZE_OF_HEAP_RESERVE,
GET_OPTHDR_SIZE_OF_HEAP_COMMIT, PUT_OPTHDR_SIZE_OF_HEAP_COMMIT,
GET_PDATA_ENTRY, _bfd_peLoongArch64_bfd_copy_private_bfd_data_common,
_bfd_peLoongArch64_bfd_copy_private_section_data,
_bfd_peLoongArch64_get_symbol_info, _bfd_peLoongArch64_only_swap_filehdr_out,
_bfd_peLoongArch64_print_private_bfd_data_common,
_bfd_peLoongArch64i_final_link_postscript,
_bfd_peLoongArch64i_only_swap_filehdr_out, _bfd_peLoongArch64i_swap_aouthdr_in,
_bfd_peLoongArch64i_swap_aouthdr_out, _bfd_peLoongArch64i_swap_aux_in,
_bfd_peLoongArch64i_swap_aux_out, _bfd_peLoongArch64i_swap_lineno_in,
_bfd_peLoongArch64i_swap_lineno_out, _bfd_peLoongArch64i_swap_scnhdr_out,
_bfd_peLoongArch64i_swap_sym_in, _bfd_peLoongArch64i_swap_sym_out,
_bfd_peLoongArch64i_swap_debugdir_in, _bfd_peLoongArch64i_swap_debugdir_out,
_bfd_peLoongArch64i_write_codeview_record,
_bfd_peLoongArch64i_slurp_codeview_record,
_bfd_peLoongArch64_print_ce_compressed_pdata): New.
* peXXigen.c (_bfd_XXi_swap_aouthdr_in, _bfd_XXi_swap_aouthdr_out,
_bfd_XXi_swap_scnhdr_out, pe_print_pdata, _bfd_XX_print_private_bfd_data_common,
_bfd_XX_bfd_copy_private_section_data, _bfd_XXi_final_link_postscript):
Support COFF_WITH_peLoongArch64,
* pei-loongarch64.c: New file.
* peicode.h (coff_swap_scnhdr_in, pe_ILF_build_a_bfd, pe_ILF_object_p):
Support COFF_WITH_peLoongArch64.
(jtab): Add dummy entry that traps.
* targets.c (loongarch64_pei_vec): New.
binutils
* testsuite/binutils-all/loongarch64/loongarch64.exp: New file.
* testsuite/binutils-all/loongarch64/pei-loongarch64.d: New test.
* testsuite/binutils-all/loongarch64/pei-loongarch64.s: New test.
include
* coff/loongarch64.h: New file.
* coff/pe.h (IMAGE_FILE_MACHINE_LOONGARCH64): New.
Signed-off-by: Youling Tang <tangyouling@loongson.cn>
|
|
|
|
|
|
While using perf top for MozillaThunderbird I noticed quite some slow
dissably call with source code involved. E.g.
time ./objdump --start-address=0x0000000004e0dcd0 --stop-address=0x0000000004e0df8b -l -d --no-show-raw-insn -S -C /usr/lib64/thunderbird/libxul.so
took 2.071s and I noticed quite some time is spent in
find_abstract_instance:
33.46% objdump objdump [.] find_abstract_instance
18.22% objdump objdump [.] arange_add
13.77% objdump objdump [.] read_attribute_value
4.82% objdump objdump [.] comp_unit_maybe_decode_line_info
3.10% objdump libc.so.6 [.] __memset_avx2_unaligned_erms
where linked list of CU is iterated when searing for where info_ptr
belongs to:
: 3452 for (u = unit->prev_unit; u != NULL; u = u->prev_unit)
0.00 : 4c61f7: mov 0x10(%rbx),%rax
0.00 : 4c61fb: test %rax,%rax
0.00 : 4c61fe: je 4c6215 <find_abstract_instance+0x365>
: 3453 if (info_ptr >= u->info_ptr_unit && info_ptr < u->end_ptr)
0.00 : 4c6200: cmp 0x60(%rax),%rdx
83.20 : 4c6204: jb 4c620c <find_abstract_instance+0x35c>
0.00 : 4c6206: cmp 0x78(%rax),%rdx
6.89 : 4c620a: jb 4c6270 <find_abstract_instance+0x3c0>
: 3452 for (u = unit->prev_unit; u != NULL; u = u->prev_unit)
0.00 : 4c620c: mov 0x10(%rax),%rax
7.90 : 4c6210: test %rax,%rax
0.00 : 4c6213: jne 4c6200 <find_abstract_instance+0x350>
The following scan can be replaced with search in a splay tree and with
that I can get to 1.5s and there are other symbols where the difference
is even bigger.
bfd/ChangeLog:
PR 29081
* dwarf2.c (struct addr_range): New.
(addr_range_intersects): Likewise.
(splay_tree_compare_addr_range): Likewise.
(splay_tree_free_addr_range): Likewise.
(struct dwarf2_debug_file): Add comp_unit_tree.
(find_abstract_instance): Use the splay tree when searching
for a info_ptr.
(stash_comp_unit): Insert to the splay tree.
(_bfd_dwarf2_cleanup_debug_info): Clean up the splay tree.
|
|
The following simple test case fails when dwz is used:
$ cat demo.C
namespace std {
enum { _S_fixed, _S_floatfield = _S_fixed };
struct {
struct {};
}
__ioinit;
}
int main() {
return 0;
}
$ g++ demo.C -g && cp a.out b.out && dwz -m xxx.so a.out b.out && objdump -S a.out >/dev/null
objdump: DWARF error: could not find variable specification at offset 0x3d3
As seen the reference is defined in xxx.so shared part:
$ eu-readelf -w -N a.out | grep -A3 -B3 3d3
decl_column (data1) 11
sibling (ref_udata) [ 387]
[ 387] variable abbrev: 30
specification (GNU_ref_alt) [ 3d3]
location (exprloc)
[ 0] addr 0x404019
[ 396] subprogram abbrev: 32
$ eu-readelf -w -N a.out | less
...
Compilation unit at offset 920:
Version: 5, Abbreviation section offset: 0, Address size: 8, Offset size: 4
Unit type: partial (3)
...
[ 3d3] variable abbrev: 31
name (strp) "__ioinit"
decl_file (data1) demo.C (10)
decl_line (data1) 6
decl_column (data1) 3
type (ref_udata) [ 3c4]
declaration (flag_present) yes
With the patch the same output is emitted as before usage of dwz.
bfd/ChangeLog:
PR 29442
* dwarf2.c (struct varinfo): Use const char * type.
(scan_unit_for_symbols): Call find_abstract_instance for
DW_AT_specification for variables that can be in a different CU
(e.g. done by dwz)
|
|
|
|
|
|
On coff_slurp_symbol_table printing "unrecognized storage class"
for a symbol error. If the symbol name is the last string in its
section and not terminated, we run off the end of the buffer.
* coffgen.c (build_debug_section): Terminate the section with
an extra 0.
|
|
More fuzzed input file nonsense.
* coffgen.c (coff_write_symbol): Don't call coff_write_auxent_fname
when extrap is NULL.
|
|
Catches fuzzed input with unterminated strings that later run off the
end of their buffers when calling strlen.
* mach-o.c: Use size_t vars where approprite.
(bfd_mach_o_alloc_and_read): Add "extra" param. Allocate that
much extra and clear. Update all callers, those that set up
strings with one extra byte.
|
|
bfd_set_section_alignment currently always returns true. This patch
changes it to return false on silly alignment values, avoiding yet
another way to trigger ubsan errors like coffcode.h:3192:12: runtime
error: shift exponent 299 is too large for 32-bit type 'int'. We'll
catch that one in objcopy.c:setup_sections. However, setup_sections
gives up on other setup operations that are necessary even after an
error of some sort. Change that to keep going, which might change the
error message but that shouldn't matter in the least.
bfd/
* section.c (bfd_set_section_alignment): Return false and
don't set alignment_power for stupidly large alignments.
* bfd-in2.h: Regenerate.
* coffcode.h (coff_compute_section_file_positions): Don't use
an int constant when calculating alignment.
binutils/
* objcopy.c (setup_section): Keep on going after hitting
non-fatal errors.
|
|
Do the shift using unsigned variables to avoid UB on << 8.
* som.c (som_set_reloc_info): Make v unsigned. Localise some
variables to their blocks.
|
|
|
|
Remove the BFD_VMA_FMT defines in bfd.h and configure support.
* bfd-in.h (BFD_VMA_FMT): Don't define.
* configure.ac (BFD_INT64_FMT): Remove configure test.
* configure.com: Likewise.
* Makefile.in: Regenerate.
* bfd-in2.h: Regenerate.
* configure: Regenerate.
|