public inbox for libc-hacker@sourceware.org
 help / color / mirror / Atom feed
* RFC: New macros for bypassing PLT calls
@ 2002-07-31  7:45 Jakub Jelinek
  2002-07-31 13:03 ` Roland McGrath
  0 siblings, 1 reply; 5+ messages in thread
From: Jakub Jelinek @ 2002-07-31  7:45 UTC (permalink / raw)
  To: Ulrich Drepper; +Cc: Glibc hackers

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

Hi!

ATM glibc uses a couple of different methods for the hidden
function aliases.
Below is what I came up today, I wonder whether you agree with it
before changing it everywhere.
The usage is:
in include/ (ie. glibc private header) add something like:
libc_hidden (int, close, (int __fd));
if you want to all close (fd) calls to bypass PLT inside of libc.so.
Then the only other change is at the actual close function definition.

If the function is originally defined with some other name, say __close
and close used to be just weak or strong alias, then one needs to do:

int __close (int __fd)
{
... function definition
}
strong_alias (__close, close)	// This is what the code already contained
libc_hidden_def (close)		// If the close is supposed to
				// be strong, otherwise libc_hidden_weak (close)

If there were no aliases (or just INTDEF etc.), then only:

int close (int __fd)
{
... function definition
}
libc_hidden_def (close)

One alternative would be to get rid of the prototypes in include/ headers,
ie. just say:
libc_hidden (close);
in include/foo.h.
libc_hidden definition would then have to change slightly:
# define libc_hidden(name) __libc_hidden(name, __GI_##name)
# define __libc_hidden(name, internal) \
  __typeof(name) internal; \
  __typeof(name) __REDIRECT (name, , internal) attribute_hidden

Are there any common cases which should be solved I've missed?

	Jakub

[-- Attachment #2: libc-hidden.h --]
[-- Type: text/plain, Size: 2334 bytes --]

#include "libc-symbols.h"

#if !defined NOT_IN_libc && defined SHARED \
    && defined DO_VERSIONING && defined __REDIRECT
# define libc_hidden(type, name, proto) __libc_hidden(type, name, proto, __GI_##name)
# define __libc_hidden(type, name, proto, internal) \
  type internal proto; \
  type __REDIRECT (name, proto, internal) attribute_hidden
# ifdef HAVE_ASM_SET_DIRECTIVE
#  define __libc_hidden_def_1(original, alias)			\
  ASM_GLOBAL_DIRECTIVE C_SYMBOL_NAME (alias) ASM_LINE_SEP	\
  .set C_SYMBOL_NAME (alias), C_SYMBOL_NAME (original)
# else
#  ifdef HAVE_ASM_GLOBAL_DOT_NAME
#   define __libc_hidden_def_1(original, alias)			\
  ASM_GLOBAL_DIRECTIVE C_SYMBOL_NAME (alias) ASM_LINE_SEP	\
  C_SYMBOL_NAME (alias) = C_SYMBOL_NAME (original) ASM_LINE_SEP	\
  ASM_GLOBAL_DIRECTIVE C_SYMBOL_DOT_NAME (alias) ASM_LINE_SEP	\
  C_SYMBOL_DOT_NAME (alias) = C_SYMBOL_DOT_NAME (original)
#  else
#   define __libc_hidden_def_1(original, alias)			\
  ASM_GLOBAL_DIRECTIVE C_SYMBOL_NAME (alias) ASM_LINE_SEP	\
  C_SYMBOL_NAME (alias) = C_SYMBOL_NAME (original)
#  endif
# endif
# define __libc_hidden_def_2(...) #__VA_ARGS__
# define __libc_hidden_def_3(...) __libc_hidden_def_2(__VA_ARGS__)
# define libc_hidden_def(name)				\
  __asm__ (__libc_hidden_def_3 (__libc_hidden_def_1 (__GI_##name, name)));
# ifdef HAVE_WEAK_SYMBOLS
#  ifdef HAVE_ASM_WEAKEXT_DIRECTIVE
#   define __libc_hidden_weak_1(original, alias)		\
  .weakext C_SYMBOL_NAME (alias), C_SYMBOL_NAME (original)
#  else /* ! HAVE_ASM_WEAKEXT_DIRECTIVE */
#   ifdef HAVE_ASM_GLOBAL_DOT_NAME
#    define __libc_hidden_weak_1(original, alias)		\
  .weak C_SYMBOL_NAME (alias) ASM_LINE_SEP			\
  C_SYMBOL_NAME (alias) = C_SYMBOL_NAME (original) ASM_LINE_SEP	\
  ASM_GLOBAL_DIRECTIVE C_SYMBOL_DOT_NAME (alias) ASM_LINE_SEP	\
  C_SYMBOL_DOT_NAME (alias) = C_SYMBOL_DOT_NAME (original)
#   else
#    define __libc_hidden_weak_1(original, alias)		\
  .weak C_SYMBOL_NAME (alias) ASM_LINE_SEP			\
  C_SYMBOL_NAME (alias) = C_SYMBOL_NAME (original)
#   endif
#  endif
#  define libc_hidden_weak(name)				\
  __asm__ (__libc_hidden_def_3 (__libc_hidden_weak_1 (__GI_##name, name)));
# else
#  define libc_hidden_weak(name) libc_hidden_def(name)
# endif
#else
# define libc_hidden(type, name, proto) type name proto
# define libc_hidden_def(name)
# define libc_hidden_weak(name)
#endif

[-- Attachment #3: libc-symbols.h --]
[-- Type: text/plain, Size: 3643 bytes --]

#define SHARED
#define DO_VERSIONING
#define NO_UNDERSCORES 1
#define HAVE_ASM_WEAK_DIRECTIVE 1
#define HAVE_ASM_SET_DIRECTIVE 1
#define ASM_GLOBAL_DIRECTIVE .globl
#ifndef ASM_LINE_SEP
# define ASM_LINE_SEP ;
#endif
#ifndef C_SYMBOL_NAME
# ifdef NO_UNDERSCORES
#  define C_SYMBOL_NAME(name) name
# else
#  define C_SYMBOL_NAME(name) _##name
# endif
#endif
   
#define attribute_hidden __attribute__ ((visibility ("hidden")))
#include <features.h>

#ifndef __ASSEMBLER__
/* GCC understands weak symbols and aliases; use its interface where
   possible, instead of embedded assembly language.  */

/* Define ALIASNAME as a strong alias for NAME.  */
# define strong_alias(name, aliasname) _strong_alias(name, aliasname)
# define _strong_alias(name, aliasname) \
  extern __typeof (name) aliasname __attribute__ ((alias (#name)));

/* This comes between the return type and function name in
   a function definition to make that definition weak.  */
# define weak_function __attribute__ ((weak))
# define weak_const_function __attribute__ ((weak, __const__))

# ifdef HAVE_WEAK_SYMBOLS

/* Define ALIASNAME as a weak alias for NAME.
   If weak aliases are not available, this defines a strong alias.  */
#  define weak_alias(name, aliasname) _weak_alias (name, aliasname)
#  define _weak_alias(name, aliasname) \
  extern __typeof (name) aliasname __attribute__ ((weak, alias (#name)));

/* Declare SYMBOL as weak undefined symbol (resolved to 0 if not defined).  */
#  define weak_extern(symbol) _weak_extern (symbol)
#  ifdef HAVE_ASM_WEAKEXT_DIRECTIVE
#   define _weak_extern(symbol) asm (".weakext " __SYMBOL_PREFIX #symbol);
#  else
#   define _weak_extern(symbol)    asm (".weak " __SYMBOL_PREFIX #symbol);
#  endif

# else

#  define weak_alias(name, aliasname) strong_alias(name, aliasname)
#  define weak_extern(symbol) /* Nothing. */

# endif

#else /* __ASSEMBLER__ */

# ifdef HAVE_ASM_SET_DIRECTIVE
#  define strong_alias(original, alias)		\
  ASM_GLOBAL_DIRECTIVE C_SYMBOL_NAME (alias) ASM_LINE_SEP	\
  .set C_SYMBOL_NAME (alias),C_SYMBOL_NAME (original)
# else
#  ifdef HAVE_ASM_GLOBAL_DOT_NAME
#   define strong_alias(original, alias)	\
  ASM_GLOBAL_DIRECTIVE C_SYMBOL_NAME (alias) ASM_LINE_SEP	\
  C_SYMBOL_NAME (alias) = C_SYMBOL_NAME (original) ASM_LINE_SEP	\
  ASM_GLOBAL_DIRECTIVE C_SYMBOL_DOT_NAME (alias) ASM_LINE_SEP	\
  C_SYMBOL_DOT_NAME (alias) = C_SYMBOL_DOT_NAME (original)
#  else
#   define strong_alias(original, alias)	\
  ASM_GLOBAL_DIRECTIVE C_SYMBOL_NAME (alias) ASM_LINE_SEP	\
  C_SYMBOL_NAME (alias) = C_SYMBOL_NAME (original)
#  endif
# endif

# ifdef HAVE_WEAK_SYMBOLS
#  ifdef HAVE_ASM_WEAKEXT_DIRECTIVE
#   define weak_alias(original, alias)	\
  .weakext C_SYMBOL_NAME (alias), C_SYMBOL_NAME (original)
#   define weak_extern(symbol)	\
  .weakext C_SYMBOL_NAME (symbol)

#  else /* ! HAVE_ASM_WEAKEXT_DIRECTIVE */

#   ifdef HAVE_ASM_GLOBAL_DOT_NAME
#    define weak_alias(original, alias)	\
  .weak C_SYMBOL_NAME (alias) ASM_LINE_SEP			\
  C_SYMBOL_NAME (alias) = C_SYMBOL_NAME (original) ASM_LINE_SEP	\
  ASM_GLOBAL_DIRECTIVE C_SYMBOL_DOT_NAME (alias) ASM_LINE_SEP	\
  C_SYMBOL_DOT_NAME (alias) = C_SYMBOL_DOT_NAME (original)
#   else
#    define weak_alias(original, alias)	\
  .weak C_SYMBOL_NAME (alias) ASM_LINE_SEP	\
  C_SYMBOL_NAME (alias) = C_SYMBOL_NAME (original)
#   endif

#   define weak_extern(symbol)	\
  .weak C_SYMBOL_NAME (symbol)

#  endif /* ! HAVE_ASM_WEAKEXT_DIRECTIVE */

# else /* ! HAVE_WEAK_SYMBOLS */

#  define weak_alias(original, alias) strong_alias(original, alias)
#  define weak_extern(symbol) /* Nothing */
# endif /* ! HAVE_WEAK_SYMBOLS */

#endif /* __ASSEMBLER__ */

[-- Attachment #4: x.h --]
[-- Type: text/plain, Size: 95 bytes --]

#include "libc-hidden.h"
libc_hidden (int, h1, (int __fd));
libc_hidden (int, h2, (int __fd));

[-- Attachment #5: x.c --]
[-- Type: text/plain, Size: 133 bytes --]

#include "x.h"
void foo (void)
{
  h1 (26);
}

int __h2 (int __fd)
{
  return __fd;
}
strong_alias (__h2, h2)
libc_hidden_weak (h2)


[-- Attachment #6: y.c --]
[-- Type: text/plain, Size: 137 bytes --]

#include "x.h"

void bar (void)
{
  h1 (26);
}

int h1 (int __fd)
{
  return __fd;
}
libc_hidden_def(h1)

void baz (void)
{
  h1 (26);
}

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: RFC: New macros for bypassing PLT calls
  2002-07-31  7:45 RFC: New macros for bypassing PLT calls Jakub Jelinek
@ 2002-07-31 13:03 ` Roland McGrath
  2002-07-31 13:29   ` Ulrich Drepper
  0 siblings, 1 reply; 5+ messages in thread
From: Roland McGrath @ 2002-07-31 13:03 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Glibc hackers

I definitely like the typeof version.  It would be nice to get rid of all
those repeated prototypes, which are just typos waiting to happen.
I haven't done real heavy cogitation to find anything wrong with this plan,
or to think up anything it fails to cover.  But it looks good to me.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: RFC: New macros for bypassing PLT calls
  2002-07-31 13:03 ` Roland McGrath
