[PATCH v3] elf: Only use function size from regular object
Alan Modra
amodra@gmail.com
Sun Sep 13 04:59:00 GMT 2026
If we wanted to go down the path that HJ claims is correct, then the
following on top of v2 would work, but I question the premise of the
patch that ld should not copy any function st_size from a shared
object. We clearly do have a minor bug in pr34585 and not copying any
st_size from a shared library would fix it, but there is another
possible fix which is to copy a zero st_size from the definition.
I'm inclined to think st_size from an actual definition in a shared
library is perhaps useful information about the link-time function.
diff --git a/bfd/elflink.c b/bfd/elflink.c
index 61b80132f98..278c357781d 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -5631,8 +5631,12 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
/* Remember the symbol size if it isn't undefined. */
if (isym->st_shndx != SHN_UNDEF)
{
- if (ELF_ST_TYPE (isym->st_info) == STT_FUNC
- || ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC)
+ if ((ELF_ST_TYPE (isym->st_info) == STT_FUNC
+ || ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC)
+ && !(/* PowerPC64 ELFv1 function descriptor is
+ somewhat like an object symbol. */
+ definition
+ && (h->root.u.def.section->flags & SEC_CODE) == 0))
{
/* Only use function size defined in regular object
since function size defined in shared library at
diff --git a/ld/testsuite/ld-elf/pr34585a.rd b/ld/testsuite/ld-elf/pr34585a.rd
index a930c464002..edbcd567388 100644
--- a/ld/testsuite/ld-elf/pr34585a.rd
+++ b/ld/testsuite/ld-elf/pr34585a.rd
@@ -1,5 +1,5 @@
Symbol table '\.dynsym' contains [0-9]+ entries:
+Num: +Value +Size Type +Bind +Vis +Ndx Name
#...
- +[0-9]+: +[0-9a-f]+ +0 +FUNC +GLOBAL +DEFAULT +[0-9]+ +foo
+ +[0-9]+: +[0-9a-f]+ +0 +FUNC +GLOBAL +DEFAULT .* foo
#pass
diff --git a/ld/testsuite/ld-elf/pr34585b.rd b/ld/testsuite/ld-elf/pr34585b.rd
index e0a8ac203c6..a4a8d25d693 100644
--- a/ld/testsuite/ld-elf/pr34585b.rd
+++ b/ld/testsuite/ld-elf/pr34585b.rd
@@ -1,5 +1,5 @@
Symbol table '\.dynsym' contains [0-9]+ entries:
+Num: +Value +Size Type +Bind +Vis +Ndx Name
#...
- +[0-9]+: +[0-9a-f]+ +40 +FUNC +GLOBAL +DEFAULT +[0-9]+ +foo
+ +[0-9]+: +[0-9a-f]+ +40 +FUNC +GLOBAL +DEFAULT .* foo
#pass
--
Alan Modra
More information about the Binutils
mailing list