Remove `-Wshadow' compilation errors:
cc1: warnings being treated as errors
.../bfd/wasm-module.c: In function 'wasm_scan_name_function_section':
.../bfd/wasm-module.c:312: error: declaration of 'index' shadows a global declaration
/usr/include/string.h:303: error: shadowed declaration is here
.../bfd/wasm-module.c: In function 'wasm_register_section':
.../bfd/wasm-module.c:494: error: declaration of 'index' shadows a global declaration
/usr/include/string.h:303: error: shadowed declaration is here
.../bfd/wasm-module.c: In function 'wasm_compute_custom_section_file_position':
.../bfd/wasm-module.c:523: error: declaration of 'index' shadows a global declaration
/usr/include/string.h:303: error: shadowed declaration is here
and:
cc1: warnings being treated as errors
.../opcodes/wasm32-dis.c: In function 'print_insn_wasm32':
.../opcodes/wasm32-dis.c:272: error: declaration of 'index' shadows a global declaration
/usr/include/string.h:303: error: shadowed declaration is here
make[4]: *** [wasm32-dis.lo] Error 1
which for versions of GCC before 4.8 prevent support for the WebAssembly
target from being built. See also GCC PR c/53066.
bfd/
* wasm-module.c (wasm_scan_name_function_section): Rename
`index' local variable to `idx'.
opcodes/
* wasm32-dis.c (print_insn_wasm32): Rename `index' local
variable to `function_index'.
This fixes the case where all of a group is removed with ld -r, the
situation in the PR, and failures where part of a group is removed
that contain relocs.
bfd/
PR 22836
* elf.c (_bfd_elf_fixup_group_sections): Account for removed
relocation sections. If size reduces to just the flag word,
remove that too and mark with SEC_EXCLUDE.
* elflink.c (bfd_elf_final_link): Strip empty group sections.
binutils/
* testsuite/binutils-all/group-7.s,
* testsuite/binutils-all/group-7a.d,
* testsuite/binutils-all/group-7b.d,
* testsuite/binutils-all/group-7c.d: New tests.
* testsuite/binutils-all/objcopy.exp: Run them.
ld/
* testsuite/ld-elf/pr22836-2.d,
* testsuite/ld-elf/pr22836-2.s: New test.
lld lays out the relro segment differently to GNU ld, not bothering to
include the first few bytes of .got.plt and padding out to a page at
the end of the segment. This patch teaches binutils to recognize the
different (and somewhat inferior) layout as valid.
bfd/
PR 22829
* elf.c (assign_file_positions_for_non_load_sections): Rewrite
PT_GNU_RELRO setup.
ld/
* testsuite/ld-x86-64/pr14207.d: Adjust relro p_filesz.
See email thread starting here: https://www.sourceware.org/ml/binutils/2018-01/msg00001.html
include * coff/msdos.h: New header.
* coff/pe.h: Move common defines to msdos.h.
* coff/powerpc.h: Likewise.
bfd * i386msdos.c (msdos_mkobject); New function.
(msdos_object_p): New function.
(i386_msdos_vec): Use msdos_object_p as the check_format
function.
* peicode.h: Rename external_PEI_DOS_hdr, DOSMAGIC, and
NT_SIGNATURE to external_DOS_hdr, IMAGE_DOS_SIGNATURE, and
IMAGE_NT_SIGNATURE.
* peXXigen.c: Likewise.
* coff-ia64.c: Likewise.
There are 2 failures left in the linker testsuite on SPARC64/Linux and
they are caused by 2 different issues leading to the same end effect:
the overflow of the relocation section for the GOT, i.e. the linker
generates too many dynamic relocations for the GOT wrt the size of the
relocation section, leading to memory corruption and missing relocations
in the final binary.
The first issue was introduced by:
https://sourceware.org/ml/binutils/2017-06/msg00368.html
which makes the linker generate more R_SPARC_RELATIVE relocations for
the GOT without adjusting the size of the relocation section. This is
fixed by (1) preventively adjusting this size in allocate_dynrelocs and
(2) generating R_SPARC_NONE if needed when R_SPARC_GOTDATA_OP is relaxed.
The second issue is that we generate a GOT relocation for an undefined
weak symbol with non-default visibility in a PIC binary without accounting
for that in the size of the relocation section. Since the address of the
symbol should resolve to 0 at run time, it is fixed by not generating the
relocation at all, i.e. leaving the GOT entry zeroed.
bfd/
* elfxx-sparc.c (UNDEFINED_WEAK_RESOLVED_TO_ZERO): Reorder conditions.
(sparc_elf_append_rela): Assert that there is enough room in section.
(_bfd_sparc_elf_copy_indirect_symbol): Fix formatting.
(_bfd_sparc_elf_adjust_dynamic_symbol): Minor tweak.
(allocate_dynrelocs): Remove outdated comments and reorder conditions.
For a symbol subject to a GOT relocation, reserve a slot in the
relocation section if the symbol isn't dynamic and we are in PIC mode.
(_bfd_sparc_elf_relocate_section) <R_SPARC_GOTDATA_OP>: If relocation
is relaxed and a slot was reserved, generate a R_SPARC_NONE relocation.
<R_SPARC_GOTDATA_OP_HIX22>: Adjust comments.
<R_SPARC_PC10>: Reorder conditions. Remove always-false assertion.
(_bfd_sparc_elf_finish_dynamic_symbol): Rename local_undefweak into
resolved_to_zero. Do not generate a dynamic GOT relocation for an
undefined weak symbol with non-default visibility. Remove superfluous
'else' and fix formatting.
Solaris requires to keep _GLOBAL_OFFSET_TABLE_ even if it isn't used.
This patch detects Solaris target and keeps _GLOBAL_OFFSET_TABLE_ for
Solaris.
* elf32-i386.c (elf32_i386_copy_solaris_special_section_fields):
New prototype.
(elf_i386_link_setup_gnu_properties): Set need_global_offset_table
for Solaris.
* elf64-x86-64.c (elf64_x86_64_copy_solaris_special_section_fields):
New prototype.
(elf_x86_64_link_setup_gnu_properties): Set
need_global_offset_table for Solaris.
* elfxx-x86.c (_bfd_x86_elf_size_dynamic_sections): Keep the
unused _GLOBAL_OFFSET_TABLE_ for Solaris.
(_bfd_x86_elf_link_setup_gnu_properties): Copy
need_global_offset_table.
* elfxx-x86.h (elf_x86_link_hash_table): Add
need_global_offset_table.
(elf_x86_init_table): Likewise.
This reverts most of commit 1be5d8d3bb.
Left in place are addition of --no-plt-align to some ppc32 ld tests
and the ld.texinfo --no-plt-thread-safe fix.
This is -fpie -pie generating dynamic relocations in the text section,
simply because no TLS transitions are applied in PIE mode. The meat
of the patch is to turn calls to bfd_link_pic (info) in TLS-related code
into !bfd_link_executable (info) and there are quite a lot of them...
bfd/
* elfxx-sparc.c (sparc_elf_tls_transition): Turn call to bfd_link_pic
into call to !bfd_link_executable and tidy up.
(_bfd_sparc_elf_check_relocs): Fix formatting and tidy up.
<R_SPARC_TLS_LE_HIX22>: Turn call to bfd_link_pic into call to
!bfd_link_executable.
<R_SPARC_TLS_IE_HI22>: Likewise.
<GOT relocations>: Remove useless code, tidy and merge blocks.
<R_SPARC_TLS_GD_CALL>: Turn call to bfd_link_pic into call to
!bfd_link_executable.
<R_SPARC_WPLT30>: Tidy up.
(_bfd_sparc_elf_gc_mark_hook): Turn call to bfd_link_pic into call
to !bfd_link_executable.
(allocate_dynrelocs): Likewise.
(_bfd_sparc_elf_relocate_section): Fix formatting and tidy up.
<R_SPARC_TLS_GD_HI22>: Merge into...
<R_SPARC_TLS_GD_LO10>: ...this. Adjust 4th argument in call to
sparc_elf_tls_transition and remove redundant code.
<R_SPARC_TLS_LDM_HI22>: Turn call to bfd_link_pic into call to
!bfd_link_executable.
<R_SPARC_TLS_LDO_HIX22>: Likewise.
<R_SPARC_TLS_LE_HIX22>: Likewise. Tidy up.
<R_SPARC_TLS_LDM_CALL>: Likewise.
<R_SPARC_TLS_GD_CALL>: Likewise. Tidy up.
<R_SPARC_TLS_GD_ADD>: Likewise.
<R_SPARC_TLS_LDM_ADD>: Likewise.
<R_SPARC_TLS_LDO_ADD>: Likewise.
<R_SPARC_TLS_IE_LD>: Likewise.
ld/
* testsuite/ld-elf/tls.exp (AFLAGS_PIC): Define on SPARC.
(pr22263-1): Pass AFLAGS_PIC to the assembler.
* testsuite/ld-sparc/tlspie32.s: Add test for other 3 transitions.
* testsuite/ld-sparc/tlspie32.dd: Adjust to above.
* testsuite/ld-sparc/tlspie64.s: Add test for other 3 transitions.
* testsuite/ld-sparc/tlspie64.dd: Adjust to above.
PR 22789
* elfxx-mips.c (_bfd_mips_elf_find_nearest_line): If the dwarf
functions failed to find the function name, try the generic elf
find function instead.
GCC 8 will bring a new warning option which will detect possible
overflow and truncation on string manipulation functions. For more
details, see:
https://gcc.gnu.org/ml/gcc-patches/2017-08/msg00471.html
While compiling BFD with it, I can see one place on bfd/coff-rs6000.c
where the warning is triggered. This:
(void) strncpy (fhdr.magic, XCOFFARMAG, SXCOFFARMAG);
will not include the trailing NUL on fhdr.magic, but that's fine
because it's a magic number. The fix is trivial: just use memcpy
instead.
OK to push?
2018-02-06 Sergio Durigan Junior <sergiodj@redhat.com>
* coff-rs6000.c (xcoff_write_archive_contents_old): Use
'memcpy' instead of 'strncpy' when writing the magic number.
PR 22794
* opncls.c (bfd_get_debug_link_info_1): Check the size of the
section before attempting to read it in.
(bfd_get_alt_debug_link_info): Likewise.
The nm utility supports -l for using debug information to obtain file and line information for each symbol, if available.
We have a tool that consumes this information and displays it.
This identified a problem with the 'nm' utility.
When a source is compiled with -O2, functions can be inlined. The compiler also produces an uninlined copy of the function, normally for linking to other object files.
In the case of DWARF2 debug information, the compiler generates debug information to describe a function. If that function is inlined, the compiler then references that debug information from the inlined and uninlined copies of the routine through the use of the DW_AT_abstract_origin reference.
When nm is used on such a file, it is not able to find file and line information because that information is present in the common debug information and not at each actual implementation of the function.
The 'nm' utility only retrieves the name of the function from the abstract origin debug information and no more.
What I am proposing is to modify the find_abstract_instance_name() function (which I renamed to find_abstract_instance() ) to return the name of the function as well as any file and line information. The routine is already parsing all of the debug information in the abstract instance, so it is easy to pick up the file and line information at that time. If, for some reason, the file and line information is not present, the routine behaves as before.
For example, if I have a simple test case:
int foo(int j)
{
if (j < 15)
j += j << 2;
else
j += j << 6;
return j;
}
int main (int argc,char **argv)
{
int i = argc;
i += foo(i);
return i;
}
If that test case is compiled with -O2 and then 'nm -l' reads that executable, it currently produces this symbol output (ignoring a lot of library symbols):
8048400 T foo
080482e0 T main /scratch/pcarroll/its254/test/mytest.c:12
If I modify 'nm' to return file and line information for abstract instances, it produces the following output:
08048400 T foo /scratch/pcarroll/its254/test/mytest.c:1
080482e0 T main /scratch/pcarroll/its254/test/mytest.c:12
--------------------------------------------------------------------------
bfd * bfd/dwarf2.c (find_abstract_name): Modified to return file and
line information in addition to name, if they can be found.
The assumption that R_AARCH64_ABS16 and R_AARCH64_ABS32 relocation in LP64 abi
will be used to generate an address does not hold for absolute symbol.
In this case, it is a value fixed at static linking time.
The condition to check the relocations is relax to allow absolute symbol and
undefined symbol case.
bfd/
2018-02-05 Renlin Li <renlin.li@arm.com>
PR ld/22764
* elfnn-aarch64.c (elfNN_aarch64_check_relocs): Relax the
R_AARCH64_ABS32 and R_AARCH64_ABS16 for absolute symbol. Apply the
check for writeable section as well.
ld/
2018-02-05 Renlin Li <renlin.li@arm.com>
PR ld/22764
* testsuite/ld-aarch64/emit-relocs-258.s: Define symbol as an address.
* testsuite/ld-aarch64/emit-relocs-259.s: Likewise.
* testsuite/ld-aarch64/aarch64-elf.exp: Run new test.
* testsuite/ld-aarch64/pr22764.s: New.
* testsuite/ld-aarch64/pr22764.d: New.
Since _GLOBAL_OFFSET_TABLE_ may be referenced implicitly on x86,
checking ref_regular_nonweak leaves the unused _GLOBAL_OFFSET_TABLE_
in output. This patch checks explicit GOT references instead.
ld-i386/discarded1.s and ld-x86-64/discarded1.s are updated to avoid
linker optimization which removes GOT references.
bfd/
PR ld/22782
* elf32-i386.c (elf_i386_check_relocs): Set got_referenced if
_GLOBAL_OFFSET_TABLE_ is referenced or GOT is needed to resolve
undefined weak symbol to 0.
* elf64-x86-64.c (elf_x86_64_check_relocs): Set got_referenced
if _GLOBAL_OFFSET_TABLE_ is referenced.
* elfxx-x86.c (_bfd_x86_elf_size_dynamic_sections): Check
got_referenced instead of ref_regular_nonweak. Remove the
unused _GLOBAL_OFFSET_TABLE_ from symbol table.
* elfxx-x86.h (elf_x86_link_hash_table): Add got_referenced.
ld/
PR ld/22782
* testsuite/ld-i386/discarded1.s: Replace mov with div.
* testsuite/ld-x86-64/discarded1.s: Likewise.
* testsuite/ld-i386/i386.exp: Run pr22782.
* testsuite/ld-i386/load1-nacl.d: Updated for removing
_GLOBAL_OFFSET_TABLE_ from output.
* testsuite/ld-i386/load1.d: Likewise.
* testsuite/ld-x86-64/load1a-nacl.d: Likewise.
* testsuite/ld-x86-64/load1a.d: Likewise.
* testsuite/ld-x86-64/load1b-nacl.d: Likewise.
* testsuite/ld-x86-64/load1b.d: Likewise.
* testsuite/ld-i386/pr22782.d: New file.
* testsuite/ld-i386/pr22782.s: Likewise.
* testsuite/ld-x86-64/pr22782.s: Likewise.
* testsuite/ld-x86-64/pr22782a.d: Likewise.
* testsuite/ld-x86-64/pr22782b.d: Likewise.
* testsuite/ld-x86-64/x86-64.exp: Run pr22782a and pr22782b.
Correct a commit 9d06997adb ("RISC-V: Relax RISCV_PCREL_* to
RISCV_GPREL_*") regression and remove a `-Wmissing-field-initializers'
compilation error:
cc1: warnings being treated as errors
.../bfd/elfnn-riscv.c: In function '_bfd_riscv_relax_pc':
.../bfd/elfnn-riscv.c:3117: error: missing initializer
.../bfd/elfnn-riscv.c:3117: error: (near initialization for 'hi_reloc.hi_addend')
make[4]: *** [elf64-riscv.lo] Error 1
which for versions of GCC before 4.7 prevents support for RISC-V targets
from being built. See also GCC PR c/36750.
bfd/
* elfnn-riscv.c (_bfd_riscv_relax_pc): Use `memset' to
initialize `hi_reloc'.
Report an error when an unsupported `.reginfo' section size is found in
`_bfd_mips_elf_section_processing', removing an assertion that triggers
at elfxx-mips.c:7105 in GAS when assembling input like:
.section .reginfo
.word 0xdeadbeef
and in `objcopy --rename-section' when renaming an incorrectly sized
section to `.reginfo'.
bfd/
* elfxx-mips.c (_bfd_mips_elf_section_processing): For
SHT_MIPS_REGINFO sections don't assert the correct size and
report an error instead.
binutils/
* testsuite/binutils-all/mips/mips-reginfo.d: New test.
* testsuite/binutils-all/mips/mips-reginfo-n32.d: New test.
* testsuite/binutils-all/mips/mips-reginfo.s: New test source.
* testsuite/binutils-all/mips/mips.exp: Run the new tests.
gas/
* testsuite/gas/mips/reginfo-2.d: New test.
* testsuite/gas/mips/reginfo-2-n32.d: New test.
* testsuite/gas/mips/reginfo-2.l: New test stderr output.
* testsuite/gas/mips/reginfo-2.s: New test source.
* testsuite/gas/mips/mips.exp: Run the new tests.
Fix the issue of any failure from `->elf_backend_section_processing'
not being propagated by `_bfd_elf_write_object_contents'. The MIPS
`_bfd_mips_elf_section_processing' handler can actually potentially
fail, however the caller currently ignores that.
bfd/
* elf.c (_bfd_elf_write_object_contents): Propagate a failure
status from `->elf_backend_section_processing'.
bfd/
PR ld/22756
* elfnn-riscv.c (riscv_relax_delete_bytes): New parameter link_info.
If link_info->wrap_hash, check for a duplicate symbol and ignore.
(_bfd_riscv_relax_call, bfd_riscv_relax_lui, _bfd_riscv_relax_tls_le):
Pass new argument to riscv_relax_delete_bytes.
(_bfd_riscv_relax_align, _bfd_riscv_relax_delete): Likewise. Remove
ATTRIBUTE_UNUSED from link_info parameter.
This fixes a "bug" in that nops emitted as part of code optimization
were being relocated. As it happens the relocation value was always
zero so the nop wasn't changed. Whew! I've also moved the use of
"howto" later since I was caught out in some recent code changes with
the howto not matching r_type.
* elf64-ppc.c (ppc64_elf_relocate_section): Don't relocate nops
emitted for toc sequence optimization. Set and use "howto" later.
bfdI would like to fix instances of the following warning, when building
with clang with no special CFLAGS other than -g3 -O0.
/home/emaisin/src/binutils-gdb/bfd/elflink.c:5425:45: error: performing pointer arithmetic on a null pointer has undefined behavior [-Werror,-Wnull-pointer-arithmetic]
return (struct elf_link_hash_entry *) 0 - 1;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^
Replacing those with "(struct elf_link_hash_entry *) -1" gets rid of the
warning. I wanted to check that it didn't change the resulting code, so
I tried to build this:
$ cat test.c
int *before()
{
return (int *) 0 - 1;
}
int *after()
{
return (int *) - 1;
}
$ gcc -c test.c -g
$ objdump -d test.o
test.o: file format elf64-x86-64
Disassembly of section .text:
0000000000000000 <before>:
0: 55 push %rbp
1: 48 89 e5 mov %rsp,%rbp
4: 48 c7 c0 fc ff ff ff mov $0xfffffffffffffffc,%rax
b: 5d pop %rbp
c: c3 retq
000000000000000d <after>:
d: 55 push %rbp
e: 48 89 e5 mov %rsp,%rbp
11: 48 c7 c0 ff ff ff ff mov $0xffffffffffffffff,%rax
18: 5d pop %rbp
19: c3 retq
This shows that the previous code doesn't actually return -1 as the
function documentation says, but the new one does, so it's kind of a
bugfix.
bfd * elf64-ppc.c (ppc64_elf_archive_symbol_lookup): Avoid pointer
arithmetic on NULL pointer.
* elflink.c (_bfd_elf_archive_symbol_lookup,
elf_link_add_archive_symbols): Likewise.
ld * ldexp.c (fold_name, exp_fold_tree_1): Avoid pointer arithmetic
on NULL pointer.
We really need to check for a dynamic def, not only a ref.
See added testcase.
bfd/
* elflink.c (bfd_elf_define_start_stop): Fix check of
def_dynamic.
ld/
* testsuite/ld-elf/pr21964-5.c: New test.
* testsuite/ld-elf/shared.exp: Run it.
Define __start/__stop symbols if they are referenced by shared objects,
not if they are also defined in shared objects.
bfd/
PR ld/21964
* elflink.c (bfd_elf_define_start_stop): Check if __start and
__stop symbols are referenced by shared objects.
ld/
PR ld/21964
* testsuite/ld-elf/pr21964-4.c: New file.
* testsuite/ld-elf/shared.exp: Run pr21964-4 test on Linux.
We can't map different disk pages into the same memory page; The last
page mapped will simply overwrite any previous pages. The
executable/non-executable new_segment test ignored this fact, leading
to a ld.so segfault on hppa when .dynamic is overwritten with zeros.
This patch moves existing tests for demand paging with lma on the same
memory page, to a new test performed before any case where we want a
new segment due to protection or loadable conflicts.
PR 22758
* elf.c (_bfd_elf_map_sections_to_segments): Don't start a new
segment when demand paged with lma on the same page. Test this
before load/non-load, executable/non-executable,
writable/non-writable tests and simplify. Delete bogus relro
condition in writable/non-writable test. Delete outdated
comment. Formatting.
bfd/
* elflink.c (bfd_elf_define_start_stop): Make __start and __stop
symbols dynamic.
ld/
* testsuite/ld-elf/pr21964-3a.c: New file.
* testsuite/ld-elf/pr21964-3c.c: New file.
* testsuite/ld-elf/shared.exp: Run new __start/__stop testcase.