@ 2002-07-31 13:29   ` Ulrich Drepper
  2002-08-01 15:27     ` [PATCH] " Jakub Jelinek
  0 siblings, 1 reply; 5+ messages in thread
From: Ulrich Drepper @ 2002-07-31 13:29 UTC (permalink / raw)
  To: Roland McGrath; +Cc: Jakub Jelinek, Glibc hackers

Roland McGrath wrote:
> I definitely like the typeof version.  It would be nice to get rid of all
> those repeated prototypes, which are just typos waiting to happen.
> I haven't done real heavy cogitation to find anything wrong with this plan,
> or to think up anything it fails to cover.  But it looks good to me.

Yes, let's just give it a try.

-- 
---------------.                          ,-.   1325 Chesapeake Terrace
Ulrich Drepper  \    ,-------------------'   \  Sunnyvale, CA 94089 USA
Red Hat          `--' drepper at redhat.com   `------------------------

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH] New macros for bypassing PLT calls
  2002-07-31 13:29   ` Ulrich Drepper
@ 2002-08-01 15:27     ` Jakub Jelinek
  2002-08-02  0:26       ` Ulrich Drepper
  0 siblings, 1 reply; 5+ messages in thread
From: Jakub Jelinek @ 2002-08-01 15:27 UTC (permalink / raw)
  To: Ulrich Drepper; +Cc: Roland McGrath, Glibc hackers

On Wed, Jul 31, 2002 at 01:26:15PM -0700, Ulrich Drepper wrote:
> Roland McGrath wrote:
> > I definitely like the typeof version.  It would be nice to get rid of all
> > those repeated prototypes, which are just typos waiting to happen.
> > I haven't done real heavy cogitation to find anything wrong with this plan,
> > or to think up anything it fails to cover.  But it looks good to me.
> 
> Yes, let's just give it a try.

Here it is (I just did a few, some new ones, some converted, etc., tried to
cover the various usages).
I've verified that {libc|libm|ld}.so dynsym contains the
same symbols and symbol types before and after the patch and of course the
number of plt slots in libc.so went down.
There is one problem though - due to a bug in gcc attribute visibility
handling it works only with CVS gcc as of half an hour ago
or the 3.2 backport of it if HAVE_VISIBILITY_ATTRIBUTE (otherwise
it should work too). I'll add HAVE_BROKEN_VISIBILITY_ATTRIBUTE check
tomorrow (attribute_hidden can be defined just if HAVE_VISIBILITY_ATTRIBUTE
is defined, but hidden_proto can use it only
if HAVE_BROKEN_VISIBILITY_ATTRIBUTE will not be defined).

Shall I continue tomorrow (well, today europe time) with other symbols?

2002-08-02  Jakub Jelinek  <jakub@redhat.com>

	* assert/assert.c (__assert_fail): Remove undef.
	Replace INTDEF with libc_hidden_def.
	* assert/__assert.c (__assert): Remove INTUSE.
	* elf/dl-minimal.c (__assert_fail): Replace INTDEF with
	libc_hidden_weak.
	* include/libc-symbols.h (hidden_proto, hidden_def, hidden_weak,
	libc_hidden_proto, libc_hidden_def, libc_hidden_weak,
	rtld_hidden_proto, rtld_hidden_def, rtld_hidden_weak,
	libm_hidden_proto, libm_hidden_def, libm_hidden_weak): Define.
	* include/assert.h (__assert_fail_internal): Remove.
	(__assert_fail): Add prototype.  Add hidden_proto.
	* include/libc-internal.h (__libc_freeres): Add libc_hidden_proto.
	* include/wchar.h (__mbrtowc_internal, __mbrlen_internal): Remove.
	(__mbrtowc, __mbrlen): Use libc_hidden_proto.  Remove macros.
	* include/string.h (__mempcpy): Add libc_hidden_proto.
	* include/fcntl.h (__open64, __libc_open, __libc_fcntl, __fcntl):
	Add libc_hidden_proto.  Remove macros.
	(__open_internal, __fcntl_internal): Remove.
	* libio/iofdopen.c (_IO_fcntl): Remove INTUSE from __fcntl.
	* malloc/set-freeres.c (__libc_freeres): Add libc_hidden_def.
	* nss/nsswitch.h (__nss_database_lookup, __nss_next): Add
	libc_hiden_proto.
	* nss/nsswitch.c (__nss_database_lookup, __nss_next): Add
	libc_hidden_def.
	* sysdeps/generic/mempcpy.c (__mempcpy): Remove undef.
	Add libc_hidden_def.
	* sysdeps/generic/open64.c (__open64): Add libc_hidden_def.
	* sysdeps/generic/open.c (__open): Remove undef.
	Add libc_hidden_def.  Remove INTDEF.
	* sysdeps/generic/fcntl.c (__fcntl): Remove undef.
	Add libc_hidden_def.
	* sysdeps/i386/i586/mempcpy.S (__mempcpy): Add libc_hidden_def.
	* sysdeps/i386/i686/mempcpy.S (__mempcpy): Likewise.
	* sysdeps/mach/hurd/fcntl.c (__libc_fcntl, __fcntl): Remove undef.
	(__fcntl): Remove INTDEF2.  Add libc_hidden_weak.
	(__libc_fcntl): Add libc_hidden_def.
	* sysdeps/mach/hurd/open.c (__libc_open, __open): Remove undef.
	(__open): Remove INTDEF2.  Add libc_hidden_weak.
	(__libc_open): Add libc_hidden_def.
	* sysdeps/posix/open64.c (__open64): Add libc_hidden_weak.
	* sysdeps/standalone/open.c (__open): Add libc_hidden_def.
	* sysdeps/unix/sysv/aix/fcntl.c (__libc_fcntl, __fcntl): Remove undef.
	Add libc_hidden_def.
	* sysdeps/unix/sysv/aix/open.c (__libc_open, __open): Remove undef.
	Add libc_hidden_def.
	* sysdeps/unix/sysv/linux/i386/fcntl.c (__libc_fcntl, __fcntl): Remove
	undef.
	(__fcntl): Remove INTDEF2.  Add libc_hidden_weak.
	(__libc_fcntl): Add libc_hidden_def.
	* sysdeps/unix/sysv/linux/syscalls.list (__fcntl_internal): Remove.
	(__GI___fcntl, __GI___libc_fcntl): Add.
	* sysdeps/unix/syscalls.list (__GI___fcntl, __GI___libc_fcntl,
	__GI___open, __GI___libc_open): Add.
	* wcsmbs/mbrlen.c (__mbrlen): Remove undef.
	Replace INTDEF with libc_hidden_def.
	* wcsmbs/mbrtowc.c (__mbrtowc): Likewise.

--- libc/assert/assert.c.jj	2002-07-29 15:14:49.000000000 +0200
+++ libc/assert/assert.c	2002-08-01 15:26:40.000000000 +0200
@@ -42,7 +42,6 @@ extern const char *__progname;
 # include FATAL_PREPARE_INCLUDE
 #endif
 
-#undef __assert_fail
 void
 __assert_fail (const char *assertion, const char *file, unsigned int line,
 	       const char *function)
@@ -82,4 +81,4 @@ __assert_fail (const char *assertion, co
 
   abort ();
 }
-INTDEF(__assert_fail)
+libc_hidden_def(__assert_fail)
--- libc/assert/__assert.c.jj	2002-04-30 12:51:29.000000000 +0200
+++ libc/assert/__assert.c	2002-08-01 15:28:26.000000000 +0200
@@ -23,5 +23,5 @@
 void
 __assert (const char *assertion, const char *file, int line)
 {
-  INTUSE(__assert_fail) (assertion, file, line, (const char *) 0);
+  __assert_fail (assertion, file, line, (const char *) 0);
 }
--- libc/elf/dl-minimal.c.jj	2002-07-29 15:14:50.000000000 +0200
+++ libc/elf/dl-minimal.c	2002-08-01 15:41:39.000000000 +0200
@@ -209,7 +209,7 @@ Inconsistency detected by ld.so: %s: %u:
 		    assertion);
 
 }
-INTDEF(__assert_fail)
+rtld_hidden_weak(__assert_fail)
 
 #endif
 
--- libc/include/libc-symbols.h.jj	2002-04-30 12:52:49.000000000 +0200
+++ libc/include/libc-symbols.h	2002-08-01 19:08:07.000000000 +0200
@@ -381,4 +381,154 @@
 # define INTVARDEF2(name, newname)
 #endif
 
+/* The following macros are used for PLT bypassing within libc.so
+   (and if needed other libraries similarly).
+   First of all, you need to have the function prototyped somewhere,
+   say in foo/foo.h:
+
+   int foo (int __bar);
+
+   If calls to foo within libc.so should always go to foo defined in libc.so,
+   then in include/foo.h you add:
+
+   libc_hidden_proto (foo)
+
+   line and after the foo function definition:
+   
+   int foo (int __bar)
+   {
+     return __bar;
+   }
+   libc_hidden_def (foo)
+
+   or
+
+   int foo (int __bar)
+   {
+     return __bar;
+   }
+   libc_hidden_weak (foo)
+
+   If foo is normally just an alias (strong or weak) of some other function,
+   you should use the normal strong_alias first, then add libc_hidden_def
+   or libc_hidden_weak:
+
+   int baz (int __bar)
+   {
+     return __bar;
+   }
+   strong_alias (baz, foo)
+   libc_hidden_weak (foo)
+
+   If the function should be internal to multiple objects, say ld.so and
+   libc.so, the best way is to use:
+ 
+   #if !defined NOT_IN_libc || defined IS_IN_rtld
+   hidden_proto (foo)
+   #endif
+
+   in include/foo.h and the normal macros at all function definitions
+   depending on what DSO they belong to.  */
+
+#if defined SHARED && defined DO_VERSIONING
+# ifndef __ASSEMBLER__
+#  define hidden_proto(name) __hidden_proto (name, __GI_##name)
+#  define __hidden_proto(name, internal) \
+  __typeof (name) internal; \
+  __typeof (name) name __asm__ (__hidden_asmname (#internal)) \
+  attribute_hidden;
+#  define __hidden_asmname(name) \
+  __hidden_asmname1 (__USER_LABEL_PREFIX__, name)
+#  define __hidden_asmname1(prefix, name) __hidden_asmname2(prefix, name)
+#  define __hidden_asmname2(prefix, name) #prefix name
+#  ifdef HAVE_ASM_SET_DIRECTIVE
+#   define __hidden_def1(original, alias)			\
+  ASM_GLOBAL_DIRECTIVE C_SYMBOL_NAME (alias) ASM_LINE_SEP	\
+  .set C_SYMBOL_NAME (alias), C_SYMBOL_NAME (original)
+#  else
+#   ifdef HAVE_ASM_GLOBAL_DOT_NAME
+#    define __hidden_def1(original, alias)			\
+  ASM_GLOBAL_DIRECTIVE C_SYMBOL_NAME (alias) ASM_LINE_SEP	\
+  C_SYMBOL_NAME (alias) = C_SYMBOL_NAME (original) ASM_LINE_SEP	\
+  ASM_GLOBAL_DIRECTIVE C_SYMBOL_DOT_NAME (alias) ASM_LINE_SEP	\
+  C_SYMBOL_DOT_NAME (alias) = C_SYMBOL_DOT_NAME (original)
+#   else
+#    define __hidden_def1(original, alias)			\
+  ASM_GLOBAL_DIRECTIVE C_SYMBOL_NAME (alias) ASM_LINE_SEP	\
+  C_SYMBOL_NAME (alias) = C_SYMBOL_NAME (original)
+#   endif
+#  endif
+#  define __hidden_def2(...) #__VA_ARGS__
+#  define __hidden_def3(...) __hidden_def2 (__VA_ARGS__)
+#  define hidden_def(name)					\
+  __asm__ (__hidden_def3 (__hidden_def1 (__GI_##name, name)));
+#  ifdef HAVE_WEAK_SYMBOLS
+#   ifdef HAVE_ASM_WEAKEXT_DIRECTIVE
+#    define __hidden_weak1(original, alias)			\
+  .weakext C_SYMBOL_NAME (alias), C_SYMBOL_NAME (original)
+#   else /* ! HAVE_ASM_WEAKEXT_DIRECTIVE */
+#    ifdef HAVE_ASM_GLOBAL_DOT_NAME
+#     define __hidden_weak1(original, alias)			\
+  .weak C_SYMBOL_NAME (alias) ASM_LINE_SEP			\
+  C_SYMBOL_NAME (alias) = C_SYMBOL_NAME (original) ASM_LINE_SEP	\
+  ASM_GLOBAL_DIRECTIVE C_SYMBOL_DOT_NAME (alias) ASM_LINE_SEP	\
+  C_SYMBOL_DOT_NAME (alias) = C_SYMBOL_DOT_NAME (original)
+#    else
+#     define __hidden_weak1(original, alias)			\
+  .weak C_SYMBOL_NAME (alias) ASM_LINE_SEP			\
+  C_SYMBOL_NAME (alias) = C_SYMBOL_NAME (original)
+#    endif
+#   endif
+#   define hidden_weak(name)					\
+  __asm__ (__hidden_def3 (__hidden_weak1 (__GI_##name, name)));
+#  else
+#   define hidden_weak(name) hidden_def (name)
+#  endif
+# else
+/* For assembly, we need to do the opposite of what we do in C:
+   in assembly gcc __REDIRECT stuff is not in place, so functions
+   are defined by its normal name and we need to create the
+   __GI_* alias to it, in C __REDIRECT causes the function definition
+   to use __GI_* name and we need to add alias to the real name.
+   hidden_proto and hidden_weak don't make sense for assembly.  */
+#  define hidden_def(name) strong_alias (name, __GI_##name)
+# endif
+#else
+# ifndef __ASSEMBLY__
+#  define hidden_proto(name)
+#  define hidden_weak(name)
+# endif
+# define hidden_def(name)
+#endif
+
+#if !defined NOT_IN_libc
+# define libc_hidden_proto(name) hidden_proto (name)
+# define libc_hidden_def(name) hidden_def (name)
+# define libc_hidden_weak(name) hidden_weak (name)
+#else
+# define libc_hidden_proto(name)
+# define libc_hidden_def(name)
+# define libc_hidden_weak(name)
+#endif
+
+#if defined NOT_IN_libc && defined IS_IN_rtld
+# define rtld_hidden_proto(name) hidden_proto (name)
+# define rtld_hidden_def(name) hidden_def (name)
+# define rtld_hidden_weak(name) hidden_weak (name)
+#else
+# define rtld_hidden_proto(name)
+# define rtld_hidden_def(name)
+# define rtld_hidden_weak(name)
+#endif
+
+#if defined NOT_IN_libc && defined IS_IN_libm
+# define libm_hidden_proto(name) hidden_proto (name)
+# define libm_hidden_def(name) hidden_def (name)
+# define libm_hidden_weak(name) hidden_weak (name)
+#else
+# define libm_hidden_proto(name)
+# define libm_hidden_def(name)
+# define libm_hidden_weak(name)
+#endif
+
 #endif /* libc-symbols.h */
--- libc/include/assert.h.jj	2002-07-29 15:14:50.000000000 +0200
+++ libc/include/assert.h	2002-08-01 18:25:41.000000000 +0200
@@ -1,10 +1,12 @@
 #include <assert/assert.h>
 
-extern void __assert_fail_internal (__const char *__assertion,
-				    __const char *__file,
-				    unsigned int __line,
-				    __const char *__function)
-     __attribute__ ((__noreturn__)) attribute_hidden;
-#if defined SHARED && !defined NOT_IN_libc
-# define __assert_fail __assert_fail_internal
+/* This prints an "Assertion failed" message and aborts.
+   In installed assert.h this is only conditionally declared,
+   so it has to be repeated here.  */
+extern void __assert_fail (__const char *__assertion, __const char *__file,
+			   unsigned int __line, __const char *__function)
+  __THROW __attribute__ ((__noreturn__));
+
+#if !defined NOT_IN_libc || defined IS_IN_rtld
+hidden_proto (__assert_fail)
 #endif
--- libc/include/libc-internal.h.jj	2002-03-23 11:50:27.000000000 +0100
+++ libc/include/libc-internal.h	2002-08-01 15:44:51.000000000 +0200
@@ -25,6 +25,7 @@ extern hp_timing_t __get_clockfreq (void
 
 /* Free all allocated resources.  */
 extern void __libc_freeres (void);
+libc_hidden_proto (__libc_freeres)
 
 /* Define and initialize `__progname' et. al.  */
 extern void __init_misc (int, char **, char **);
