This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: GENERATE_SHLIB_SCRIPT vs. EMBEDDED
On Thu, Nov 07, 2019 at 10:25:14AM -0700, Nathan Chancellor wrote:
> On Thu, Nov 07, 2019 at 06:13:30PM +1030, Alan Modra wrote:
> > On Thu, Nov 07, 2019 at 12:37:00AM -0700, Nathan Chancellor wrote:
> > > For what it's worth, this breaks building the Linux kernel for me:
> > >
> > > aarch64-linux-ld: -shared not supported
> >
> > An aarch64-linux ld will use emulparams/aarch64linux.sh, which does
> > have shared support. If you're trying to use binutils configured for
> > aarch64-elf on Linux, well, good luck with that.
>
> As it turns out, this error is related to the arm64 Linux kernel using
> the ELF emulation mode by default, falling back to the Linux one if it
> is not supported. See the following commits:
>
> https://git.kernel.org/linus/38fc4248677552ce35efc09902fdcb06b61d7ef9
> https://git.kernel.org/linus/96f95a17c1cfe65a002e525114d96616e91a8f2d
> https://git.kernel.org/linus/c931d34ea0853d41349e93f871bd3f17f1c03a6b
Ah, now your report is starting to make more sense. The Linux kernel
makes use of -shared to build the kernel vdso and when building a
relocatable kernel. In both cases the ELF file header and program
headers are not needed to load those images.
However, in any other shared library the headers must be present for
the binary to be loaded by ld.so. That's what I meant with my comment
"good luck with that". So attempting to build an aarch64-linux shared
library using -maarch64elf or -maarch64elfb generally will result in a
non-functional binary. I think the linker should at least warn about
that.
I wonder if the following would work for the aarch64 kernel build?
You might also need -Ttext-segment=0 along with -shared in the kernel
Makefiles since otherwise you'd get a vsdo and relocatable kernel
linked at something other than a zero base address.
diff --git a/ld/lexsup.c b/ld/lexsup.c
index d7766c3c55..f28245b0ca 100644
--- a/ld/lexsup.c
+++ b/ld/lexsup.c
@@ -1187,33 +1187,25 @@ parse_args (unsigned argc, char **argv)
link_info.prohibit_multiple_definition_absolute = TRUE;
break;
case OPTION_SHARED:
- if (config.has_shared)
- {
- if (bfd_link_relocatable (&link_info))
- einfo (_("%F%P: -r and %s may not be used together\n"),
- "-shared");
-
- link_info.type = type_dll;
- /* When creating a shared library, the default
- behaviour is to ignore any unresolved references. */
- if (link_info.unresolved_syms_in_objects == RM_NOT_YET_SET)
- link_info.unresolved_syms_in_objects = RM_IGNORE;
- if (link_info.unresolved_syms_in_shared_libs == RM_NOT_YET_SET)
- link_info.unresolved_syms_in_shared_libs = RM_IGNORE;
- }
- else
- einfo (_("%F%P: -shared not supported\n"));
+ if (!config.has_shared)
+ einfo (_("%P: warning: -shared not supported\n"));
+ if (bfd_link_relocatable (&link_info))
+ einfo (_("%F%P: -r and %s may not be used together\n"),
+ "-shared");
+ link_info.type = type_dll;
+ /* When creating a shared library, the default
+ behaviour is to ignore any unresolved references. */
+ if (link_info.unresolved_syms_in_objects == RM_NOT_YET_SET)
+ link_info.unresolved_syms_in_objects = RM_IGNORE;
+ if (link_info.unresolved_syms_in_shared_libs == RM_NOT_YET_SET)
+ link_info.unresolved_syms_in_shared_libs = RM_IGNORE;
break;
case OPTION_PIE:
- if (config.has_shared)
- {
- if (bfd_link_relocatable (&link_info))
- einfo (_("%F%P: -r and %s may not be used together\n"), "-pie");
-
- link_info.type = type_pie;
- }
- else
- einfo (_("%F%P: -pie not supported\n"));
+ if (!config.has_shared)
+ einfo (_("%P: warning: -pie not supported\n"));
+ if (bfd_link_relocatable (&link_info))
+ einfo (_("%F%P: -r and %s may not be used together\n"), "-pie");
+ link_info.type = type_pie;
break;
case 'h': /* Used on Solaris. */
case OPTION_SONAME:
--
Alan Modra
Australia Development Lab, IBM