diff options
author | Ian Lance Taylor <ian@airs.com> | 1996-03-12 23:39:18 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@airs.com> | 1996-03-12 23:39:18 +0000 |
commit | e3d73386d704f9fdd4c3c2bd87531cbc5f4e28d6 (patch) | |
tree | 3315be13f078607db0e3279c8a1b64bd8f3d09bc /ld | |
parent | 8881b321e06d93be5b37a5504359347b0e104bf0 (diff) | |
download | gdb-e3d73386d704f9fdd4c3c2bd87531cbc5f4e28d6.zip gdb-e3d73386d704f9fdd4c3c2bd87531cbc5f4e28d6.tar.gz gdb-e3d73386d704f9fdd4c3c2bd87531cbc5f4e28d6.tar.bz2 |
* lexsup.c (parse_args): Handle --wrap.
* ldmain.c (main): Initialize link_info.wrap_hash.
* ldexp.c (fold_name): Use bfd_wrapped_link_hash_lookup in DEFINED
and NAME cases.
* ld.texinfo, ld.1: Document --wrap.
Diffstat (limited to 'ld')
-rw-r--r-- | ld/ChangeLog | 6 | ||||
-rw-r--r-- | ld/ld.1 | 16 | ||||
-rw-r--r-- | ld/ld.texinfo | 40 | ||||
-rw-r--r-- | ld/ldmain.c | 2 | ||||
-rw-r--r-- | ld/lexsup.c | 18 |
5 files changed, 76 insertions, 6 deletions
diff --git a/ld/ChangeLog b/ld/ChangeLog index 89cbc47..96f6ed0 100644 --- a/ld/ChangeLog +++ b/ld/ChangeLog @@ -8,6 +8,12 @@ Tue Mar 12 12:43:59 1996 David Mosberger-Tang <davidm@koala.azstarnet.com> Tue Mar 12 12:02:21 1996 Ian Lance Taylor <ian@cygnus.com> + * lexsup.c (parse_args): Handle --wrap. + * ldmain.c (main): Initialize link_info.wrap_hash. + * ldexp.c (fold_name): Use bfd_wrapped_link_hash_lookup in DEFINED + and NAME cases. + * ld.texinfo, ld.1: Document --wrap. + * configure: Rebuild with autoconf 2.8. Don't do SunOS style dynamic linking for sparc-aout: @@ -123,6 +123,9 @@ ld \- the GNU linker .RB "[\|" \-warn\-once "\|]" .RB "[\|" \-\-whole\-archive "\|]" .RB "[\|" \-\-no\-whole\-archive "\|]" +.RB "[\|" "\-\-wrap\ "\c +.I symbol\c +\&\|] .RB "[\|" \-X "\|]" .RB "[\|" \-x "\|]" .ad b @@ -934,6 +937,19 @@ Turn off the effect of the option for archives which appear later on the command line. .TP +.BI "--wrap " "symbol" +Use a wrapper function for +.I symbol. +Any undefined reference to +.I symbol +will be resolved to +.BI "__wrap_" "symbol". +Any undefined reference to +.BI "__real_" "symbol" +will be resolved to +.I symbol. + +.TP .B \-X Delete all temporary local symbols. For most targets, this is all local symbols whose names begin with `\|\c diff --git a/ld/ld.texinfo b/ld/ld.texinfo index 23fc78a..11d6d39 100644 --- a/ld/ld.texinfo +++ b/ld/ld.texinfo @@ -184,12 +184,12 @@ ld [ -o @var{output} ] @var{objfile}@dots{} [ -Ttext @var{org} ] [ -Tdata @var{org} ] [ -Tbss @var{org} ] [ -t ] [ -traditional-format ] [ -u @var{symbol}] [-V] [-v] [ -verbose] [ -version ] - [ -warn-common ] [ -warn-constructors] [ -warn-multiple-gp ] [ -warn-once ] - [ -y @var{symbol} ] [ -X ] [-x ] + [ -warn-common ] [ -warn-constructors] [ -warn-multiple-gp ] + [ -warn-once ] [ -y @var{symbol} ] [ -X ] [-x ] [ -( [ archives ] -) ] [ --start-group [ archives ] --end-group ] [ -split-by-reloc @var{count} ] [ -split-by-file ] - [ --whole-archive ] [ --no-whole-archive ] + [ --whole-archive ] [ --no-whole-archive ] [ --wrap @var{symbol} ] @end smallexample This plethora of command-line options may seem intimidating, but in @@ -968,6 +968,40 @@ library. Turn off the effect of the @code{--whole-archive} option for archives which appear later on the command line. +@kindex --wrap +@item --wrap @var{symbol} +Use a wrapper function for @var{symbol}. Any undefined reference to +@var{symbol} will be resolved to @code{__wrap_@var{symbol}}. Any +undefined reference to @code{__real_@var{symbol}} will be resolved to +@var{symbol}. + +This can be used to provide a wrapper for a system function. The +wrapper function should be called @code{__wrap_@var{symbol}}. If it +wishes to call the system function, it should call +@code{__real_@var{symbol}}. + +Here is a trivial example: + +@smallexample +void * +__wrap_malloc (int c) +@{ + printf ("malloc called with %ld\n", c); + return __real_malloc (c); +@} +@end smallexample + +If you link other code with this file using @code{--wrap malloc}, then +all calls to @code{malloc} will call the function @code{__wrap_malloc} +instead. The call to @code{__real_malloc} in @code{__wrap_malloc} will +call the real @code{malloc} function. + +You may wish to provide a @code{__real_malloc} function as well, so that +links without the @code{--wrap} option will succeed. If you do this, +you should not put the definition of @code{__real_malloc} in the same +file as @code{__wrap_malloc}; if you do, the assembler may resolve the +call before the linker has a chance to wrap it to @code{malloc}. + @kindex -X @cindex local symbols, deleting @cindex L, deleting symbols beginning diff --git a/ld/ldmain.c b/ld/ldmain.c index 5dbfc55..6d78e27 100644 --- a/ld/ldmain.c +++ b/ld/ldmain.c @@ -189,7 +189,7 @@ main (argc, argv) link_info.hash = NULL; link_info.keep_hash = NULL; link_info.notice_hash = NULL; - + link_info.wrap_hash = NULL; ldfile_add_arch (""); diff --git a/ld/lexsup.c b/ld/lexsup.c index d90b8c7..47fd2c5 100644 --- a/ld/lexsup.c +++ b/ld/lexsup.c @@ -108,7 +108,7 @@ parse_args (argc, argv) #define OPTION_SPLIT_BY_RELOC (OPTION_WARN_ONCE + 1) #define OPTION_SPLIT_BY_FILE (OPTION_SPLIT_BY_RELOC + 1) #define OPTION_WHOLE_ARCHIVE (OPTION_SPLIT_BY_FILE + 1) - +#define OPTION_WRAP (OPTION_WHOLE_ARCHIVE + 1) static struct option longopts[] = { /* Sorted alphabeticaly, except for the PE options grouped at the end. */ @@ -165,8 +165,8 @@ parse_args (argc, argv) {"split-by-reloc", required_argument, NULL, OPTION_SPLIT_BY_RELOC}, {"split-by-file", no_argument, NULL, OPTION_SPLIT_BY_FILE}, {"whole-archive", no_argument, NULL, OPTION_WHOLE_ARCHIVE}, + {"wrap", required_argument, NULL, OPTION_WRAP}, - {NULL, no_argument, NULL, 0} }; @@ -498,6 +498,20 @@ parse_args (argc, argv) case OPTION_WHOLE_ARCHIVE: whole_archive = true; break; + case OPTION_WRAP: + if (link_info.wrap_hash == NULL) + { + link_info.wrap_hash = ((struct bfd_hash_table *) + xmalloc (sizeof (struct bfd_hash_table))); + if (! bfd_hash_table_init_n (link_info.wrap_hash, + bfd_hash_newfunc, + 61)) + einfo ("%P%F: bfd_hash_table_init failed: %E\n"); + } + if (bfd_hash_lookup (link_info.wrap_hash, optarg, true, true) + == NULL) + einfo ("%P%F: bfd_hash_lookup failed: %E\n"); + break; case 'X': link_info.discard = discard_l; break; |