Message ID | 20170901180029.9527-9-hjl.tools@gmail.com |
---|---|
State | New |
Headers | show |
Series | Hide internal functions in libc.so | expand |
On 09/01/2017 07:59 PM, H.J. Lu wrote: > diff --git a/include/stdlib.h b/include/stdlib.h > index 2274790a2e..d0dcbf81c3 100644 > --- a/include/stdlib.h > +++ b/include/stdlib.h > @@ -5,6 +5,10 @@ > #endif > #include <stdlib/stdlib.h> > > +/* __dso_handle is always defined by either crtbegin.o from GCC or our > + dso_handle.c. */ > +extern void *__dso_handle __attribute__ ((visibility ("hidden"))); This causes conform test failures. You need to use __visibility__ here. Thanks, Florian
On 09/03/2017 10:21 AM, Florian Weimer wrote: > On 09/01/2017 07:59 PM, H.J. Lu wrote: >> diff --git a/include/stdlib.h b/include/stdlib.h >> index 2274790a2e..d0dcbf81c3 100644 >> --- a/include/stdlib.h >> +++ b/include/stdlib.h >> @@ -5,6 +5,10 @@ >> #endif >> #include <stdlib/stdlib.h> >> >> +/* __dso_handle is always defined by either crtbegin.o from GCC or our >> + dso_handle.c. */ >> +extern void *__dso_handle __attribute__ ((visibility ("hidden"))); > > This causes conform test failures. You need to use __visibility__ here. Or alternatively, move the declaration under #ifndef _ISOMAC. That's probably the better approach because __dso_handle is not part of the installed headers. Thanks, Florian
On Sun, Sep 3, 2017 at 2:11 AM, Florian Weimer <fweimer@redhat.com> wrote: > On 09/03/2017 10:21 AM, Florian Weimer wrote: >> On 09/01/2017 07:59 PM, H.J. Lu wrote: >>> diff --git a/include/stdlib.h b/include/stdlib.h >>> index 2274790a2e..d0dcbf81c3 100644 >>> --- a/include/stdlib.h >>> +++ b/include/stdlib.h >>> @@ -5,6 +5,10 @@ >>> #endif >>> #include <stdlib/stdlib.h> >>> >>> +/* __dso_handle is always defined by either crtbegin.o from GCC or our >>> + dso_handle.c. */ >>> +extern void *__dso_handle __attribute__ ((visibility ("hidden"))); >> >> This causes conform test failures. You need to use __visibility__ here. I am testing it. > Or alternatively, move the declaration under #ifndef _ISOMAC. That's > probably the better approach because __dso_handle is not part of the > installed headers. > No, we can't do that. Some tests reference __dso_handle and _ISOMAC isn't defined for tests. BTW, hjl/pr18822 branch is what I am using.
On 09/03/2017 03:42 PM, H.J. Lu wrote: > On Sun, Sep 3, 2017 at 2:11 AM, Florian Weimer <fweimer@redhat.com> wrote: >> On 09/03/2017 10:21 AM, Florian Weimer wrote: >>> On 09/01/2017 07:59 PM, H.J. Lu wrote: >>>> diff --git a/include/stdlib.h b/include/stdlib.h >>>> index 2274790a2e..d0dcbf81c3 100644 >>>> --- a/include/stdlib.h >>>> +++ b/include/stdlib.h >>>> @@ -5,6 +5,10 @@ >>>> #endif >>>> #include <stdlib/stdlib.h> >>>> >>>> +/* __dso_handle is always defined by either crtbegin.o from GCC or our >>>> + dso_handle.c. */ >>>> +extern void *__dso_handle __attribute__ ((visibility ("hidden"))); >>> >>> This causes conform test failures. You need to use __visibility__ here. >> Or alternatively, move the declaration under #ifndef _ISOMAC. That's >> probably the better approach because __dso_handle is not part of the >> installed headers. >> > > No, we can't do that. Some tests reference __dso_handle and _ISOMAC > isn't defined for tests. These tests should be moved to tests-internal, or __dso_handle should be declared in a different header and the tests should include it. As far as I understand it, the _ISOMAC mechanism is there to make the include/ headers as close as possible to the installed headers, so declaring things there which are not available after installation partially invalidates in-tree testing. Thanks, Florian
On Mon, Sep 4, 2017 at 12:22 AM, Florian Weimer <fweimer@redhat.com> wrote: > On 09/03/2017 03:42 PM, H.J. Lu wrote: >> On Sun, Sep 3, 2017 at 2:11 AM, Florian Weimer <fweimer@redhat.com> wrote: >>> On 09/03/2017 10:21 AM, Florian Weimer wrote: >>>> On 09/01/2017 07:59 PM, H.J. Lu wrote: >>>>> diff --git a/include/stdlib.h b/include/stdlib.h >>>>> index 2274790a2e..d0dcbf81c3 100644 >>>>> --- a/include/stdlib.h >>>>> +++ b/include/stdlib.h >>>>> @@ -5,6 +5,10 @@ >>>>> #endif >>>>> #include <stdlib/stdlib.h> >>>>> >>>>> +/* __dso_handle is always defined by either crtbegin.o from GCC or our >>>>> + dso_handle.c. */ >>>>> +extern void *__dso_handle __attribute__ ((visibility ("hidden"))); >>>> >>>> This causes conform test failures. You need to use __visibility__ here. > >>> Or alternatively, move the declaration under #ifndef _ISOMAC. That's >>> probably the better approach because __dso_handle is not part of the >>> installed headers. >>> >> >> No, we can't do that. Some tests reference __dso_handle and _ISOMAC >> isn't defined for tests. > > These tests should be moved to tests-internal, or __dso_handle should be We may not define _ISOMAC for these tests since it may introduce many issues. > declared in a different header and the tests should include it. Here is an updated with include/dso_handle.h. OK for master? Thanks.
On Mon, Sep 4, 2017 at 2:19 PM, H.J. Lu <hjl.tools@gmail.com> wrote: > On Mon, Sep 4, 2017 at 12:22 AM, Florian Weimer <fweimer@redhat.com> wrote: >> On 09/03/2017 03:42 PM, H.J. Lu wrote: >>> On Sun, Sep 3, 2017 at 2:11 AM, Florian Weimer <fweimer@redhat.com> wrote: >>>> On 09/03/2017 10:21 AM, Florian Weimer wrote: >>>>> On 09/01/2017 07:59 PM, H.J. Lu wrote: >>>>>> diff --git a/include/stdlib.h b/include/stdlib.h >>>>>> index 2274790a2e..d0dcbf81c3 100644 >>>>>> --- a/include/stdlib.h >>>>>> +++ b/include/stdlib.h >>>>>> @@ -5,6 +5,10 @@ >>>>>> #endif >>>>>> #include <stdlib/stdlib.h> >>>>>> >>>>>> +/* __dso_handle is always defined by either crtbegin.o from GCC or our >>>>>> + dso_handle.c. */ >>>>>> +extern void *__dso_handle __attribute__ ((visibility ("hidden"))); >>>>> >>>>> This causes conform test failures. You need to use __visibility__ here. >> >>>> Or alternatively, move the declaration under #ifndef _ISOMAC. That's >>>> probably the better approach because __dso_handle is not part of the >>>> installed headers. >>>> >>> >>> No, we can't do that. Some tests reference __dso_handle and _ISOMAC >>> isn't defined for tests. >> >> These tests should be moved to tests-internal, or __dso_handle should be > > We may not define _ISOMAC for these tests since it may introduce > many issues. > >> declared in a different header and the tests should include it. > > Here is an updated with include/dso_handle.h. OK for master? > > Thanks. > Any comments or objections? Thanks.
On 9/12/17, H.J. Lu <hjl.tools@gmail.com> wrote: > On Mon, Sep 4, 2017 at 2:19 PM, H.J. Lu <hjl.tools@gmail.com> wrote: >> On Mon, Sep 4, 2017 at 12:22 AM, Florian Weimer <fweimer@redhat.com> >> wrote: >>> On 09/03/2017 03:42 PM, H.J. Lu wrote: >>>> On Sun, Sep 3, 2017 at 2:11 AM, Florian Weimer <fweimer@redhat.com> >>>> wrote: >>>>> On 09/03/2017 10:21 AM, Florian Weimer wrote: >>>>>> On 09/01/2017 07:59 PM, H.J. Lu wrote: >>>>>>> diff --git a/include/stdlib.h b/include/stdlib.h >>>>>>> index 2274790a2e..d0dcbf81c3 100644 >>>>>>> --- a/include/stdlib.h >>>>>>> +++ b/include/stdlib.h >>>>>>> @@ -5,6 +5,10 @@ >>>>>>> #endif >>>>>>> #include <stdlib/stdlib.h> >>>>>>> >>>>>>> +/* __dso_handle is always defined by either crtbegin.o from GCC or >>>>>>> our >>>>>>> + dso_handle.c. */ >>>>>>> +extern void *__dso_handle __attribute__ ((visibility ("hidden"))); >>>>>> >>>>>> This causes conform test failures. You need to use __visibility__ >>>>>> here. >>> >>>>> Or alternatively, move the declaration under #ifndef _ISOMAC. That's >>>>> probably the better approach because __dso_handle is not part of the >>>>> installed headers. >>>>> >>>> >>>> No, we can't do that. Some tests reference __dso_handle and _ISOMAC >>>> isn't defined for tests. >>> >>> These tests should be moved to tests-internal, or __dso_handle should be >> >> We may not define _ISOMAC for these tests since it may introduce >> many issues. >> >>> declared in a different header and the tests should include it. >> >> Here is an updated with include/dso_handle.h. OK for master? >> >> Thanks. >> > > Any comments or objections? > > Thanks. > I will check it in today.
diff --git a/dlfcn/modatexit.c b/dlfcn/modatexit.c index e620d10c70..95c18dcbac 100644 --- a/dlfcn/modatexit.c +++ b/dlfcn/modatexit.c @@ -35,9 +35,7 @@ dummy (void) void foo (void *p) { - extern void *__dso_handle __attribute__ ((__weak__)); printf ("This is %s\n", __FUNCTION__); atexit (dummy); - if (&__dso_handle) puts ("have dso handle"); else puts ("no dso handle"); ip = p; } diff --git a/dlfcn/modcxaatexit.c b/dlfcn/modcxaatexit.c index fbda2f3c9f..b921b5c9ac 100644 --- a/dlfcn/modcxaatexit.c +++ b/dlfcn/modcxaatexit.c @@ -34,7 +34,6 @@ fluffy (void *p) void bar (void *p) { - extern void *__dso_handle; printf ("This is %s\n", __FUNCTION__); __cxa_atexit (fluffy, p, __dso_handle); } diff --git a/dlfcn/tstatexit.c b/dlfcn/tstatexit.c index 2073843b8f..e25a3f8000 100644 --- a/dlfcn/tstatexit.c +++ b/dlfcn/tstatexit.c @@ -20,8 +20,6 @@ #include <stdlib.h> -extern void *__dso_handle __attribute__ ((__weak__)); - int main (void) { @@ -30,12 +28,6 @@ main (void) void (*fp) (void *); int v = 0; - if (&__dso_handle == NULL) - { - puts ("__dso_handle not available, cannot perform the test"); - exit (0); - } - h = dlopen (fname, RTLD_NOW); if (h == NULL) { diff --git a/dlfcn/tstcxaatexit.c b/dlfcn/tstcxaatexit.c index fde645c16b..37f25d63d4 100644 --- a/dlfcn/tstcxaatexit.c +++ b/dlfcn/tstcxaatexit.c @@ -19,8 +19,6 @@ #include <stdio.h> #include <stdlib.h> -extern void *__dso_handle __attribute__ ((__weak__)); - int main (void) { @@ -29,12 +27,6 @@ main (void) void (*fp) (void *); int v = 0; - if (&__dso_handle == NULL) - { - puts ("__dso_handle not available, cannot perform the test"); - exit (0); - } - h = dlopen (fname, RTLD_LAZY); if (h == NULL) { diff --git a/include/stdlib.h b/include/stdlib.h index 2274790a2e..d0dcbf81c3 100644 --- a/include/stdlib.h +++ b/include/stdlib.h @@ -5,6 +5,10 @@ #endif #include <stdlib/stdlib.h> +/* __dso_handle is always defined by either crtbegin.o from GCC or our + dso_handle.c. */ +extern void *__dso_handle __attribute__ ((visibility ("hidden"))); + /* Now define the internal interfaces. */ #if !defined _ISOMAC # include <sys/stat.h> diff --git a/malloc/mtrace.c b/malloc/mtrace.c index 6c362d9679..40dadc2be3 100644 --- a/malloc/mtrace.c +++ b/malloc/mtrace.c @@ -315,10 +315,9 @@ mtrace (void) #ifdef _LIBC if (!added_atexit_handler) { - extern void *__dso_handle __attribute__ ((__weak__)); added_atexit_handler = 1; __cxa_atexit ((void (*)(void *))release_libc_mem, NULL, - &__dso_handle ? __dso_handle : NULL); + __dso_handle); } #endif } diff --git a/nptl/pthread_atfork.c b/nptl/pthread_atfork.c index dc2ea07887..dd328b76f1 100644 --- a/nptl/pthread_atfork.c +++ b/nptl/pthread_atfork.c @@ -36,10 +36,6 @@ #include "pthreadP.h" #include <fork.h> -/* This is defined by newer gcc version unique for each module. */ -extern void *__dso_handle __attribute__ ((__weak__, - __visibility__ ("hidden"))); - /* Hide the symbol so that no definition but the one locally in the executable or DSO is used. */ @@ -51,8 +47,7 @@ attribute_hidden __pthread_atfork (void (*prepare) (void), void (*parent) (void), void (*child) (void)) { - return __register_atfork (prepare, parent, child, - &__dso_handle == NULL ? NULL : __dso_handle); + return __register_atfork (prepare, parent, child, __dso_handle); } #ifndef __pthread_atfork extern int pthread_atfork (void (*prepare) (void), void (*parent) (void), diff --git a/nptl/tst-atfork2mod.c b/nptl/tst-atfork2mod.c index fe64046d3c..1e49612bdd 100644 --- a/nptl/tst-atfork2mod.c +++ b/nptl/tst-atfork2mod.c @@ -46,7 +46,6 @@ static void __attribute__ ((constructor)) init (void) { - extern void *__dso_handle; printf ("dsohandle = %p\n", __dso_handle); if (pthread_atfork (prepare, parent, child) != 0) diff --git a/posix/wordexp-test.c b/posix/wordexp-test.c index 17ae812346..6ae769678c 100644 --- a/posix/wordexp-test.c +++ b/posix/wordexp-test.c @@ -30,13 +30,11 @@ #define IFS " \n\t" -extern void *__dso_handle __attribute__ ((__weak__, __visibility__ ("hidden"))); extern int __register_atfork (void (*) (void), void (*) (void), void (*) (void), void *); static int __app_register_atfork (void (*prepare) (void), void (*parent) (void), void (*child) (void)) { - return __register_atfork (prepare, parent, child, - &__dso_handle == NULL ? NULL : __dso_handle); + return __register_atfork (prepare, parent, child, __dso_handle); } /* Number of forks seen. */ diff --git a/stdlib/at_quick_exit.c b/stdlib/at_quick_exit.c index 3b74d0a688..ca54c3f851 100644 --- a/stdlib/at_quick_exit.c +++ b/stdlib/at_quick_exit.c @@ -36,15 +36,10 @@ #include "exit.h" -/* This is defined by newer gcc version unique for each module. */ -extern void *__dso_handle __attribute__ ((__weak__)); - - /* Register FUNC to be executed by `quick_exit'. */ int attribute_hidden at_quick_exit (void (*func) (void)) { - return __cxa_at_quick_exit ((void (*) (void *)) func, - &__dso_handle == NULL ? NULL : __dso_handle); + return __cxa_at_quick_exit ((void (*) (void *)) func, __dso_handle); } diff --git a/stdlib/atexit.c b/stdlib/atexit.c index f28b6ba1b7..aec7f5ce1b 100644 --- a/stdlib/atexit.c +++ b/stdlib/atexit.c @@ -35,11 +35,6 @@ #include <stdlib.h> #include "exit.h" - -/* This is defined by newer gcc version unique for each module. */ -extern void *__dso_handle __attribute__ ((__weak__)); - - /* Register FUNC to be executed by `exit'. */ int #ifndef atexit @@ -47,6 +42,5 @@ attribute_hidden #endif atexit (void (*func) (void)) { - return __cxa_atexit ((void (*) (void *)) func, NULL, - &__dso_handle == NULL ? NULL : __dso_handle); + return __cxa_atexit ((void (*) (void *)) func, NULL, __dso_handle); } diff --git a/stdlib/tst-tls-atexit-lib.c b/stdlib/tst-tls-atexit-lib.c index a227e4653c..9bdd690842 100644 --- a/stdlib/tst-tls-atexit-lib.c +++ b/stdlib/tst-tls-atexit-lib.c @@ -18,8 +18,6 @@ #include <stdlib.h> -extern void *__dso_handle; - typedef struct { void *val;