public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Matt Rice <ratmice@gmail.com>
To: Matt Rice <ratmice@gmail.com>, Binutils <binutils@sourceware.org>
Subject: Re: PATCH/RFC: ld add -p/-P options
Date: Mon, 14 Sep 2009 11:59:00 -0000	[thread overview]
Message-ID: <8ba6bed40909140459j561e3d13g81390a9ced8a08a0@mail.gmail.com> (raw)
In-Reply-To: <20090914003943.GU28290@bubble.grove.modra.org>

[-- Attachment #1: Type: text/plain, Size: 3333 bytes --]

On Sun, Sep 13, 2009 at 5:39 PM, Alan Modra <amodra@bigpond.net.au> wrote:
> On Sat, Sep 12, 2009 at 08:21:35AM -0700, Matt Rice wrote:
>>       (gld${EMULATION_NAME}_add_options): Add -p and -P options.
>
> There's a small problem here.  See armelf.em:PARSE_AND_LIST_SHORTOPTS.
> You'll need to get approval from one of the ARM maintainers to remove
> that from armelf.em.

doesn't look like this is going to be an option, this is still passed
to ld by the linux kernel

http://git.kernel.org/?p=linux/kernel/git/next/linux-next.git;a=blob;f=arch/arm/Makefile;h=54661125a8bfff2b69a1daee5d6de3ae5ebd1395;hb=HEAD

 13 LDFLAGS_vmlinux :=-p --no-undefined -X

http://sourceware.org/ml/binutils/2004-11/msg00401.html
is the thread where this option was turned into a nop.

a possible hack I hesitate to mention is to make -p on gnu-ld accept
an optional argument,
in that case '-pfoo.so' will work with both linkers, the -p in '-p
--other-option' will be a ignored, but '-p foo.so' will
fail to recognize 'foo.so' as an argument to -p though....  there is
probably some caveat i'm missing, but it
does seem to maintain compatibility with the existing -p in armelf,
and give the ability to use a command line which will also work under
solaris.

Personally, I prefer just adding --audit with no short option and
seeing if solaris won't add a long option for compatibilty with us.
then if the armelf guys feel like deprecating their -p and going
through that whole process we could add -p as a short option to
--audit.
that doesn't help in the interim, but i'm going to need configure
checks to see if ld supports the option anyways.

if the hack is wanted i can send a follow up patch.

>> +static void gld${EMULATION_NAME}_append_to_separated_string(char **, char *);
>
> No need for a prototype.

Fixed

>> +gld${EMULATION_NAME}_append_to_separated_string(char **to, char *optarg)
>
> Space before (.  Other than that the patch looks good.

And fixed.

>> I guess the *.rd files might be a bit fragile if it ever decides to be
>> something other than the 4th line.
>
>Write it like this:

>#...
>.*Audit library: \[tmpdir/audit.so\].*
>#pass

Thanks,
I also removed the auditlib.c from the tests since it was unused.


2009-09-12  Matt Rice <ratmice@gmail.com>

       * bfd-in.h (bfd_elf_size_dynamic_sections): Add audit and depaudit
       arguments.
       * elflink.c (bfd_elf_size_dynamic_sections): Generate DT_AUDIT,
       DT_DEPAUDIT from audit/depaudit arguments.
       (elf_finalize_dynstr): finalize DT_AUDIT and DT_DEPAUDIT strtab entries.
       * bfd-in2.h: Regenerate.

2009-09-12  Matt Rice <ratmice@gmail.com>

       * emultempl/elf32.em:
       (gld${EMULATION_NAME}_add_options): Add --audit, --depaudit,
and -P options.
       (gld${EULATION_NAME}_handle_options): Ditto.
       (gld${EULATION_NAME}_list_options): Ditto.
       (gld${EMULATION_NAME}_append_to_separated_string): New function for
       handling rpath-like colon separated strings.
       (gld${EMULATION_NAME}_before_allocation): Pass the audit and depaudit
       libs to bfd.
       ld.texinfo: Document new options.

2009-09-12  Matt Rice <ratmice@gmail.com>

       ld-elf/audit.exp: New.
       ld-elf/audit.rd: New.
       ld-elf/depaudit.rd: New.

[-- Attachment #2: audit2.diff --]
[-- Type: application/octet-stream, Size: 11794 bytes --]

? bfd/ChangeLog.snip
Index: ld/ld.texinfo
===================================================================
RCS file: /cvs/src/src/ld/ld.texinfo,v
retrieving revision 1.247
diff -u -p -r1.247 ld.texinfo
--- ld/ld.texinfo	6 Jul 2009 13:48:51 -0000	1.247
+++ ld/ld.texinfo	14 Sep 2009 11:22:35 -0000
@@ -364,6 +364,14 @@ argument must be one of the strings @sam
 @samp{-Bstatic}, and the other two keywords are functionally equivalent
 to @samp{-Bdynamic}.  This option may be used any number of times.
 
+@kindex --audit @var{AUDITLIB}
+@item --audit @var{AUDITLIB}
+Adds @var{AUDITLIB} to the @code{DT_AUDIT} entry of the dynamic section.
+@var{AUDITLIB} is not checked for existence, nor will it use the DT_SONAME
+specified in the library.  If specified multiple times @code{DT_AUDIT}
+will contain a colon separated list of audit interfaces to use.  This
+option is only meaningful on ELF platforms supporting the rtld-audit interface.  
+
 @ifset I960
 @cindex architectures
 @kindex -A @var{arch}
@@ -451,6 +459,17 @@ even if a relocatable output file is spe
 script command @code{FORCE_COMMON_ALLOCATION} has the same effect.
 @xref{Miscellaneous Commands}.
 
+@kindex --depaudit @var{AUDITLIB}
+@kindex -P @var{AUDITLIB}
+@item --depaudit @var{AUDITLIB}
+@itemx -P @var{AUDITLIB}
+Adds @var{AUDITLIB} to the @code{DT_DEPAUDIT} entry of the dynamic section.
+@var{AUDITLIB} is not checked for existence, nor will it use the DT_SONAME
+specified in the library.  If specified multiple times @code{DT_DEPAUDIT}
+will contain a colon separated list of audit interfaces to use.  This
+option is only meaningful on ELF platforms supporting the rtld-audit interface.
+The -P option is provided for Solaris compatibility.  
+
 @cindex entry point, from command line
 @kindex -e @var{entry}
 @kindex --entry=@var{entry}
Index: ld/emultempl/elf32.em
===================================================================
RCS file: /cvs/src/src/ld/emultempl/elf32.em,v
retrieving revision 1.203
diff -u -p -r1.203 elf32.em
--- ld/emultempl/elf32.em	11 Sep 2009 15:27:35 -0000	1.203
+++ ld/emultempl/elf32.em	14 Sep 2009 11:22:35 -0000
@@ -157,6 +157,10 @@ static lang_input_statement_type *global
 static struct bfd_link_needed_list *global_vercheck_needed;
 static bfd_boolean global_vercheck_failed;
 
+/* These variables are used to implement target options */
+
+static char *audit; /* colon (typically) separated list of libs */
+static char *depaudit; /* colon (typically) separated list of libs */
 
 /* On Linux, it's possible to have different versions of the same
    shared library linked against different versions of libc.  The
@@ -1420,7 +1424,7 @@ gld${EMULATION_NAME}_before_allocation (
     rpath = (const char *) getenv ("LD_RUN_PATH");
   if (! (bfd_elf_size_dynamic_sections
 	 (link_info.output_bfd, command_line.soname, rpath,
-	  command_line.filter_shlib,
+	  command_line.filter_shlib, audit, depaudit,
 	  (const char * const *) command_line.auxiliary_filters,
 	  &link_info, &sinterp, lang_elf_version_info)))
     einfo ("%P%F: failed to set dynamic section sizes: %E\n");
@@ -2007,15 +2011,19 @@ fragment <<EOF
 #define OPTION_EXCLUDE_LIBS		(OPTION_EH_FRAME_HDR + 1)
 #define OPTION_HASH_STYLE		(OPTION_EXCLUDE_LIBS + 1)
 #define OPTION_BUILD_ID			(OPTION_HASH_STYLE + 1)
+#define OPTION_AUDIT			(OPTION_BUILD_ID + 1)
+#define OPTION_DEPAUDIT			(OPTION_AUDIT + 1)
 
 static void
 gld${EMULATION_NAME}_add_options
   (int ns, char **shortopts, int nl, struct option **longopts,
    int nrl ATTRIBUTE_UNUSED, struct option **really_longopts ATTRIBUTE_UNUSED)
 {
-  static const char xtra_short[] = "${PARSE_AND_LIST_SHORTOPTS}z:";
+  static const char xtra_short[] = "${PARSE_AND_LIST_SHORTOPTS}z:P:";
   static const struct option xtra_long[] = {
     {"build-id", optional_argument, NULL, OPTION_BUILD_ID},
+    {"audit", required_argument, NULL, OPTION_AUDIT},
+    {"depaudit", required_argument, NULL, OPTION_DEPAUDIT},
 EOF
 
 if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then
@@ -2048,6 +2056,45 @@ fragment <<EOF
 
 #define DEFAULT_BUILD_ID_STYLE	"sha1"
 
+static void 
+gld${EMULATION_NAME}_append_to_separated_string (char **to, char *optarg)
+{
+  if (*to == NULL)
+    *to = xstrdup (optarg);
+  else
+    {
+      size_t to_len = strlen (*to);
+      size_t optarg_len = strlen (optarg);
+      char *buf;
+      char *cp = *to;
+
+      /* First see whether OPTARG is already in the path.  */
+      do
+	{
+	  if (strncmp (optarg, cp, optarg_len) == 0
+	      && (cp[optarg_len] == 0
+		  || cp[optarg_len] == config.rpath_separator))
+	    /* We found it.  */
+	    break;
+
+	  /* Not yet found.  */
+	  cp = strchr (cp, config.rpath_separator);
+	  if (cp != NULL)
+	    ++cp;
+	}
+      while (cp != NULL);
+
+      if (cp == NULL)
+	{
+	  buf = xmalloc (to_len + optarg_len + 2);
+	  sprintf (buf, "%s%c%s", *to,
+		   config.rpath_separator, optarg);
+	  free (*to);
+	  *to = buf;
+	}
+    }
+}
+
 static bfd_boolean
 gld${EMULATION_NAME}_handle_option (int optc)
 {
@@ -2067,6 +2114,13 @@ gld${EMULATION_NAME}_handle_option (int 
       if (strcmp (optarg, "none"))
 	link_info.emit_note_gnu_build_id = xstrdup (optarg);
       break;
+    case OPTION_AUDIT:
+  	gld${EMULATION_NAME}_append_to_separated_string(&audit, optarg); 
+	break;
+    case OPTION_DEPAUDIT:
+    case 'P':
+	gld${EMULATION_NAME}_append_to_separated_string(&depaudit, optarg);
+	break;
 
 EOF
 
@@ -2218,6 +2272,11 @@ gld${EMULATION_NAME}_list_options (FILE 
 {
   fprintf (file, _("\
   --build-id[=STYLE]          Generate build ID note\n"));
+  fprintf (file, _("\
+  --audit=AUDITLIB            Specify a library to use for auditing\n"));
+  fprintf (file, _("\
+  -P AUDITLIB, --depaudit=AUDITLIB\n" "\
+                              Specify a library to use for auditing dependencies\n"));
 EOF
 
 if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then
Index: ld/testsuite/ld-elf/audit.exp
===================================================================
RCS file: ld/testsuite/ld-elf/audit.exp
diff -N ld/testsuite/ld-elf/audit.exp
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ ld/testsuite/ld-elf/audit.exp	14 Sep 2009 11:22:35 -0000
@@ -0,0 +1,51 @@
+# Expect script for various ELF tests.
+#   Copyright 2009 Free Software Foundation, Inc.
+#
+# This file is part of the GNU Binutils.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
+# MA 02110-1301, USA.
+#
+
+# Exclude non-ELF targets.
+
+if ![is_elf_format] {
+    return
+}
+
+# The following tests require running the executable generated by ld.
+if ![isnative] {
+    return
+}
+
+# Check if compiler works
+if { [which $CC] == 0 } {
+    return
+}
+
+set build_tests {
+  {"Run with -paudit.so"
+     "-Wl,--audit=tmpdir/audit.so" ""
+     {main.c} {{"readelf" {-d} "audit.rd"}} "audit.out"}
+  {"Run with -Paudit.so"
+     "-Wl,-Ptmpdir/audit.so" ""
+     {main.c} {{"readelf" {-d} "depaudit.rd"}} "depaudit.out"}
+  {"Run with --depaudit=audit.so"
+     "-Wl,--depaudit=tmpdir/audit.so" ""
+     {main.c} {{"readelf" {-d} "depaudit.rd"}} "depaudit2.out"}
+}
+
+run_cc_link_tests $build_tests
+
Index: ld/testsuite/ld-elf/audit.rd
===================================================================
RCS file: ld/testsuite/ld-elf/audit.rd
diff -N ld/testsuite/ld-elf/audit.rd
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ ld/testsuite/ld-elf/audit.rd	14 Sep 2009 11:22:35 -0000
@@ -0,0 +1,3 @@
+#...
+.*Audit library: \[tmpdir/audit.so\].*
+#pass
Index: ld/testsuite/ld-elf/depaudit.rd
===================================================================
RCS file: ld/testsuite/ld-elf/depaudit.rd
diff -N ld/testsuite/ld-elf/depaudit.rd
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ ld/testsuite/ld-elf/depaudit.rd	14 Sep 2009 11:22:35 -0000
@@ -0,0 +1,3 @@
+#...
+.*Dependency audit library: \[tmpdir/audit.so\].*
+#pass
Index: bfd/bfd-in.h
===================================================================
RCS file: /cvs/src/src/bfd/bfd-in.h,v
retrieving revision 1.146
diff -u -p -r1.146 bfd-in.h
--- bfd/bfd-in.h	2 Sep 2009 07:18:35 -0000	1.146
+++ bfd/bfd-in.h	14 Sep 2009 11:22:35 -0000
@@ -635,8 +635,8 @@ extern struct bfd_link_needed_list *bfd_
 extern bfd_boolean bfd_elf_get_bfd_needed_list
   (bfd *, struct bfd_link_needed_list **);
 extern bfd_boolean bfd_elf_size_dynamic_sections
-  (bfd *, const char *, const char *, const char *, const char * const *,
-   struct bfd_link_info *, struct bfd_section **,
+  (bfd *, const char *, const char *, const char *, const char *, const char *,
+   const char * const *, struct bfd_link_info *, struct bfd_section **,
    struct bfd_elf_version_tree *);
 extern bfd_boolean bfd_elf_size_dynsym_hash_dynstr
   (bfd *, struct bfd_link_info *);
Index: bfd/bfd-in2.h
===================================================================
RCS file: /cvs/src/src/bfd/bfd-in2.h,v
retrieving revision 1.493
diff -u -p -r1.493 bfd-in2.h
--- bfd/bfd-in2.h	9 Sep 2009 21:38:57 -0000	1.493
+++ bfd/bfd-in2.h	14 Sep 2009 11:22:35 -0000
@@ -642,8 +642,8 @@ extern struct bfd_link_needed_list *bfd_
 extern bfd_boolean bfd_elf_get_bfd_needed_list
   (bfd *, struct bfd_link_needed_list **);
 extern bfd_boolean bfd_elf_size_dynamic_sections
-  (bfd *, const char *, const char *, const char *, const char * const *,
-   struct bfd_link_info *, struct bfd_section **,
+  (bfd *, const char *, const char *, const char *, const char *, const char *, 
+   const char * const *, struct bfd_link_info *, struct bfd_section **,
    struct bfd_elf_version_tree *);
 extern bfd_boolean bfd_elf_size_dynsym_hash_dynstr
   (bfd *, struct bfd_link_info *);
Index: bfd/elflink.c
===================================================================
RCS file: /cvs/src/src/bfd/elflink.c,v
retrieving revision 1.353
diff -u -p -r1.353 elflink.c
--- bfd/elflink.c	9 Sep 2009 21:38:57 -0000	1.353
+++ bfd/elflink.c	14 Sep 2009 11:22:36 -0000
@@ -3234,6 +3234,8 @@ elf_finalize_dynstr (bfd *output_bfd, st
 	case DT_RUNPATH:
 	case DT_FILTER:
 	case DT_AUXILIARY:
+	case DT_AUDIT:
+	case DT_DEPAUDIT:
 	  dyn.d_un.d_val = _bfd_elf_strtab_offset (dynstr, dyn.d_un.d_val);
 	  break;
 	default:
@@ -5451,6 +5453,8 @@ bfd_elf_size_dynamic_sections (bfd *outp
 			       const char *soname,
 			       const char *rpath,
 			       const char *filter_shlib,
+			       const char *audit,
+			       const char *depaudit,
 			       const char * const *auxiliary_filters,
 			       struct bfd_link_info *info,
 			       asection **sinterpptr,
@@ -5603,6 +5607,28 @@ bfd_elf_size_dynamic_sections (bfd *outp
 	    }
 	}
 
+      if (audit != NULL)
+	{
+	  bfd_size_type indx;
+
+	  indx = _bfd_elf_strtab_add (elf_hash_table (info)->dynstr, audit,
+				      TRUE);
+	  if (indx == (bfd_size_type) -1
+	      || !_bfd_elf_add_dynamic_entry (info, DT_AUDIT, indx))
+	    return FALSE;
+	}
+
+      if (depaudit != NULL)
+	{
+	  bfd_size_type indx;
+
+	  indx = _bfd_elf_strtab_add (elf_hash_table (info)->dynstr, depaudit,
+				      TRUE);
+	  if (indx == (bfd_size_type) -1
+	      || !_bfd_elf_add_dynamic_entry (info, DT_DEPAUDIT, indx))
+	    return FALSE;
+	}
+
       eif.info = info;
       eif.verdefs = verdefs;
       eif.failed = FALSE;

  reply	other threads:[~2009-09-14 11:59 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-08-28 21:41 Matt Rice
2009-08-30  2:30 ` Matt Rice
2009-08-31 17:43   ` Ian Lance Taylor
2009-09-12 15:21     ` Matt Rice
2009-09-12 16:56       ` Matt Rice
2009-09-14  0:42         ` Alan Modra
2009-09-14  0:39       ` Alan Modra
2009-09-14 11:59         ` Matt Rice [this message]
2009-09-22 20:50           ` Matt Rice
2009-09-23 13:56             ` Alan Modra

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8ba6bed40909140459j561e3d13g81390a9ced8a08a0@mail.gmail.com \
    --to=ratmice@gmail.com \
    --cc=binutils@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).