--- libc/include/wchar.h.jj	2002-04-30 12:52:49.000000000 +0200
+++ libc/include/wchar.h	2002-08-01 15:50:52.000000000 +0200
@@ -18,12 +18,8 @@ extern int __mbsinit (__const __mbstate_
 extern size_t __mbrtowc (wchar_t *__restrict __pwc,
 			 __const char *__restrict __s, size_t __n,
 			 __mbstate_t *__restrict __p);
-extern size_t __mbrtowc_internal (wchar_t *__restrict __pwc,
-				  __const char *__restrict __s, size_t __n,
-				  __mbstate_t *__restrict __p)
-     attribute_hidden;
-extern size_t __mbrlen_internal (__const char *__restrict __s, size_t __n,
-				 mbstate_t *__restrict __ps) attribute_hidden;
+libc_hidden_proto (__mbrtowc)
+libc_hidden_proto (__mbrlen)
 extern size_t __wcrtomb (char *__restrict __s, wchar_t __wc,
 			 __mbstate_t *__restrict __ps);
 extern size_t __mbsrtowcs (wchar_t *__restrict __dst,
@@ -68,10 +64,5 @@ extern int __vfwprintf (__FILE *__restri
 			__gnuc_va_list __arg)
      /* __attribute__ ((__format__ (__wprintf__, 3, 0))) */;
 
-#  ifndef NOT_IN_libc
-#   define __mbrlen(s, n, ps) INTUSE(__mbrlen) (s, n, ps)
-#   define __mbrtowc(pwc, s, n, p) INTUSE(__mbrtowc) (pwc, s, n, p)
-#  endif
-
 # endif
 #endif
--- libc/include/string.h.jj	2001-09-12 09:56:44.000000000 +0200
+++ libc/include/string.h	2002-08-01 15:59:50.000000000 +0200
@@ -60,3 +60,5 @@ extern char *__strerror_r (int __errnum,
       (char *) memcpy (__new, __old, __len);				      \
     }))
 #endif
+
+libc_hidden_proto (__mempcpy)
--- libc/include/fcntl.h.jj	2002-04-30 12:52:49.000000000 +0200
+++ libc/include/fcntl.h	2002-08-01 18:11:11.000000000 +0200
@@ -3,23 +3,15 @@
 
 /* Now define the internal interfaces.  */
 extern int __open64 (__const char *__file, int __oflag, ...);
+libc_hidden_proto (__open64)
 extern int __libc_open64 (const char *file, int oflag, ...);
 extern int __libc_open (const char *file, int oflag, ...);
+libc_hidden_proto (__libc_open)
 extern int __libc_fcntl (int fd, int cmd, ...);
+libc_hidden_proto (__libc_fcntl)
 extern int __open (__const char *__file, int __oflag, ...);
-extern int __open_internal (__const char *__file, int __oflag, ...)
-     attribute_hidden;
+libc_hidden_proto (__open)
 extern int __fcntl (int __fd, int __cmd, ...);
-extern int __fcntl_internal (int __fd, int __cmd, ...) attribute_hidden;
-
-#ifndef NOT_IN_libc
-# define __fcntl(fd, cmd, args...) INTUSE(__fcntl) (fd, cmd, ##args)
-# define __open(file, oflag, args...) INTUSE(__open) (file, oflag, ##args)
-# ifdef SHARED
-#  define __libc_fcntl(fd, cmd, args...) __fcntl_internal (fd, cmd, ##args)
-#  define __libc_open(file, oflag, args...) \
-  __open_internal (file, oflag, ##args)
-# endif
-#endif
+libc_hidden_proto (__fcntl)
 
 #endif
--- libc/libio/iofdopen.c.jj	2002-04-30 12:52:49.000000000 +0200
+++ libc/libio/iofdopen.c	2002-08-01 18:03:29.000000000 +0200
@@ -37,7 +37,7 @@
 
 #ifndef _IO_fcntl
 #ifdef _LIBC
-#define _IO_fcntl INTUSE(__fcntl)
+#define _IO_fcntl __fcntl
 #else
 #define _IO_fcntl fcntl
 #endif
--- libc/malloc/set-freeres.c.jj	2001-08-23 18:48:21.000000000 +0200
+++ libc/malloc/set-freeres.c	2002-08-01 15:45:22.000000000 +0200
@@ -43,3 +43,4 @@ __libc_freeres (void)
       RUN_HOOK (__libc_subfreeres, ());
     }
 }
