tools/xenstore: try to get minimum thread stack size for watch thread
PATCH v2 1/1 tools/xenstore: try to get minimum thread stack size for watch thread
When creating a pthread in xs_watch() try to get the minimal needed size of the thread from glibc instead of using a constant. This avoids problems when the library is used in programs with large per-thread memory.
Use dlsym() to get the pointer to __pthread_get_minstack() in order to avoid linkage problems and fall back to the current constant size if not found.
---
V2:
- use _GNU_SOURCE (Wei Liu)
- call __pthread_get_minstack() with parameter
- add -ldl to correct make flags
- ensure to not using smaller stack size than today
--- tools/xenstore/Makefile | 4 ++++ tools/xenstore/xs.c | 21 ++++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-)
tools/xenstore/Makefile +4 -0
@@ -100,6 +100,10 @@ libxenstore.so.$(MAJOR): libxenstore.so.$(MAJOR).$(MINOR) ln -sf $< $@ xs.opic: CFLAGS += -DUSE_PTHREAD +ifeq ($(CONFIG_Linux),y) +xs.opic: CFLAGS += -DUSE_DLSYM +libxenstore.so.$(MAJOR).$(MINOR): LDFLAGS += -ldl +endif libxenstore.so.$(MAJOR).$(MINOR): xs.opic xs_lib.opic $(CC) $(LDFLAGS) $(PTHREAD_LDFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,libxenstore.so.$(MAJOR) $(SHLIB_LDFLAGS) -o $@ $^ $(LDLIBS_libxentoolcore) $(SOCKET_LIBS) $(PTHREAD_LIBS) $(APPEND_LDFLAGS)
tools/xenstore/xs.c +20 -1
@@ -16,6 +16,8 @@License along with this library; If not, see <http://www.gnu.org/licenses/>. */ +#define _GNU_SOURCE +#include <sys/types.h> #include <sys/stat.h> #include <fcntl.h>
@@ -47,6 +49,10 @@ struct xs_stored_msg {#include <pthread.h> +#ifdef USE_DLSYM +#include <dlfcn.h> +#endif +struct xs_handle {/* Communications channel to xenstore daemon. */ int fd;
@@ -810,12 +816,25 @@ bool xs_watch(struct xs_handle *h, const char *path, const char *token)if (!h->read_thr_exists) {sigset_t set, old_set;pthread_attr_t attr; +static size_t stack_size; +#ifdef USE_DLSYM +size_t (*getsz)(pthread_attr_t *attr); +#endif if (pthread_attr_init (&attr) !=0 ) {mutex_unlock (&h->request_mutex);return false; } -if (pthread_attr_setstacksize (&attr,READ_THREAD_STACKSIZE ) !=0 ) { +if (!stack_size) { +#ifdef USE_DLSYM + getsz =dlsym (RTLD_DEFAULT ,"__pthread_get_minstack" ); +if (getsz) + stack_size =getsz (&attr); +#endif +if (stack_size <READ_THREAD_STACKSIZE ) + stack_size =READ_THREAD_STACKSIZE ; + } +if (pthread_attr_setstacksize (&attr, stack_size) !=0 ) {pthread_attr_destroy (&attr);mutex_unlock (&h->request_mutex);return false;
Signature · 7 lines
2.13.6 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 67 lines · Juergen Gross
When creating a pthread in
xs_watch()try to get the minimal needed size of the thread from glibc instead of using a constant. This avoids problems when the library is used in programs with large per-thread memory.Use
dlsym()to get the pointer to__pthread_get_minstack()in order to avoid linkage problems and fall back to the current constant size if not found.Signed-off-by Juergen Gross <[email protected]>---
V2:
- use_GNU_SOURCE(Wei Liu)
- call__pthread_get_minstack()with parameter
- add -ldl to correct make flags
- ensure to not using smaller stack size than today--- tools/xenstore/Makefile | 4 ++++ tools/xenstore/xs.c | 21 ++++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-)tools/xenstore/Makefile +4
-0@@ -100,6 +100,10 @@ libxenstore.so.$(MAJOR): libxenstore.so.$(MAJOR).$(MINOR) ln -sf $< $@ xs.opic: CFLAGS += -DUSE_PTHREAD +ifeq ($(CONFIG_Linux),y) +xs.opic: CFLAGS += -DUSE_DLSYM +libxenstore.so.$(MAJOR).$(MINOR): LDFLAGS += -ldl +endif libxenstore.so.$(MAJOR).$(MINOR): xs.opic xs_lib.opic $(CC) $(LDFLAGS) $(PTHREAD_LDFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,libxenstore.so.$(MAJOR) $(SHLIB_LDFLAGS) -o $@ $^ $(LDLIBS_libxentoolcore) $(SOCKET_LIBS) $(PTHREAD_LIBS) $(APPEND_LDFLAGS)tools/xenstore/xs.c +9
-0@@ -16,6 +16,8 @@License along with this library; If not, see <http://www.gnu.org/licenses/>. */ +#define _GNU_SOURCE +#include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> @@ -47,6 +49,10 @@ struct xs_stored_msg {#include <pthread.h> +#ifdef USE_DLSYM +#include <dlfcn.h> +#endif +struct xs_handle {/* Communications channel to xenstore daemon. */ int fd;@@ -810,12 +816,25 @@ bool xs_watch(struct xs_handle *h, const char *path, const char *token)if (!h->read_thr_exists) {sigset_t set, old_set;pthread_attr_t attr; +static size_t stack_size; +#ifdef USE_DLSYM +size_t (*getsz)(pthread_attr_t *attr);
tools/xenstore/xs.c bool xs_watch(struct xs_handle *h, const char *path, const char *token) · line 830
Quoted 10 lines
tools/xenstore/xs.c +4
-1+#endif if (pthread_attr_init (&attr) !=0 ) {mutex_unlock (&h->request_mutex);return false; } -if (pthread_attr_setstacksize (&attr,READ_THREAD_STACKSIZE ) !=0 ) { +if (!stack_size) { +#ifdef USE_DLSYM + getsz =dlsym (RTLD_DEFAULT ,"__pthread_get_minstack" );
dlsym is part of libc in FreeBSD, so it can be used but there's no ldl library (so passing -ldl to the linker is going to throw an error).
I guess it would be nice to have a configure test for this, but I'm not going to argue over it.
Roger.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 13 lines · Roger Pau Monné
tools/xenstore/xs.c bool xs_watch(struct xs_handle *h, const char *path, const char *token) · line 830
Quoted 9 lines
tools/xenstore/xs.c +3
-1if (pthread_attr_init (&attr) !=0 ) {mutex_unlock (&h->request_mutex);return false; } -if (pthread_attr_setstacksize (&attr,READ_THREAD_STACKSIZE ) !=0 ) { +if (!stack_size) { +#ifdef USE_DLSYM + getsz =dlsym (RTLD_DEFAULT ,"__pthread_get_minstack" );dlsym is part of libc in FreeBSD, so it can be used but there's no ldl library (so passing -ldl to the linker is going to throw an error).
Quoted 2 lines
I guess it would be nice to have a configure test for this, but I'm not going to argue over it.
I don't think FreeBSD needs this particular workaround for glibc FWIW.
Wei.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Wei Liu writes ("Re: [Xen-devel] [PATCH v2] tools/xenstore: try to get minimum thread stack size for watch thread"):
Quoted 1 line
I don't think FreeBSD needs this particular workaround for glibc FWIW.
Indeed.
Err, I guess we should have a configure test of some kind then ?
The patch looks good.
Ian.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 7 lines · Ian Jackson
Wei Liu writes ("Re: [Xen-devel] [PATCH v2]
tools/xenstore: try to get minimum thread stack size for watch thread"):Quoted 1 line
I don't think FreeBSD needs this particular workaround for glibc FWIW.
Indeed.
Err, I guess we should have a configure test of some kind then ?
It is already enclosed in CONFIG_Linux. I think that should be enough.
Wei.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Ian Jackson
Acked-byWei Liu writes ("Re: [Xen-devel] [PATCH v2] tools/xenstore: try to get minimum thread stack size for watch thread"):
Quoted 1 line
It is already enclosed in
CONFIG_Linux. I think that should be enough.
Oh, I see. I had read USE_DLSYM as CONFIG_DLSYM, ie "dlsym is available". A better name might be USE_DLSYM_MINSTACK_HACK but I'm happy with the patch as is.
I would like a test report from Jim, although the thread suggests that Jim's *actual* problem was something else so that might not be applicable.
Ian.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 10 lines · Juergen Gross
When creating a pthread in
xs_watch()try to get the minimal needed size of the thread from glibc instead of using a constant. This avoids problems when the library is used in programs with large per-thread memory.Use
dlsym()to get the pointer to__pthread_get_minstack()in order to avoid linkage problems and fall back to the current constant size if not found.Signed-off-by Juergen Gross <[email protected]>
I would like to give Jim a chance to test it before applying.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 26 lines · Juergen Gross
When creating a pthread in
xs_watch()try to get the minimal needed size of the thread from glibc instead of using a constant. This avoids problems when the library is used in programs with large per-thread memory.Use
dlsym()to get the pointer to__pthread_get_minstack()in order to avoid linkage problems and fall back to the current constant size if not found.Signed-off-by Juergen Gross <[email protected]>---
V2:
- use_GNU_SOURCE(Wei Liu)
- call__pthread_get_minstack()with parameter
- add -ldl to correct make flags
- ensure to not using smaller stack size than today--- tools/xenstore/Makefile | 4 ++++ tools/xenstore/xs.c | 21 ++++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-)tools/xenstore/Makefile +0
-0
tools/xenstore/Makefile libxenstore.so.$(MAJOR): libxenstore.so.$(MAJOR).$(MINOR) · line 106
Quoted 7 lines
tools/xenstore/Makefile +4
-0@@ -100,6 +100,10 @@ libxenstore.so.$(MAJOR): libxenstore.so.$(MAJOR).$(MINOR) ln -sf $< $@ xs.opic: CFLAGS += -DUSE_PTHREAD +ifeq ($(CONFIG_Linux),y) +xs.opic: CFLAGS += -DUSE_DLSYM +libxenstore.so.$(MAJOR).$(MINOR): LDFLAGS += -ldl +endif
Dropping this patch in one of my automated builds caused a libxenstore link failure
[ 99s] gcc -lsystemd -ldl -pthread -Wl,-soname -Wl,libxenstore.so.3.0 -shared -o libxenstore.so.3.0.3 xs.opic xs_lib.opic /home/abuild/rpmbuild/BUILD/xen-4.10.0-testing/tools/xenstore/../../tools/libs/toolcore/libxentoolcore.so
[ 99s] /home/abuild/rpmbuild/BUILD/xen-4.10.0-testing/tools/xenstore/../../tools/xenstore/libxenstore.so: undefined reference to `dlsym'
I hacked around it by appending '-ldl' to the end of the subsequent libxenstore.so rule.
Quoted 43 lines
tools/xenstore/Makefile +0
-0libxenstore.so.$(MAJOR).$(MINOR): xs.opic xs_lib.opic $(CC) $(LDFLAGS) $(PTHREAD_LDFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,libxenstore.so.$(MAJOR) $(SHLIB_LDFLAGS) -o $@ $^ $(LDLIBS_libxentoolcore) $(SOCKET_LIBS) $(PTHREAD_LIBS) $(APPEND_LDFLAGS)tools/xenstore/xs.c +13
-1@@ -16,6 +16,8 @@License along with this library; If not, see <http://www.gnu.org/licenses/>. */ +#define _GNU_SOURCE +#include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> @@ -47,6 +49,10 @@ struct xs_stored_msg {#include <pthread.h> +#ifdef USE_DLSYM +#include <dlfcn.h> +#endif +struct xs_handle {/* Communications channel to xenstore daemon. */ int fd;@@ -810,12 +816,25 @@ bool xs_watch(struct xs_handle *h, const char *path, const char *token)if (!h->read_thr_exists) {sigset_t set, old_set;pthread_attr_t attr; +static size_t stack_size; +#ifdef USE_DLSYM +size_t (*getsz)(pthread_attr_t *attr); +#endif if (pthread_attr_init (&attr) !=0 ) {mutex_unlock (&h->request_mutex);return false; } -if (pthread_attr_setstacksize (&attr,READ_THREAD_STACKSIZE ) !=0 ) { +if (!stack_size) { +#ifdef USE_DLSYM + getsz =dlsym (RTLD_DEFAULT ,"__pthread_get_minstack" );
tools/xenstore/xs.c bool xs_watch(struct xs_handle *h, const char *path, const char *token) · line 840
Quoted 10 lines
tools/xenstore/xs.c +7
-0+if (getsz) + stack_size =getsz (&attr); +#endif +if (stack_size <READ_THREAD_STACKSIZE ) + stack_size =READ_THREAD_STACKSIZE ; + } +if (pthread_attr_setstacksize (&attr, stack_size) !=0 ) {pthread_attr_destroy (&attr);mutex_unlock (&h->request_mutex);return false;
This worked fine, even on the system with the buggy glibc.
Regards,
Jim
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 36 lines · Jim Fehlig
Quoted 26 lines · Juergen Gross
When creating a pthread in
xs_watch()try to get the minimal needed size of the thread from glibc instead of using a constant. This avoids problems when the library is used in programs with large per-thread memory.Use
dlsym()to get the pointer to__pthread_get_minstack()in order to avoid linkage problems and fall back to the current constant size if not found.Signed-off-by Juergen Gross <[email protected]>---
V2:
- use_GNU_SOURCE(Wei Liu)
- call__pthread_get_minstack()with parameter
- add -ldl to correct make flags
- ensure to not using smaller stack size than today--- tools/xenstore/Makefile | 4 ++++ tools/xenstore/xs.c | 21 ++++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-)tools/xenstore/Makefile +0
-0tools/xenstore/Makefile libxenstore.so.$(MAJOR): libxenstore.so.$(MAJOR).$(MINOR) · line 105
Quoted 6 lines
tools/xenstore/Makefile +4
-0@@ -100,6 +100,10 @@ libxenstore.so.$(MAJOR): libxenstore.so.$(MAJOR).$(MINOR) ln -sf $< $@ xs.opic: CFLAGS += -DUSE_PTHREAD +ifeq ($(CONFIG_Linux),y) +xs.opic: CFLAGS += -DUSE_DLSYM +libxenstore.so.$(MAJOR).$(MINOR): LDFLAGS += -ldl +endifDropping this patch in one of my automated builds caused a libxenstore link failure
Quoted 8 lines
[ 99s] gcc -lsystemd -ldl -pthread -Wl,-soname -Wl,libxenstore.so.3.0
-shared -o libxenstore.so.3.0.3 xs.opic xs_lib.opic/home/abuild/rpmbuild/BUILD/xen-4.10.0-testing/tools/xenstore/../../tools/libs/toolcore/libxentoolcore.so[ 99s]
/home/abuild/rpmbuild/BUILD/xen-4.10.0-testing/tools/xenstore/../../tools/xenstore/libxenstore.so:
undefined reference to `dlsym'I hacked around it by appending '-ldl' to the end of the subsequent libxenstore.so rule.
Hmm... Maybe I'm a bit dense today. I know the position of -l matters but I don't quite understand how placing -pthread before xs.opic works but -ldl doesn't. xs.c uses both after all.
Wei.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 43 lines · Wei Liu
Quoted 42 lines · Jim Fehlig
Quoted 26 lines · Juergen Gross
When creating a pthread in
xs_watch()try to get the minimal needed size of the thread from glibc instead of using a constant. This avoids problems when the library is used in programs with large per-thread memory.Use
dlsym()to get the pointer to__pthread_get_minstack()in order to avoid linkage problems and fall back to the current constant size if not found.Signed-off-by Juergen Gross <[email protected]>---
V2:
- use_GNU_SOURCE(Wei Liu)
- call__pthread_get_minstack()with parameter
- add -ldl to correct make flags
- ensure to not using smaller stack size than today--- tools/xenstore/Makefile | 4 ++++ tools/xenstore/xs.c | 21 ++++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-)tools/xenstore/Makefile +0
-0tools/xenstore/Makefile libxenstore.so.$(MAJOR): libxenstore.so.$(MAJOR).$(MINOR) · line 105
Quoted 6 lines
tools/xenstore/Makefile +4
-0@@ -100,6 +100,10 @@ libxenstore.so.$(MAJOR): libxenstore.so.$(MAJOR).$(MINOR) ln -sf $< $@ xs.opic: CFLAGS += -DUSE_PTHREAD +ifeq ($(CONFIG_Linux),y) +xs.opic: CFLAGS += -DUSE_DLSYM +libxenstore.so.$(MAJOR).$(MINOR): LDFLAGS += -ldl +endifDropping this patch in one of my automated builds caused a libxenstore link failure
[ 99s] gcc -lsystemd -ldl -pthread -Wl,-soname -Wl,libxenstore.so.3.0
-shared -o libxenstore.so.3.0.3 xs.opic xs_lib.opic/home/abuild/rpmbuild/BUILD/xen-4.10.0-testing/tools/xenstore/../../tools/libs/toolcore/libxentoolcore.so[ 99s]
/home/abuild/rpmbuild/BUILD/xen-4.10.0-testing/tools/xenstore/../../tools/xenstore/libxenstore.so:
undefined reference to `dlsym'
Quoted 6 lines
Quoted 2 lines
I hacked around it by appending '-ldl' to the end of the subsequent libxenstore.so rule.
Hmm... Maybe I'm a bit dense today. I know the position of -l matters but I don't quite understand how placing -pthread before xs.opic works but -ldl doesn't.
xs.cuses both after all.
I'm indeed very dense -- -pthread is a special option that sets the proper flags for linking pthread library for both the preprocessor and linker.
But still, Juergen must have tested the change, so I wonder why it doesn't work in your setup. What is your build environment? Gcc version?
Wei.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 51 lines · Wei Liu
Quoted 43 lines · Wei Liu
Quoted 42 lines · Jim Fehlig
Quoted 26 lines · Juergen Gross
When creating a pthread in
xs_watch()try to get the minimal needed size of the thread from glibc instead of using a constant. This avoids problems when the library is used in programs with large per-thread memory.Use
dlsym()to get the pointer to__pthread_get_minstack()in order to avoid linkage problems and fall back to the current constant size if not found.Signed-off-by Juergen Gross <[email protected]>---
V2:
- use_GNU_SOURCE(Wei Liu)
- call__pthread_get_minstack()with parameter
- add -ldl to correct make flags
- ensure to not using smaller stack size than today--- tools/xenstore/Makefile | 4 ++++ tools/xenstore/xs.c | 21 ++++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-)tools/xenstore/Makefile +0
-0tools/xenstore/Makefile libxenstore.so.$(MAJOR): libxenstore.so.$(MAJOR).$(MINOR) · line 105
Quoted 6 lines
tools/xenstore/Makefile +4
-0@@ -100,6 +100,10 @@ libxenstore.so.$(MAJOR): libxenstore.so.$(MAJOR).$(MINOR) ln -sf $< $@ xs.opic: CFLAGS += -DUSE_PTHREAD +ifeq ($(CONFIG_Linux),y) +xs.opic: CFLAGS += -DUSE_DLSYM +libxenstore.so.$(MAJOR).$(MINOR): LDFLAGS += -ldl +endifDropping this patch in one of my automated builds caused a libxenstore link failure
[ 99s] gcc -lsystemd -ldl -pthread -Wl,-soname -Wl,libxenstore.so.3.0
-shared -o libxenstore.so.3.0.3 xs.opic xs_lib.opic/home/abuild/rpmbuild/BUILD/xen-4.10.0-testing/tools/xenstore/../../tools/libs/toolcore/libxentoolcore.so[ 99s]
/home/abuild/rpmbuild/BUILD/xen-4.10.0-testing/tools/xenstore/../../tools/xenstore/libxenstore.so:
undefined reference to `dlsym'Quoted 6 lines
Quoted 2 lines
I hacked around it by appending '-ldl' to the end of the subsequent libxenstore.so rule.
Hmm... Maybe I'm a bit dense today. I know the position of -l matters but I don't quite understand how placing -pthread before xs.opic works but -ldl doesn't.
xs.cuses both after all.
Quoted 6 lines
I'm indeed very dense -- -pthread is a special option that sets the proper flags for linking pthread library for both the preprocessor and linker.
But still, Juergen must have tested the change, so I wonder why it doesn't work in your setup. What is your build environment? Gcc version?
And why is "-lsystemd" working correctly?
I have tested with gcc 4.8.5, binutils 2.25.0
Juergen
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 52 lines · Juergen Gross
Quoted 51 lines · Wei Liu
Quoted 49 lines · Wei Liu
Quoted 36 lines · Jim Fehlig
Quoted 26 lines · Juergen Gross
When creating a pthread in
xs_watch()try to get the minimal needed size of the thread from glibc instead of using a constant. This avoids problems when the library is used in programs with large per-thread memory.Use
dlsym()to get the pointer to__pthread_get_minstack()in order to avoid linkage problems and fall back to the current constant size if not found.Signed-off-by Juergen Gross <[email protected]>---
V2:
- use_GNU_SOURCE(Wei Liu)
- call__pthread_get_minstack()with parameter
- add -ldl to correct make flags
- ensure to not using smaller stack size than today--- tools/xenstore/Makefile | 4 ++++ tools/xenstore/xs.c | 21 ++++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-)tools/xenstore/Makefile +0
-0tools/xenstore/Makefile libxenstore.so.$(MAJOR): libxenstore.so.$(MAJOR).$(MINOR) · line 105
Quoted 6 lines
tools/xenstore/Makefile +4
-0@@ -100,6 +100,10 @@ libxenstore.so.$(MAJOR): libxenstore.so.$(MAJOR).$(MINOR) ln -sf $< $@ xs.opic: CFLAGS += -DUSE_PTHREAD +ifeq ($(CONFIG_Linux),y) +xs.opic: CFLAGS += -DUSE_DLSYM +libxenstore.so.$(MAJOR).$(MINOR): LDFLAGS += -ldl +endifDropping this patch in one of my automated builds caused a libxenstore link failure
Quoted 8 lines
[ 99s] gcc -lsystemd -ldl -pthread -Wl,-soname -Wl,libxenstore.so.3.0
-shared -o libxenstore.so.3.0.3 xs.opic xs_lib.opic/home/abuild/rpmbuild/BUILD/xen-4.10.0-testing/tools/xenstore/../../tools/libs/toolcore/libxentoolcore.so[ 99s]
/home/abuild/rpmbuild/BUILD/xen-4.10.0-testing/tools/xenstore/../../tools/xenstore/libxenstore.so:
undefined reference to `dlsym'I hacked around it by appending '-ldl' to the end of the subsequent libxenstore.so rule.
Hmm... Maybe I'm a bit dense today. I know the position of -l matters but I don't quite understand how placing -pthread before xs.opic works but -ldl doesn't.
xs.cuses both after all.
Quoted 8 lines
Quoted 6 lines
I'm indeed very dense -- -pthread is a special option that sets the proper flags for linking pthread library for both the preprocessor and linker.
But still, Juergen must have tested the change, so I wonder why it doesn't work in your setup. What is your build environment? Gcc version?
And why is "-lsystemd" working correctly?
That's red-herring because libxenstore doesn't use systemd functions. The only place systemd is used is in xenstored_core.c -- calling sd_notify.
But we still need to figure out why -ldl works in your setup but not Jim's.
Wei.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 57 lines · Wei Liu
Quoted 56 lines · Juergen Gross
Quoted 55 lines · Wei Liu
Quoted 43 lines · Wei Liu
Quoted 42 lines · Jim Fehlig
Quoted 26 lines · Juergen Gross
When creating a pthread in
xs_watch()try to get the minimal needed size of the thread from glibc instead of using a constant. This avoids problems when the library is used in programs with large per-thread memory.Use
dlsym()to get the pointer to__pthread_get_minstack()in order to avoid linkage problems and fall back to the current constant size if not found.Signed-off-by Juergen Gross <[email protected]>---
V2:
- use_GNU_SOURCE(Wei Liu)
- call__pthread_get_minstack()with parameter
- add -ldl to correct make flags
- ensure to not using smaller stack size than today--- tools/xenstore/Makefile | 4 ++++ tools/xenstore/xs.c | 21 ++++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-)tools/xenstore/Makefile +0
-0tools/xenstore/Makefile libxenstore.so.$(MAJOR): libxenstore.so.$(MAJOR).$(MINOR) · line 105
Quoted 6 lines
tools/xenstore/Makefile +4
-0@@ -100,6 +100,10 @@ libxenstore.so.$(MAJOR): libxenstore.so.$(MAJOR).$(MINOR) ln -sf $< $@ xs.opic: CFLAGS += -DUSE_PTHREAD +ifeq ($(CONFIG_Linux),y) +xs.opic: CFLAGS += -DUSE_DLSYM +libxenstore.so.$(MAJOR).$(MINOR): LDFLAGS += -ldl +endifDropping this patch in one of my automated builds caused a libxenstore link failure
[ 99s] gcc -lsystemd -ldl -pthread -Wl,-soname -Wl,libxenstore.so.3.0
-shared -o libxenstore.so.3.0.3 xs.opic xs_lib.opic/home/abuild/rpmbuild/BUILD/xen-4.10.0-testing/tools/xenstore/../../tools/libs/toolcore/libxentoolcore.so[ 99s]
/home/abuild/rpmbuild/BUILD/xen-4.10.0-testing/tools/xenstore/../../tools/xenstore/libxenstore.so:
undefined reference to `dlsym'Quoted 6 lines
Quoted 2 lines
I hacked around it by appending '-ldl' to the end of the subsequent libxenstore.so rule.
Hmm... Maybe I'm a bit dense today. I know the position of -l matters but I don't quite understand how placing -pthread before xs.opic works but -ldl doesn't.
xs.cuses both after all.I'm indeed very dense -- -pthread is a special option that sets the proper flags for linking pthread library for both the preprocessor and linker.
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
But still, Juergen must have tested the change, so I wonder why it doesn't work in your setup. What is your build environment? Gcc version?
And why is "-lsystemd" working correctly?
That's red-herring because libxenstore doesn't use systemd functions. The only place systemd is used is in
xenstored_core.c-- callingsd_notify.
Nevertheless it is working:
# ldd /usr/lib64/libxenstore.so.3.0
linux-vdso.so.1 (0x00007ffdfcbc6000)
libsystemd.so.0 => /usr/lib64/libsystemd.so.0 (0x00007f1d054cb000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007f1d052c7000)
libxentoolcore.so.1 => /usr/lib64/libxentoolcore.so.1
(0x00007f1d050c5000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f1d04ea8000)
libc.so.6 => /lib64/libc.so.6 (0x00007f1d04b01000)
liblzma.so.5 => /usr/lib64/liblzma.so.5 (0x00007f1d048db000)
libgcrypt.so.20 => /usr/lib64/libgcrypt.so.20 (0x00007f1d045f5000)
librt.so.1 => /lib64/librt.so.1 (0x00007f1d043ed000)
libresolv.so.2 => /lib64/libresolv.so.2 (0x00007f1d041d6000)
/lib64/ld-linux-x86-64.so.2 (0x00007f1d05900000)
libgpg-error.so.0 => /usr/lib64/libgpg-error.so.0
(0x00007f1d03fd1000)Quoted 2 lines
But we still need to figure out why -ldl works in your setup but not Jim's.
I just rebuilt libxenstore.so and the xenstore clients. I've verified all components are installed from the new build and working properly.
So obviously there are some differences in tooling.
What about using SHLIB_LDFLAGS instead of LDFLAGS?
Juergen
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 51 lines · Wei Liu
Quoted 43 lines · Wei Liu
Quoted 42 lines · Jim Fehlig
Quoted 26 lines · Juergen Gross
When creating a pthread in
xs_watch()try to get the minimal needed size of the thread from glibc instead of using a constant. This avoids problems when the library is used in programs with large per-thread memory.Use
dlsym()to get the pointer to__pthread_get_minstack()in order to avoid linkage problems and fall back to the current constant size if not found.Signed-off-by Juergen Gross <[email protected]>---
V2:
- use_GNU_SOURCE(Wei Liu)
- call__pthread_get_minstack()with parameter
- add -ldl to correct make flags
- ensure to not using smaller stack size than today--- tools/xenstore/Makefile | 4 ++++ tools/xenstore/xs.c | 21 ++++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-)tools/xenstore/Makefile +0
-0tools/xenstore/Makefile libxenstore.so.$(MAJOR): libxenstore.so.$(MAJOR).$(MINOR) · line 105
Quoted 6 lines
tools/xenstore/Makefile +4
-0@@ -100,6 +100,10 @@ libxenstore.so.$(MAJOR): libxenstore.so.$(MAJOR).$(MINOR) ln -sf $< $@ xs.opic: CFLAGS += -DUSE_PTHREAD +ifeq ($(CONFIG_Linux),y) +xs.opic: CFLAGS += -DUSE_DLSYM +libxenstore.so.$(MAJOR).$(MINOR): LDFLAGS += -ldl +endifDropping this patch in one of my automated builds caused a libxenstore link failure
[ 99s] gcc -lsystemd -ldl -pthread -Wl,-soname -Wl,libxenstore.so.3.0
-shared -o libxenstore.so.3.0.3 xs.opic xs_lib.opic/home/abuild/rpmbuild/BUILD/xen-4.10.0-testing/tools/xenstore/../../tools/libs/toolcore/libxentoolcore.so[ 99s]
/home/abuild/rpmbuild/BUILD/xen-4.10.0-testing/tools/xenstore/../../tools/xenstore/libxenstore.so:
undefined reference to `dlsym'Quoted 6 lines
Quoted 2 lines
I hacked around it by appending '-ldl' to the end of the subsequent libxenstore.so rule.
Hmm... Maybe I'm a bit dense today. I know the position of -l matters but I don't quite understand how placing -pthread before xs.opic works but -ldl doesn't.
xs.cuses both after all.
Quoted 6 lines
I'm indeed very dense -- -pthread is a special option that sets the proper flags for linking pthread library for both the preprocessor and linker.
But still, Juergen must have tested the change, so I wonder why it doesn't work in your setup. What is your build environment? Gcc version?
I dropped the patch in a package build on the openSUSE build service, where gcc7 was used. But I don't see the problem when building from sources with gcc7. Apparently we have a bug in our package build, so ignore this comment. Tested-by still stands though :-).
Regards,
Jim
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 56 lines · Jim Fehlig
Quoted 55 lines · Wei Liu
Quoted 43 lines · Wei Liu
Quoted 42 lines · Jim Fehlig
Quoted 26 lines · Juergen Gross
When creating a pthread in
xs_watch()try to get the minimal needed size of the thread from glibc instead of using a constant. This avoids problems when the library is used in programs with large per-thread memory.Use
dlsym()to get the pointer to__pthread_get_minstack()in order to avoid linkage problems and fall back to the current constant size if not found.Signed-off-by Juergen Gross <[email protected]>---
V2:
- use_GNU_SOURCE(Wei Liu)
- call__pthread_get_minstack()with parameter
- add -ldl to correct make flags
- ensure to not using smaller stack size than today--- tools/xenstore/Makefile | 4 ++++ tools/xenstore/xs.c | 21 ++++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-)tools/xenstore/Makefile +0
-0tools/xenstore/Makefile libxenstore.so.$(MAJOR): libxenstore.so.$(MAJOR).$(MINOR) · line 105
Quoted 6 lines
tools/xenstore/Makefile +4
-0@@ -100,6 +100,10 @@ libxenstore.so.$(MAJOR): libxenstore.so.$(MAJOR).$(MINOR) ln -sf $< $@ xs.opic: CFLAGS += -DUSE_PTHREAD +ifeq ($(CONFIG_Linux),y) +xs.opic: CFLAGS += -DUSE_DLSYM +libxenstore.so.$(MAJOR).$(MINOR): LDFLAGS += -ldl +endifDropping this patch in one of my automated builds caused a libxenstore link failure
[ 99s] gcc -lsystemd -ldl -pthread -Wl,-soname -Wl,libxenstore.so.3.0
-shared -o libxenstore.so.3.0.3 xs.opic xs_lib.opic/home/abuild/rpmbuild/BUILD/xen-4.10.0-testing/tools/xenstore/../../tools/libs/toolcore/libxentoolcore.so[ 99s]
/home/abuild/rpmbuild/BUILD/xen-4.10.0-testing/tools/xenstore/../../tools/xenstore/libxenstore.so:
undefined reference to `dlsym'Quoted 6 lines
Quoted 2 lines
I hacked around it by appending '-ldl' to the end of the subsequent libxenstore.so rule.
Hmm... Maybe I'm a bit dense today. I know the position of -l matters but I don't quite understand how placing -pthread before xs.opic works but -ldl doesn't.
xs.cuses both after all.I'm indeed very dense -- -pthread is a special option that sets the proper flags for linking pthread library for both the preprocessor and linker.
Quoted 8 lines
Quoted 2 lines
But still, Juergen must have tested the change, so I wonder why it doesn't work in your setup. What is your build environment? Gcc version?
I dropped the patch in a package build on the openSUSE build service, where gcc7 was used. But I don't see the problem when building from sources with gcc7. Apparently we have a bug in our package build, so ignore this comment. Tested-by still stands though :-).
OK, thanks for the reply.
I will commit this patch soon.
Wei.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 2 lines · Wei Liu
But still, Juergen must have tested the change, so I wonder why it doesn't work in your setup. What is your build environment? Gcc version?
Unclear what the difference is between building in clean chroot and locally. This change fixes it for me:
tools/Rules.mk +3 -0
@@ -148,6 +148,9 @@ SHLIB_libxenguest = $(SHDEPS_libxenguest) -Wl,-rpath-link=$(XEN_LIBXC) CFLAGS_libxenstore = -I$(XEN_XENSTORE)/include $(CFLAGS_xeninclude) SHDEPS_libxenstore = $(SHLIB_libxentoolcore) LDLIBS_libxenstore = $(SHDEPS_libxenstore) $(XEN_XENSTORE)/libxenstore$(libextension) +ifeq ($(CONFIG_Linux),y) +LDLIBS_libxenstore += -ldl +endif SHLIB_libxenstore = $(SHDEPS_libxenstore) -Wl,-rpath-link=$(XEN_XENSTORE) CFLAGS_libxenstat = -I$(XEN_LIBXENSTAT)
tools/xenstore/Makefile +1 -0
@@ -103,6 +103,7 @@ xs.opic: CFLAGS += -DUSE_PTHREAD ifeq ($(CONFIG_Linux),y) xs.opic: CFLAGS += -DUSE_DLSYM libxenstore.so.$(MAJOR).$(MINOR): LDFLAGS += -ldl +LDLIBS_xenstored += -ldl endif libxenstore.so.$(MAJOR).$(MINOR): xs.opic xs_lib.opic
Olaf
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 11 lines · Olaf Hering
Quoted 2 lines · Wei Liu
But still, Juergen must have tested the change, so I wonder why it doesn't work in your setup. What is your build environment? Gcc version?
Unclear what the difference is between building in clean chroot and locally. This change fixes it for me:
tools/Rules.mk SHLIB_libxenguest = $(SHDEPS_libxenguest) -Wl,-rpath-link=$(XEN_LIBXC) · line 153
Quoted 6 lines
tools/Rules.mk +3
-0@@ -148,6 +148,9 @@ SHLIB_libxenguest = $(SHDEPS_libxenguest) -Wl,-rpath-link=$(XEN_LIBXC) CFLAGS_libxenstore = -I$(XEN_XENSTORE)/include $(CFLAGS_xeninclude) SHDEPS_libxenstore = $(SHLIB_libxentoolcore) LDLIBS_libxenstore = $(SHDEPS_libxenstore) $(XEN_XENSTORE)/libxenstore$(libextension) +ifeq ($(CONFIG_Linux),y) +LDLIBS_libxenstore += -ldl +endif
So we need to add this to xenstore.pc, right?
tools/xenstore/Makefile xs.opic: CFLAGS += -DUSE_PTHREAD · line 106
Quoted 10 lines
tools/Rules.mk +0
-0SHLIB_libxenstore = $(SHDEPS_libxenstore) -Wl,-rpath-link=$(XEN_XENSTORE) CFLAGS_libxenstat = -I$(XEN_LIBXENSTAT)tools/xenstore/Makefile +1
-0@@ -103,6 +103,7 @@ xs.opic: CFLAGS += -DUSE_PTHREAD ifeq ($(CONFIG_Linux),y) xs.opic: CFLAGS += -DUSE_DLSYM libxenstore.so.$(MAJOR).$(MINOR): LDFLAGS += -ldl +LDLIBS_xenstored += -ldl
Why is this needed? xenstored doesn't need libxenstore and (at least on my system) doesn't try to load it. The "-ldl" addition should only be needed for programs linked against libxenstore.
Juergen
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Juergen Gross writes ("Re: [Xen-devel] [PATCH v2] tools/xenstore: try to get minimum thread stack size for watch thread"):
Quoted 6 lines · Olaf Hering
tools/Rules.mk SHLIB_libxenguest = $(SHDEPS_libxenguest) -Wl,-rpath-link=$(XEN_LIBXC) · line 153
Quoted 3 lines
tools/Rules.mk +3
-0+ifeq ($(CONFIG_Linux),y) +LDLIBS_libxenstore += -ldl +endifSo we need to add this to xenstore.pc, right?
Yes.
Ian.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel