diff --git a/ld/emultempl/aarch64elf.em b/ld/emultempl/aarch64elf.em index 8a123106e3df3a0236cf818051430b5ef27eca8e..11512a127db039066f6c11e6132f7089d0528994 100644 --- a/ld/emultempl/aarch64elf.em +++ b/ld/emultempl/aarch64elf.em @@ -330,6 +330,43 @@ gld${EMULATION_NAME}_finish (void) } finish_default (); + + struct bfd_link_hash_entry * h; + struct elf_link_hash_entry * eh; + + if (!entry_symbol.name) + return; + + h = bfd_link_hash_lookup (link_info.hash, entry_symbol.name, + FALSE, FALSE, TRUE); + eh = (struct elf_link_hash_entry *)h; + if (!h || !(eh->target_internal & ST_BRANCH_TO_C64)) + return; + if (h->type != bfd_link_hash_defined + && h->type != bfd_link_hash_defweak) + return; + if (h->u.def.section->output_section == NULL) + return; + + static char buffer[67]; + bfd_vma val; + + /* Special procesing is required for a C64 entry symbol. The + bottom bit of its address must be set. */ + val = (h->u.def.value + + bfd_section_vma (h->u.def.section->output_section) + + h->u.def.section->output_offset); + + val |= 1; + + /* Now convert this value into a string and store it in entry_symbol + where the lang_end() function will pick it up. */ + buffer[0] = '0'; + buffer[1] = 'x'; + + sprintf_vma (buffer + 2, val); + + entry_symbol.name = buffer; } /* This is a convenient point to tell BFD about target specific flags. diff --git a/ld/testsuite/ld-aarch64/aarch64-elf.exp b/ld/testsuite/ld-aarch64/aarch64-elf.exp index 721d16e09bc1392fbc5e7920a080962bb4b374a2..9352db42e9913021d17a8e5dd8d7d8cf2125fe29 100644 --- a/ld/testsuite/ld-aarch64/aarch64-elf.exp +++ b/ld/testsuite/ld-aarch64/aarch64-elf.exp @@ -269,6 +269,7 @@ run_dump_test_lp64 "morello-sec-round-data-only" run_dump_test_lp64 "morello-sec-round-include-relro" run_dump_test_lp64 "morello-pcc-bounds-include-readonly" run_dump_test_lp64 "morello-sec-round-choose-linker-syms" +run_dump_test_lp64 "morello-entry-point" run_dump_test_lp64 "morello-tlsdesc" run_dump_test_lp64 "morello-tlsdesc-static" run_dump_test_lp64 "morello-tlsdesc-staticpie" diff --git a/ld/testsuite/ld-aarch64/morello-entry-point.d b/ld/testsuite/ld-aarch64/morello-entry-point.d new file mode 100644 index 0000000000000000000000000000000000000000..29fb431199b977f1714da9d792f9da79e182339a --- /dev/null +++ b/ld/testsuite/ld-aarch64/morello-entry-point.d @@ -0,0 +1,10 @@ +# Checking that the entry point address of a binary with a c64 function symbol +# as the entry address is odd (i.e. has the LSB set). +#source: emit-relocs-morello-2.s +#as: -march=morello+c64 +#ld: -static +#readelf: --file-header + +#... + Entry point address: 0x.*[13579] +#pass