+libc_hidden_def (__libc_freeres)
--- libc/nss/nsswitch.h.jj	2002-03-23 11:50:55.000000000 +0100
+++ libc/nss/nsswitch.h	2002-08-01 17:47:05.000000000 +0200
@@ -103,7 +103,7 @@ typedef struct name_database
    than one function can use the database.  */
 int __nss_database_lookup (const char *database, const char *alternative_name,
 			   const char *defconfig, service_user **ni);
-
+libc_hidden_proto (__nss_database_lookup)
 
 /* Put first function with name FCT_NAME for SERVICE in FCTP.  The
    position is remembered in NI.  The function returns a value < 0 if
@@ -125,6 +125,7 @@ int __nss_lookup (service_user **ni, con
    natural end.  */
 int __nss_next (service_user **ni, const char *fct_name, void **fctp,
 		int status, int all_values);
+libc_hidden_proto (__nss_next)
 
 /* Search for the service described in NI for a function named FCT_NAME
    and return a pointer to this function if successful.  */
--- libc/nss/nsswitch.c.jj	2002-03-23 11:50:55.000000000 +0100
+++ libc/nss/nsswitch.c	2002-08-01 17:47:51.000000000 +0200
@@ -136,6 +136,7 @@ __nss_database_lookup (const char *datab
 
   return 0;
 }
