[PATCH] Mark _PROCEDURE_LINKAGE_TABLE_ as code instead of data
Yu-Cheng Liang
yclwlcy@gmail.com
Mon Feb 10 08:17:45 GMT 2025
The .plt section should be treated as code instead of data.
Signed-off-by: Yu-Cheng Liang <yclwlcy@gmail.com>
---
bfd/elf-bfd.h | 2 +-
bfd/elf-m10300.c | 4 ++--
bfd/elf32-bfin.c | 2 +-
bfd/elf32-cr16.c | 2 +-
bfd/elf32-frv.c | 4 ++--
bfd/elf32-ppc.c | 2 +-
bfd/elf32-tilepro.c | 2 +-
bfd/elf64-alpha.c | 4 ++--
bfd/elflink.c | 16 +++++++++++-----
bfd/elfnn-aarch64.c | 2 +-
bfd/elfnn-kvx.c | 2 +-
bfd/elfnn-loongarch.c | 2 +-
bfd/elfnn-riscv.c | 2 +-
bfd/elfxx-mips.c | 4 ++--
bfd/elfxx-tilegx.c | 2 +-
15 files changed, 29 insertions(+), 23 deletions(-)
diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h
index c89327fdc9c..2893a9d30fc 100644
--- a/bfd/elf-bfd.h
+++ b/bfd/elf-bfd.h
@@ -2594,7 +2594,7 @@ extern bool _bfd_elf_create_got_section
extern asection *_bfd_elf_section_for_symbol
(struct elf_reloc_cookie *, unsigned long, bool);
extern struct elf_link_hash_entry *_bfd_elf_define_linkage_sym
- (bfd *, struct bfd_link_info *, asection *, const char *);
+ (bfd *, struct bfd_link_info *, asection *, const char *, bool);
extern void _bfd_elf_init_1_index_section
(bfd *, struct bfd_link_info *);
extern void _bfd_elf_init_2_index_sections
diff --git a/bfd/elf-m10300.c b/bfd/elf-m10300.c
index ed399da904c..84d9b93ab61 100644
--- a/bfd/elf-m10300.c
+++ b/bfd/elf-m10300.c
@@ -734,7 +734,7 @@ _bfd_mn10300_elf_create_got_section (bfd * abfd,
if (bed->want_plt_sym)
{
h = _bfd_elf_define_linkage_sym (abfd, info, s,
- "_PROCEDURE_LINKAGE_TABLE_");
+ "_PROCEDURE_LINKAGE_TABLE_", true);
htab->hplt = h;
if (h == NULL)
return false;
@@ -759,7 +759,7 @@ _bfd_mn10300_elf_create_got_section (bfd * abfd,
(or .got.plt) section. We don't do this in the linker script
because we don't want to define the symbol if we are not creating
a global offset table. */
- h = _bfd_elf_define_linkage_sym (abfd, info, s, "_GLOBAL_OFFSET_TABLE_");
+ h = _bfd_elf_define_linkage_sym (abfd, info, s,
"_GLOBAL_OFFSET_TABLE_", false);
htab->hgot = h;
if (h == NULL)
return false;
diff --git a/bfd/elf32-bfin.c b/bfd/elf32-bfin.c
index 547661a3098..a4c575b1f3e 100644
--- a/bfd/elf32-bfin.c
+++ b/bfd/elf32-bfin.c
@@ -3217,7 +3217,7 @@ _bfin_create_got_section (bfd *abfd, struct
bfd_link_info *info)
(or .got.plt) section. We don't do this in the linker script
because we don't want to define the symbol if we are not creating
a global offset table. */
- h = _bfd_elf_define_linkage_sym (abfd, info, s,
"__GLOBAL_OFFSET_TABLE_");
+ h = _bfd_elf_define_linkage_sym (abfd, info, s,
"__GLOBAL_OFFSET_TABLE_", false);
elf_hash_table (info)->hgot = h;
if (h == NULL)
return false;
diff --git a/bfd/elf32-cr16.c b/bfd/elf32-cr16.c
index 68ac71f69e5..e614fd731c2 100644
--- a/bfd/elf32-cr16.c
+++ b/bfd/elf32-cr16.c
@@ -627,7 +627,7 @@ _bfd_cr16_elf_create_got_section (bfd * abfd,
struct bfd_link_info * info)
(or .got.plt) section. We don't do this in the linker script
because we don't want to define the symbol if we are not creating
a global offset table. */
- h = _bfd_elf_define_linkage_sym (abfd, info, s, "_GLOBAL_OFFSET_TABLE_");
+ h = _bfd_elf_define_linkage_sym (abfd, info, s,
"_GLOBAL_OFFSET_TABLE_", false);
htab->hgot = h;
if (h == NULL)
return false;
diff --git a/bfd/elf32-frv.c b/bfd/elf32-frv.c
index a7e8215ff5e..b5a1d314ade 100644
--- a/bfd/elf32-frv.c
+++ b/bfd/elf32-frv.c
@@ -4201,7 +4201,7 @@ _frv_create_got_section (bfd *abfd, struct
bfd_link_info *info)
(or .got.plt) section. We don't do this in the linker script
because we don't want to define the symbol if we are not creating
a global offset table. */
- h = _bfd_elf_define_linkage_sym (abfd, info, s, "_GLOBAL_OFFSET_TABLE_");
+ h = _bfd_elf_define_linkage_sym (abfd, info, s,
"_GLOBAL_OFFSET_TABLE_", false);
elf_hash_table (info)->hgot = h;
if (h == NULL)
return false;
@@ -4295,7 +4295,7 @@ _frv_create_got_section (bfd *abfd, struct
bfd_link_info *info)
if (bed->want_plt_sym)
{
h = _bfd_elf_define_linkage_sym (abfd, info, s,
- "_PROCEDURE_LINKAGE_TABLE_");
+ "_PROCEDURE_LINKAGE_TABLE_", true);
elf_hash_table (info)->hplt = h;
if (h == NULL)
return false;
diff --git a/bfd/elf32-ppc.c b/bfd/elf32-ppc.c
index f17effdf176..63952ae1229 100644
--- a/bfd/elf32-ppc.c
+++ b/bfd/elf32-ppc.c
@@ -2365,7 +2365,7 @@ ppc_elf_create_linker_section (bfd *abfd,
/* Define the sym on the first section of this name. */
s = bfd_get_section_by_name (abfd, lsect->name);
- lsect->sym = _bfd_elf_define_linkage_sym (abfd, info, s, lsect->sym_name);
+ lsect->sym = _bfd_elf_define_linkage_sym (abfd, info, s,
lsect->sym_name, false);
if (lsect->sym == NULL)
return false;
lsect->sym->root.u.def.value = 0x8000;
diff --git a/bfd/elf32-tilepro.c b/bfd/elf32-tilepro.c
index 6f901725524..9f14b303104 100644
--- a/bfd/elf32-tilepro.c
+++ b/bfd/elf32-tilepro.c
@@ -1247,7 +1247,7 @@ tilepro_elf_create_got_section (bfd *abfd,
struct bfd_link_info *info)
to define the symbol if we are not creating a global offset
table. */
h = _bfd_elf_define_linkage_sym (abfd, info, s_got,
- "_GLOBAL_OFFSET_TABLE_");
+ "_GLOBAL_OFFSET_TABLE_", false);
elf_hash_table (info)->hgot = h;
if (h == NULL)
return false;
diff --git a/bfd/elf64-alpha.c b/bfd/elf64-alpha.c
index b3570cebf5a..dc1f7cdae7b 100644
--- a/bfd/elf64-alpha.c
+++ b/bfd/elf64-alpha.c
@@ -1306,7 +1306,7 @@ elf64_alpha_create_dynamic_sections (bfd *abfd,
struct bfd_link_info *info)
/* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
.plt section. */
h = _bfd_elf_define_linkage_sym (abfd, info, s,
- "_PROCEDURE_LINKAGE_TABLE_");
+ "_PROCEDURE_LINKAGE_TABLE_", true);
elf_hash_table (info)->hplt = h;
if (h == NULL)
return false;
@@ -1349,7 +1349,7 @@ elf64_alpha_create_dynamic_sections (bfd *abfd,
struct bfd_link_info *info)
because we don't want to define the symbol if we are not creating
a global offset table. */
h = _bfd_elf_define_linkage_sym (abfd, info, alpha_elf_tdata(abfd)->got,
- "_GLOBAL_OFFSET_TABLE_");
+ "_GLOBAL_OFFSET_TABLE_", false);
elf_hash_table (info)->hgot = h;
if (h == NULL)
return false;
diff --git a/bfd/elflink.c b/bfd/elflink.c
index 27b02dd404f..266bc497e83 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -143,7 +143,8 @@ struct elf_link_hash_entry *
_bfd_elf_define_linkage_sym (bfd *abfd,
struct bfd_link_info *info,
asection *sec,
- const char *name)
+ const char *name,
+ bool is_code_section)
{
struct elf_link_hash_entry *h;
struct bfd_link_hash_entry *bh;
@@ -172,7 +173,12 @@ _bfd_elf_define_linkage_sym (bfd *abfd,
h->def_regular = 1;
h->non_elf = 0;
h->root.linker_def = 1;
- h->type = STT_OBJECT;
+
+ if (is_code_section)
+ h->type = STT_FUNC;
+ else
+ h->type = STT_OBJECT;
+
if (ELF_ST_VISIBILITY (h->other) != STV_INTERNAL)
h->other = (h->other & ~ELF_ST_VISIBILITY (-1)) | STV_HIDDEN;
@@ -230,7 +236,7 @@ _bfd_elf_create_got_section (bfd *abfd, struct
bfd_link_info *info)
because we don't want to define the symbol if we are not creating
a global offset table. */
h = _bfd_elf_define_linkage_sym (abfd, info, s,
- "_GLOBAL_OFFSET_TABLE_");
+ "_GLOBAL_OFFSET_TABLE_", false);
elf_hash_table (info)->hgot = h;
if (h == NULL)
return false;
@@ -363,7 +369,7 @@ _bfd_elf_link_create_dynamic_sections (bfd *abfd,
struct bfd_link_info *info)
section. We don't want to define it if there is no .dynamic
section, since on some ELF platforms the start up code examines it
to decide how to initialize the process. */
- h = _bfd_elf_define_linkage_sym (abfd, info, s, "_DYNAMIC");
+ h = _bfd_elf_define_linkage_sym (abfd, info, s, "_DYNAMIC", false);
elf_hash_table (info)->hdynamic = h;
if (h == NULL)
return false;
@@ -454,7 +460,7 @@ _bfd_elf_create_dynamic_sections (bfd *abfd,
struct bfd_link_info *info)
if (bed->want_plt_sym)
{
h = _bfd_elf_define_linkage_sym (abfd, info, s,
- "_PROCEDURE_LINKAGE_TABLE_");
+ "_PROCEDURE_LINKAGE_TABLE_", true);
elf_hash_table (info)->hplt = h;
if (h == NULL)
return false;
diff --git a/bfd/elfnn-aarch64.c b/bfd/elfnn-aarch64.c
index 1fe0b615800..bca9cb40403 100644
--- a/bfd/elfnn-aarch64.c
+++ b/bfd/elfnn-aarch64.c
@@ -7784,7 +7784,7 @@ aarch64_elf_create_got_section (bfd *abfd,
struct bfd_link_info *info)
because we don't want to define the symbol if we are not creating
a global offset table. */
h = _bfd_elf_define_linkage_sym (abfd, info, s,
- "_GLOBAL_OFFSET_TABLE_");
+ "_GLOBAL_OFFSET_TABLE_", false);
elf_hash_table (info)->hgot = h;
if (h == NULL)
return false;
diff --git a/bfd/elfnn-kvx.c b/bfd/elfnn-kvx.c
index 3720c5122c4..9bcb8a266ca 100644
--- a/bfd/elfnn-kvx.c
+++ b/bfd/elfnn-kvx.c
@@ -3178,7 +3178,7 @@ kvx_elf_create_got_section (bfd *abfd, struct
bfd_link_info *info)
because we don't want to define the symbol if we are not creating
a global offset table. */
h = _bfd_elf_define_linkage_sym (abfd, info, s,
- "_GLOBAL_OFFSET_TABLE_");
+ "_GLOBAL_OFFSET_TABLE_", false);
elf_hash_table (info)->hgot = h;
if (h == NULL)
return false;
diff --git a/bfd/elfnn-loongarch.c b/bfd/elfnn-loongarch.c
index efa57184e44..9614c89cae3 100644
--- a/bfd/elfnn-loongarch.c
+++ b/bfd/elfnn-loongarch.c
@@ -640,7 +640,7 @@ loongarch_elf_create_got_section (bfd *abfd,
struct bfd_link_info *info)
section. We don't do this in the linker script because we don't want
to define the symbol if we are not creating a global offset table. */
h = _bfd_elf_define_linkage_sym (abfd, info, s_got,
- "_GLOBAL_OFFSET_TABLE_");
+ "_GLOBAL_OFFSET_TABLE_", false);
elf_hash_table (info)->hgot = h;
if (h == NULL)
return false;
diff --git a/bfd/elfnn-riscv.c b/bfd/elfnn-riscv.c
index 57ced95fdb3..03a0be16bfd 100644
--- a/bfd/elfnn-riscv.c
+++ b/bfd/elfnn-riscv.c
@@ -582,7 +582,7 @@ riscv_elf_create_got_section (bfd *abfd, struct
bfd_link_info *info)
to define the symbol if we are not creating a global offset
table. */
h = _bfd_elf_define_linkage_sym (abfd, info, s_got,
- "_GLOBAL_OFFSET_TABLE_");
+ "_GLOBAL_OFFSET_TABLE_", false);
elf_hash_table (info)->hgot = h;
if (h == NULL)
return false;
diff --git a/bfd/elfxx-mips.c b/bfd/elfxx-mips.c
index e428ae278ba..2df2788a3c1 100644
--- a/bfd/elfxx-mips.c
+++ b/bfd/elfxx-mips.c
@@ -9885,7 +9885,7 @@ mips_elf_lay_out_lazy_stubs (struct bfd_link_info *info)
dynobj = elf_hash_table (info)->dynobj;
BFD_ASSERT (dynobj != NULL);
- h = _bfd_elf_define_linkage_sym (dynobj, info, htab->sstubs, "_MIPS_STUBS_");
+ h = _bfd_elf_define_linkage_sym (dynobj, info, htab->sstubs,
"_MIPS_STUBS_", false);
if (h == NULL)
return false;
h->root.u.def.value = isa_bit;
@@ -10057,7 +10057,7 @@ _bfd_mips_elf_late_size_sections (bfd *output_bfd,
if (htab->root.hplt == NULL)
{
h = _bfd_elf_define_linkage_sym (dynobj, info, htab->root.splt,
- "_PROCEDURE_LINKAGE_TABLE_");
+ "_PROCEDURE_LINKAGE_TABLE_", true);
htab->root.hplt = h;
if (h == NULL)
return false;
diff --git a/bfd/elfxx-tilegx.c b/bfd/elfxx-tilegx.c
index afa9e86add5..88ef22fa7e7 100644
--- a/bfd/elfxx-tilegx.c
+++ b/bfd/elfxx-tilegx.c
@@ -1463,7 +1463,7 @@ tilegx_elf_create_got_section (bfd *abfd, struct
bfd_link_info *info)
to define the symbol if we are not creating a global offset
table. */
h = _bfd_elf_define_linkage_sym (abfd, info, s_got,
- "_GLOBAL_OFFSET_TABLE_");
+ "_GLOBAL_OFFSET_TABLE_", false);
elf_hash_table (info)->hgot = h;
if (h == NULL)
return false;
--
2.47.1
More information about the Binutils
mailing list