Message ID | ME2P282MB2242912DC6B2D7AD8DAD1ABFB4769@ME2P282MB2242.AUSP282.PROD.OUTLOOK.COM |
---|---|
State | New |
Headers | show |
Series | elf: Fix marking root dir as nonexist in open_path | expand |
On 2023-05-09 18:56, Qixing ksyx Xue via Libc-alpha wrote: > Suggested-by: Carlos O'Donell <carlos@redhat.com> > Signed-off-by: Qixing ksyx Xue <qixingxue@outlook.com> > --- > elf/Makefile | 3 +++ > elf/tst-rootdir-lib.c | 23 +++++++++++++++++++ > elf/tst-rootdir.c | 37 +++++++++++++++++++++++++++++++ > elf/tst-rootdir.root/preclean.req | 0 > elf/tst-rootdir.script | 1 + > 5 files changed, 64 insertions(+) > create mode 100644 elf/tst-rootdir-lib.c > create mode 100644 elf/tst-rootdir.c > create mode 100644 elf/tst-rootdir.root/preclean.req > create mode 100644 elf/tst-rootdir.script Sorry, I acked Andreas' patch to fix the same issue; it's also a slightly cleaner fix. It didn't have a test case though, so thank you for writing the test! Could you please send a v3 of the test with the following nits fixed and also quote the BZ number in the subject? Thanks, Sid > > diff --git a/elf/Makefile b/elf/Makefile > index 396ec51424..ee81575cbb 100644 > --- a/elf/Makefile > +++ b/elf/Makefile > @@ -325,6 +325,7 @@ static-dlopen-environment = \ > LD_LIBRARY_PATH=$(ld-library-path):$(common-objpfx)dlfcn > tst-tls9-static-ENV = $(static-dlopen-environment) > tst-single_threaded-static-dlopen-ENV = $(static-dlopen-environment) > +tst-rootdir-ENV = LD_LIBRARY_PATH=/ > > tests += \ > argv0test \ > @@ -506,6 +507,7 @@ tests-container += \ > tst-dlopen-tlsmodid-container \ > tst-pldd \ > tst-preload-pthread-libc \ > + tst-rootdir \ > # tests-container > > test-srcs = \ > @@ -854,6 +856,7 @@ modules-names += \ > tst-relsort1mod1 \ > tst-relsort1mod2 \ > tst-ro-dynamic-mod \ > + tst-rootdir-lib \ > tst-single_threaded-mod1 \ > tst-single_threaded-mod2 \ > tst-single_threaded-mod3 \ > diff --git a/elf/tst-rootdir-lib.c b/elf/tst-rootdir-lib.c > new file mode 100644 > index 0000000000..22b7bdad70 > --- /dev/null > +++ b/elf/tst-rootdir-lib.c > @@ -0,0 +1,23 @@ > +/* Simple library for testing locating library in root directories. > + Copyright (C) 2023 Free Software Foundation, Inc. Please change this to "Copyright The GNU Toolchain Authors." for both files. > + This file is part of the GNU C Library. > + > + The GNU C Library is free software; you can redistribute it and/or > + modify it under the terms of the GNU Lesser General Public > + License as published by the Free Software Foundation; either > + version 2.1 of the License, or (at your option) any later version. > + > + The GNU C Library 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 > + Lesser General Public License for more details. > + > + You should have received a copy of the GNU Lesser General Public > + License along with the GNU C Library; if not, see > + <http://www.gnu.org/licenses/>. */ > + > +const char * > +test_func (void) > +{ > + return "Success"; > +} > diff --git a/elf/tst-rootdir.c b/elf/tst-rootdir.c > new file mode 100644 > index 0000000000..a31d4237af > --- /dev/null > +++ b/elf/tst-rootdir.c > @@ -0,0 +1,37 @@ > +/* Test code for locating libraries in root directories. > + Copyright (C) 2023 Free Software Foundation, Inc. > + This file is part of the GNU C Library. > + > + The GNU C Library is free software; you can redistribute it and/or > + modify it under the terms of the GNU Lesser General Public > + License as published by the Free Software Foundation; either > + version 2.1 of the License, or (at your option) any later version. > + > + The GNU C Library 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 > + Lesser General Public License for more details. > + > + You should have received a copy of the GNU Lesser General Public > + License along with the GNU C Library; if not, see > + <http://www.gnu.org/licenses/>. */ > + > +#include <support/test-driver.h> > +#include <support/check.h> > +#include <dlfcn.h> > +#include <assert.h> > + > +static int > +do_test (void) > +{ > + void *handle = dlopen ("libtest.so", RTLD_LAZY); > + TEST_VERIFY_EXIT (handle != NULL); > + typedef const char *(test_func_t) (void); > + test_func_t *func = dlsym (handle, "test_func"); > + assert (func != NULL); > + TEST_COMPARE_STRING (func (), "Success"); > + dlclose (handle); > + return 0; > +} > + > +#include <support/test-driver.c> > diff --git a/elf/tst-rootdir.root/preclean.req b/elf/tst-rootdir.root/preclean.req > new file mode 100644 > index 0000000000..e69de29bb2 > diff --git a/elf/tst-rootdir.script b/elf/tst-rootdir.script > new file mode 100644 > index 0000000000..f852c0ec34 > --- /dev/null > +++ b/elf/tst-rootdir.script > @@ -0,0 +1 @@ > +cp $B/elf/tst-rootdir-lib.so /libtest.so
diff --git a/elf/Makefile b/elf/Makefile index 396ec51424..ee81575cbb 100644 --- a/elf/Makefile +++ b/elf/Makefile @@ -325,6 +325,7 @@ static-dlopen-environment = \ LD_LIBRARY_PATH=$(ld-library-path):$(common-objpfx)dlfcn tst-tls9-static-ENV = $(static-dlopen-environment) tst-single_threaded-static-dlopen-ENV = $(static-dlopen-environment) +tst-rootdir-ENV = LD_LIBRARY_PATH=/ tests += \ argv0test \ @@ -506,6 +507,7 @@ tests-container += \ tst-dlopen-tlsmodid-container \ tst-pldd \ tst-preload-pthread-libc \ + tst-rootdir \ # tests-container test-srcs = \ @@ -854,6 +856,7 @@ modules-names += \ tst-relsort1mod1 \ tst-relsort1mod2 \ tst-ro-dynamic-mod \ + tst-rootdir-lib \ tst-single_threaded-mod1 \ tst-single_threaded-mod2 \ tst-single_threaded-mod3 \ diff --git a/elf/tst-rootdir-lib.c b/elf/tst-rootdir-lib.c new file mode 100644 index 0000000000..22b7bdad70 --- /dev/null +++ b/elf/tst-rootdir-lib.c @@ -0,0 +1,23 @@ +/* Simple library for testing locating library in root directories. + Copyright (C) 2023 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + <http://www.gnu.org/licenses/>. */ + +const char * +test_func (void) +{ + return "Success"; +} diff --git a/elf/tst-rootdir.c b/elf/tst-rootdir.c new file mode 100644 index 0000000000..a31d4237af --- /dev/null +++ b/elf/tst-rootdir.c @@ -0,0 +1,37 @@ +/* Test code for locating libraries in root directories. + Copyright (C) 2023 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + <http://www.gnu.org/licenses/>. */ + +#include <support/test-driver.h> +#include <support/check.h> +#include <dlfcn.h> +#include <assert.h> + +static int +do_test (void) +{ + void *handle = dlopen ("libtest.so", RTLD_LAZY); + TEST_VERIFY_EXIT (handle != NULL); + typedef const char *(test_func_t) (void); + test_func_t *func = dlsym (handle, "test_func"); + assert (func != NULL); + TEST_COMPARE_STRING (func (), "Success"); + dlclose (handle); + return 0; +} + +#include <support/test-driver.c> diff --git a/elf/tst-rootdir.root/preclean.req b/elf/tst-rootdir.root/preclean.req new file mode 100644 index 0000000000..e69de29bb2 diff --git a/elf/tst-rootdir.script b/elf/tst-rootdir.script new file mode 100644 index 0000000000..f852c0ec34 --- /dev/null +++ b/elf/tst-rootdir.script @@ -0,0 +1 @@ +cp $B/elf/tst-rootdir-lib.so /libtest.so
Suggested-by: Carlos O'Donell <carlos@redhat.com> Signed-off-by: Qixing ksyx Xue <qixingxue@outlook.com> --- elf/Makefile | 3 +++ elf/tst-rootdir-lib.c | 23 +++++++++++++++++++ elf/tst-rootdir.c | 37 +++++++++++++++++++++++++++++++ elf/tst-rootdir.root/preclean.req | 0 elf/tst-rootdir.script | 1 + 5 files changed, 64 insertions(+) create mode 100644 elf/tst-rootdir-lib.c create mode 100644 elf/tst-rootdir.c create mode 100644 elf/tst-rootdir.root/preclean.req create mode 100644 elf/tst-rootdir.script