+libc_hidden_def (__nss_database_lookup)
 
 
 /* -1 == not found
@@ -199,6 +200,7 @@ __nss_next (service_user **ni, const cha
 
   return *fctp != NULL ? 0 : -1;
 }
+libc_hidden_def (__nss_next)
 
 
 int
--- libc/sysdeps/generic/mempcpy.c.jj	2001-08-23 18:49:33.000000000 +0200
+++ libc/sysdeps/generic/mempcpy.c	2002-08-01 16:01:11.000000000 +0200
@@ -25,7 +25,6 @@
 #include <pagecopy.h>
 
 #undef mempcpy
-#undef __mempcpy
 
 void *
 __mempcpy (dstpp, srcpp, len)
@@ -64,4 +63,5 @@ __mempcpy (dstpp, srcpp, len)
 
   return (void *) dstp;
 }
+libc_hidden_def (__mempcpy)
 weak_alias (__mempcpy, mempcpy)
--- libc/sysdeps/generic/open64.c.jj	2001-08-23 18:49:33.000000000 +0200
+++ libc/sysdeps/generic/open64.c	2002-08-01 17:56:47.000000000 +0200
@@ -49,6 +49,7 @@ __libc_open64 (file, oflag)
   return -1;
 }
 strong_alias (__libc_open64, __open64)
+libc_hidden_def (__open64)
 weak_alias (__libc_open64, BP_SYM (open64))
 
 stub_warning (open64)
--- libc/sysdeps/generic/open.c.jj	2002-04-30 12:53:42.000000000 +0200
+++ libc/sysdeps/generic/open.c	2002-08-01 17:57:32.000000000 +0200
@@ -21,8 +21,6 @@
 #include <stdarg.h>
 #include <stddef.h>
 
-#undef __open
-
 /* Open FILE with access OFLAG.  If OFLAG includes O_CREAT,
    a third argument is the file protection.  */
 int
@@ -49,8 +47,8 @@ __open (file, oflag)
   __set_errno (ENOSYS);
   return -1;
 }
