This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
Re: Should we allow -static libfoo.so?
On Wed, May 09, 2001 at 09:49:08PM -0400, DJ Delorie wrote:
>
> > The problem is the executable won't work right under ELF even if you
> > manage to generate such an executable.
>
> Ah. Still, I think if the user explicitly wants a dso, they should
> get something that works using the dso.
I am not aware there is a way to do so under ELF. BTW, ELF disallows
-r on DSO already.
Here is my proposed patch.
H.J.
--- binutils/bfd/elflink.h.static Wed May 9 17:36:26 2001
+++ binutils/bfd/elflink.h Wed May 9 18:51:44 2001
@@ -1066,10 +1066,12 @@ elf_link_add_object_symbols (abfd, info)
{
dynamic = true;
- /* You can't use -r against a dynamic object. Also, there's no
- hope of using a dynamic object which does not exactly match
- the format of the output file. */
- if (info->relocateable || info->hash->creator != abfd->xvec)
+ /* You can't use -r nor -static against a dynamic object. Also,
+ there's no hope of using a dynamic object which does not
+ exactly match the format of the output file. */
+ if (info->static_link
+ || info->relocateable
+ || info->hash->creator != abfd->xvec)
{
bfd_set_error (bfd_error_invalid_operation);
goto error_return;
--- binutils/ld/emultempl/elf32.em.static Thu May 3 09:28:01 2001
+++ binutils/ld/emultempl/elf32.em Wed May 9 18:42:59 2001
@@ -48,6 +48,7 @@ Foundation, Inc., 59 Temple Place - Suit
#include "ldgram.h"
#include "elf/common.h"
+static void gld${EMULATION_NAME}_after_parse PARAMS ((void));
static void gld${EMULATION_NAME}_before_parse PARAMS ((void));
static void gld${EMULATION_NAME}_vercheck
PARAMS ((lang_input_statement_type *));
@@ -84,6 +85,18 @@ fi
# If a different overriding name is given then output the standard function
# as presumably it is called from the overriding function.
#
+if test x"$LDEMUL_AFTER_PARSE" != xgld"$EMULATION_NAME"_after_parse; then
+cat >>e${EMULATION_NAME}.c <<EOF
+
+static void
+gld${EMULATION_NAME}_after_parse ()
+{
+ link_info.static_link = !config.dynamic_link;
+}
+
+EOF
+fi
+
if test x"$LDEMUL_BEFORE_PARSE" != xgld"$EMULATION_NAME"_before_parse; then
cat >>e${EMULATION_NAME}.c <<EOF
@@ -1531,7 +1544,7 @@ struct ld_emulation_xfer_struct ld_${EMU
${LDEMUL_BEFORE_PARSE-gld${EMULATION_NAME}_before_parse},
${LDEMUL_SYSLIB-syslib_default},
${LDEMUL_HLL-hll_default},
- ${LDEMUL_AFTER_PARSE-after_parse_default},
+ ${LDEMUL_AFTER_PARSE-gld${EMULATION_NAME}_after_parse},
${LDEMUL_AFTER_OPEN-gld${EMULATION_NAME}_after_open},
${LDEMUL_AFTER_ALLOCATION-after_allocation_default},
${LDEMUL_SET_OUTPUT_ARCH-set_output_arch_default},