+libc_hidden_def (__open)
 stub_warning (open)
 
-INTDEF(__open)
 weak_alias (__open, open)
 #include <stub-tag.h>
--- libc/sysdeps/generic/fcntl.c.jj	2002-04-30 12:53:42.000000000 +0200
+++ libc/sysdeps/generic/fcntl.c	2002-08-01 17:57:48.000000000 +0200
@@ -19,8 +19,6 @@
 #include <errno.h>
 #include <fcntl.h>
 
-#undef __fcntl
-
 /* Perform file control operations on FD.  */
 int
 __fcntl (fd, cmd)
@@ -36,6 +34,7 @@ __fcntl (fd, cmd)
   __set_errno (ENOSYS);
   return -1;
 }
+libc_hidden_def (__fcntl)
 stub_warning (fcntl)
 
 weak_alias (__fcntl, fcntl)
--- libc/sysdeps/i386/i586/mempcpy.S.jj	2000-07-27 15:59:51.000000000 +0200
+++ libc/sysdeps/i386/i586/mempcpy.S	2002-08-01 16:37:13.000000000 +0200
@@ -1,4 +1,5 @@
 #define memcpy __mempcpy
 #include <sysdeps/i386/i586/memcpy.S>
 
+libc_hidden_def (BP_SYM (__mempcpy))
 weak_alias (BP_SYM (__mempcpy), BP_SYM (mempcpy))
--- libc/sysdeps/i386/i686/mempcpy.S.jj	2001-08-23 18:49:52.000000000 +0200
+++ libc/sysdeps/i386/i686/mempcpy.S	2002-08-01 16:37:54.000000000 +0200
@@ -57,4 +57,5 @@ ENTRY (BP_SYM (__mempcpy))
 	LEAVE
 	RET_PTR
 END (BP_SYM (__mempcpy))
+libc_hidden_def (BP_SYM (__mempcpy))
 weak_alias (BP_SYM (__mempcpy), BP_SYM (mempcpy))
--- libc/sysdeps/mach/hurd/fcntl.c.jj	2002-06-05 10:27:45.000000000 +0200
+++ libc/sysdeps/mach/hurd/fcntl.c	2002-08-01 18:11:31.000000000 +0200
@@ -23,10 +23,6 @@
 #include <stdarg.h>
 #include <sys/file.h>		/* XXX for LOCK_* */
 
-#undef __libc_fcntl
-#undef __fcntl
-
-
 /* Perform file control operations on FD.  */
 int
 __libc_fcntl (int fd, int cmd, ...)
@@ -200,7 +196,7 @@ __libc_fcntl (int fd, int cmd, ...)
 
   return result;
 }
-
-INTDEF2 (__libc_fcntl, __fcntl)
+libc_hidden_def (__libc_fcntl)
 weak_alias (__libc_fcntl, __fcntl)
+libc_hidden_weak (__fcntl)
 weak_alias (__libc_fcntl, fcntl)
--- libc/sysdeps/mach/hurd/open.c.jj	2002-04-30 12:55:01.000000000 +0200
+++ libc/sysdeps/mach/hurd/open.c	2002-08-01 18:12:47.000000000 +0200
@@ -22,9 +22,6 @@
 #include <hurd.h>
 #include <hurd/fd.h>
 
-#undef __libc_open
-#undef __open
-
 /* Open FILE with access OFLAG.  If OFLAG includes O_CREAT,
    a third argument is the file protection.  */
 int
@@ -50,6 +47,7 @@ __libc_open (const char *file, int oflag
   return _hurd_intern_fd (port, oflag, 1);
 }
 
-INTDEF2(__libc_open, __open)
+libc_hidden_def (__libc_open)
 weak_alias (__libc_open, __open)
+libc_hidden_weak (__open)
 weak_alias (__libc_open, open)
--- libc/sysdeps/posix/open64.c.jj	2001-08-23 18:50:11.000000000 +0200
+++ libc/sysdeps/posix/open64.c	2002-08-01 18:00:52.000000000 +0200
@@ -38,4 +38,5 @@ __libc_open64 (const char *file, int ofl
   return __libc_open (file, oflag | O_LARGEFILE, mode);
 }
 weak_alias (__libc_open64, BP_SYM (__open64))
+libc_hidden_weak (BP_SYM (__open64))
 weak_alias (__libc_open64, BP_SYM (open64))
--- libc/sysdeps/standalone/open.c.jj	2001-08-23 18:50:27.000000000 +0200
+++ libc/sysdeps/standalone/open.c	2002-08-01 18:20:31.000000000 +0200
@@ -82,6 +82,7 @@ __open (file, oflag)
 
   return newfd;
 }
+libc_hidden_def (__open)
 
 /* Initialization Code for Console I/O */
 
--- libc/sysdeps/unix/sysv/aix/fcntl.c.jj	2002-04-30 12:56:36.000000000 +0200
+++ libc/sysdeps/unix/sysv/aix/fcntl.c	2002-08-01 18:13:52.000000000 +0200
@@ -19,9 +19,6 @@
 #include <fcntl.h>
 #include <stdarg.h>
 
-#undef __libc_fcntl
-#undef __fcntl
-
 extern int kfcntl (int fdes, int cmd, unsigned long int arg);
 
 int
@@ -40,5 +37,7 @@ __fcntl (int fdes, int cmd, ...)
 
   return res;
 }
+libc_hidden_def (__fcntl)
 strong_alias (__fcntl, fcntl)
 strong_alias (__fcntl, __libc_fcntl)
+libc_hidden_def (__libc_fcntl)
--- libc/sysdeps/unix/sysv/aix/open.c.jj	2002-04-30 12:56:37.000000000 +0200
+++ libc/sysdeps/unix/sysv/aix/open.c	2002-08-01 18:14:42.000000000 +0200
@@ -20,9 +20,6 @@
 #include <stdarg.h>
 #include <unistd.h>
 
-#undef __libc_open
-#undef __open
-
 int
 __open (const char *file, int oflag, ...)
 {
@@ -38,5 +35,6 @@ __open (const char *file, int oflag, ...
 
   return open (file, oflag, mode);
 }
+libc_hidden_def (__open)
 strong_alias (__open, __libc_open)
-INTDEF(__open)
+libc_hidden_def (__libc_open)
--- libc/sysdeps/unix/sysv/linux/i386/fcntl.c.jj	2002-04-25 22:02:23.000000000 +0200
+++ libc/sysdeps/unix/sysv/linux/i386/fcntl.c	2002-08-01 18:15:34.000000000 +0200
@@ -25,9 +25,6 @@
 #include <sys/syscall.h>
 #include "../kernel-features.h"
 
-#undef __libc_fcntl
-#undef __fcntl
-
 extern int __syscall_fcntl (int __fd, int __cmd, ...);
 #ifdef __NR_fcntl64
 extern int __syscall_fcntl64 (int __fd, int __cmd, ...);
@@ -133,7 +130,8 @@ __libc_fcntl (int fd, int cmd, ...)
   return -1;
 #endif  /* __ASSUME_FCNTL64  */
 }
-INTDEF2(__libc_fcntl, __fcntl);
+libc_hidden_def (__libc_fcntl)
 
 weak_alias (__libc_fcntl, __fcntl)
+libc_hidden_weak (__fcntl)
 weak_alias (__libc_fcntl, fcntl)
--- libc/sysdeps/unix/sysv/linux/syscalls.list.jj	2002-07-25 14:59:41.000000000 +0200
+++ libc/sysdeps/unix/sysv/linux/syscalls.list	2002-08-01 18:18:41.000000000 +0200
@@ -63,4 +63,4 @@ uselib		EXTRA	uselib		i:s	uselib
 wait4		-	wait4		i:iWiP	__wait4		wait4
 
 chown		-	chown		i:sii	__chown_internal __chown chown
-fcntl		-	fcntl		i:iiF	__libc_fcntl	__fcntl_internal __fcntl fcntl
+fcntl		-	fcntl		i:iiF	__libc_fcntl	__GI___libc_fcntl __fcntl __GI___fcntl fcntl
--- libc/sysdeps/unix/syscalls.list.jj	2002-04-30 12:56:18.000000000 +0200
+++ libc/sysdeps/unix/syscalls.list	2002-08-01 18:17:36.000000000 +0200
@@ -10,7 +10,7 @@ close		-	close		i:i	__libc_close	__close
 dup		-	dup		i:i	__dup		dup
 dup2		-	dup2		i:ii	__dup2		dup2 __dup2_internal
 fchdir		-	fchdir		i:i	__fchdir	fchdir
-fcntl		-	fcntl		i:iiF	__libc_fcntl	__fcntl fcntl
+fcntl		-	fcntl		i:iiF	__libc_fcntl	__GI___libc_fcntl __fcntl __GI___fcntl fcntl
 fstatfs		-	fstatfs		i:ip	__fstatfs	fstatfs
 fsync		-	fsync		i:i	__libc_fsync	fsync
 getdomain	-	getdomainname	i:si	getdomainname
@@ -26,7 +26,7 @@ kill		-	kill		i:ii	__kill		kill
 link		-	link		i:ss	__link		link
 lseek		-	lseek		i:iii	__libc_lseek	__lseek lseek
 mkdir		-	mkdir		i:si	__mkdir		mkdir
-open		-	open		i:siv	__libc_open	__open open __open_internal
+open		-	open		i:siv	__libc_open	__GI___libc_open __open open __GI___open
 profil		-	profil		i:piii	profil
 ptrace		-	ptrace		i:iiii	ptrace
 read		-	read		i:ibn	__libc_read	__read read
--- libc/wcsmbs/mbrlen.c.jj	2002-04-30 12:57:38.000000000 +0200
+++ libc/wcsmbs/mbrlen.c	2002-08-01 15:54:45.000000000 +0200
@@ -19,8 +19,6 @@
 
 #include <wchar.h>
 
-#undef __mbrlen
-
 /* The mbrlen function has an internal shift state which gets used if
    the PS parameter is NULL.  */
 static mbstate_t internal;
@@ -34,5 +32,5 @@ __mbrlen (s, n, ps)
 {
   return __mbrtowc (NULL, s, n, ps ?: &internal);
 }
-INTDEF(__mbrlen)
+libc_hidden_def (__mbrlen)
 weak_alias (__mbrlen, mbrlen)
--- libc/wcsmbs/mbrtowc.c.jj	2002-04-30 12:57:39.000000000 +0200
+++ libc/wcsmbs/mbrtowc.c	2002-08-01 15:55:52.000000000 +0200
@@ -29,8 +29,6 @@
 # define EILSEQ EINVAL
 #endif
 
-#undef __mbrtowc
-
 /* This is the private state used if PS is NULL.  */
 static mbstate_t state;
 
@@ -106,5 +104,5 @@ __mbrtowc (wchar_t *pwc, const char *s, 
 
   return result;
 }
-INTDEF(__mbrtowc)
+libc_hidden_def (__mbrtowc)
 weak_alias (__mbrtowc, mbrtowc)


	Jakub

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] New macros for bypassing PLT calls
  2002-08-01 15:27     ` [PATCH] " Jakub Jelinek
@ 2002-08-02  0:26       ` Ulrich Drepper
  0 siblings, 0 replies; 5+ messages in thread
From: Ulrich Drepper @ 2002-08-02  0:26 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Roland McGrath, Glibc hackers

Jakub Jelinek wrote:

> Shall I continue tomorrow (well, today europe time) with other symbols?

Yes, please, this looks good.

I won't check the patch in until the test for broken compilers is 
available as well.  Thanks,

-- 
---------------.                          ,-.   1325 Chesapeake Terrace
Ulrich Drepper  \    ,-------------------'   \  Sunnyvale, CA 94089 USA
Red Hat          `--' drepper at redhat.com   `------------------------

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2002-08-02  7:26 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-07-31  7:45 RFC: New macros for bypassing PLT calls Jakub Jelinek
2002-07-31 13:03 ` Roland McGrath
2002-07-31 13:29   ` Ulrich Drepper
2002-08-01 15:27     ` [PATCH] " Jakub Jelinek
2002-08-02  0:26       ` Ulrich Drepper

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).