From efa6464e415038dd42a394d50275ebde9c3e71dc Mon Sep 17 00:00:00 2001 From: Daniel Kolesa Date: Fri, 8 Jan 2021 14:55:27 +0100 Subject: [PATCH 1/4] ppc, ppc64: do not use ALIAS for libucontext_swapcontext --- arch/ppc/swapcontext.S | 5 ++++- arch/ppc64/swapcontext.S | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/arch/ppc/swapcontext.S b/arch/ppc/swapcontext.S index 4f52a92..3d1efe0 100644 --- a/arch/ppc/swapcontext.S +++ b/arch/ppc/swapcontext.S @@ -14,7 +14,10 @@ ALIAS(swapcontext, __libucontext_swapcontext) ALIAS(__swapcontext, __libucontext_swapcontext) -ALIAS(libucontext_swapcontext, __libucontext_swapcontext) + +/* make sure this is visible regardless of EXPORT_UNPREFIXED */ +.weak libucontext_swapcontext +libucontext_swapcontext = __libucontext_swapcontext FUNC(__libucontext_swapcontext) li 0, 249 # SYS_swapcontext diff --git a/arch/ppc64/swapcontext.S b/arch/ppc64/swapcontext.S index f2ee6cc..facd491 100644 --- a/arch/ppc64/swapcontext.S +++ b/arch/ppc64/swapcontext.S @@ -14,7 +14,10 @@ ALIAS(swapcontext, __libucontext_swapcontext) ALIAS(__swapcontext, __libucontext_swapcontext) -ALIAS(libucontext_swapcontext, __libucontext_swapcontext) + +/* make sure this is visible regardless of EXPORT_UNPREFIXED */ +.weak libucontext_swapcontext +libucontext_swapcontext = __libucontext_swapcontext FUNC(__libucontext_swapcontext) addis 2, 12, .TOC.-__libucontext_swapcontext@ha From 739894e9a7feb1cec62ad547cc94e0174cf77c82 Mon Sep 17 00:00:00 2001 From: Daniel Kolesa Date: Fri, 8 Jan 2021 14:55:51 +0100 Subject: [PATCH 2/4] meson: fix build --- meson.build | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/meson.build b/meson.build index e72dfa3..e2a84e6 100644 --- a/meson.build +++ b/meson.build @@ -2,6 +2,7 @@ project( 'libucontext', 'c', meson_version : '>=0.55.0', + default_options: ['c_std=gnu99'], version : run_command('head', files('VERSION')).stdout() ) @@ -39,6 +40,10 @@ if cpu not in ['mips', 'mips64', 'ppc', 'ppc64', 's390x'] project_source_files += [ 'arch' / cpu / 'trampoline.c' ] +else + project_source_files += [ + 'arch' / cpu / 'startcontext.S' + ] endif project_includes = [ @@ -47,9 +52,7 @@ project_includes = [ ] build_args = [ - '-std=gnu99', '-D_BSD_SOURCE', - '-fPIC', '-DPIC' ] @@ -68,11 +71,9 @@ if freestanding build_args += '-DFREESTANDING' build_posix = false export_unprefixed = false - project_headers += ['arch' / cpu / 'include/libucontext/bits.h'] - project_includes += ['arch' / cpu / 'include'] + project_headers += ['arch' / cpu / 'freestanding/bits.h'] else - project_headers += ['arch/common/include/libucontext/bits.h'] - project_includes += ['arch/common/include'] + project_headers += ['arch/common/bits.h'] endif if export_unprefixed @@ -93,6 +94,7 @@ libucontext_target = both_libraries( version: meson.project_version(), install : not is_subproject, c_args : build_args, + pic: true, include_directories : headers, ) if is_subproject @@ -110,6 +112,7 @@ if build_posix version: meson.project_version(), install : not is_subproject, c_args : build_args, + pic: true, include_directories : headers, ) if is_subproject @@ -167,7 +170,7 @@ if not is_subproject executable( 'test_libucontext_posix', files('test_libucontext_posix.c'), - dependencies : libucontext_posix_dep, + dependencies : [libucontext_dep, libucontext_posix_dep], install : false ) ) From 4801f0bdd877f71b9978df244225835fca157723 Mon Sep 17 00:00:00 2001 From: Daniel Kolesa Date: Fri, 8 Jan 2021 15:07:08 +0100 Subject: [PATCH 3/4] all: mark the trampoline symbol hidden this should not be a part of the public ABI --- arch/common/common-trampoline.c | 1 + arch/mips/startcontext.S | 1 + arch/mips64/startcontext.S | 1 + arch/s390x/startcontext.S | 1 + 4 files changed, 4 insertions(+) diff --git a/arch/common/common-trampoline.c b/arch/common/common-trampoline.c index ada49f4..803121b 100644 --- a/arch/common/common-trampoline.c +++ b/arch/common/common-trampoline.c @@ -14,6 +14,7 @@ #include #include +__attribute__ ((visibility ("hidden"))) void libucontext_trampoline(void) { diff --git a/arch/mips/startcontext.S b/arch/mips/startcontext.S index 1a186b8..2ac79ec 100644 --- a/arch/mips/startcontext.S +++ b/arch/mips/startcontext.S @@ -14,6 +14,7 @@ LOCALSZ = 1 #include "defs.h" +.hidden libucontext_trampoline FUNC(libucontext_trampoline) move $gp, $s1 diff --git a/arch/mips64/startcontext.S b/arch/mips64/startcontext.S index 1f923ce..a960279 100644 --- a/arch/mips64/startcontext.S +++ b/arch/mips64/startcontext.S @@ -14,6 +14,7 @@ LOCALSZ = 1 #include "defs.h" +.hidden libucontext_trampoline FUNC(libucontext_trampoline) move $gp, $s1 diff --git a/arch/s390x/startcontext.S b/arch/s390x/startcontext.S index a1b2ce2..1656943 100644 --- a/arch/s390x/startcontext.S +++ b/arch/s390x/startcontext.S @@ -12,6 +12,7 @@ #include "defs.h" +.hidden libucontext_trampoline FUNC(libucontext_trampoline) basr %r14, %r7 /* run function pointer (%r7) and return here */ ltgr %r8, %r8 /* check to see if uc_link (%r8) is null */ From f3e0033a0697c2c38abb845115eb5a9a30b85cc5 Mon Sep 17 00:00:00 2001 From: Daniel Kolesa Date: Fri, 8 Jan 2021 15:51:55 +0100 Subject: [PATCH 4/4] meson: remove the subproject-based library checking this is not idiomatic, and should not be done (and it did not even work in the first place); meson is capable of building both libraries via library() and then you can choose on commandline it defaults to only shared, but we want both out of box, so specify that --- meson.build | 53 +++++++++++++++++++++-------------------------------- 1 file changed, 21 insertions(+), 32 deletions(-) diff --git a/meson.build b/meson.build index e2a84e6..7afa67b 100644 --- a/meson.build +++ b/meson.build @@ -2,7 +2,7 @@ project( 'libucontext', 'c', meson_version : '>=0.55.0', - default_options: ['c_std=gnu99'], + default_options: ['c_std=gnu99', 'default_library=both'], version : run_command('head', files('VERSION')).stdout() ) @@ -52,8 +52,7 @@ project_includes = [ ] build_args = [ - '-D_BSD_SOURCE', - '-DPIC' + '-D_BSD_SOURCE' ] @@ -85,39 +84,31 @@ endif # ====== headers = include_directories(project_includes) -is_subproject = meson.is_subproject() -# Build only static library if subproject -libucontext_target = both_libraries( +libucontext_target = library( 'ucontext', project_source_files, version: meson.project_version(), - install : not is_subproject, + install : not meson.is_subproject(), c_args : build_args, pic: true, include_directories : headers, ) -if is_subproject - libucontext_target = libucontext_target.get_static_lib() -endif libucontext_dep = declare_dependency( include_directories: headers, link_with : libucontext_target ) if build_posix - libucontext_posix_target = both_libraries( + libucontext_posix_target = library( 'ucontext_posix', project_source_files + ['libucontext_posix.c'], version: meson.project_version(), - install : not is_subproject, + install : not meson.is_subproject(), c_args : build_args, pic: true, include_directories : headers, ) - if is_subproject - libucontext_posix_target = libucontext_posix_target.get_static_lib() - endif libucontext_posix_dep = declare_dependency( include_directories: headers, link_with : libucontext_posix_target @@ -128,7 +119,7 @@ endif # Project # ======= -if not is_subproject +if not meson.is_subproject() # Make this library usable from the system's # package manager. install_headers(project_headers, subdir : meson.project_name()) @@ -148,7 +139,7 @@ endif # ==== # TODO: meson.build for docs -if not is_subproject +if not meson.is_subproject() #subdir('docs') endif @@ -156,23 +147,21 @@ endif # Unit Tests # ========== -if not is_subproject - test('test_libucontext', +test('test_libucontext', + executable( + 'test_libucontext', + files('test_libucontext.c'), + dependencies : libucontext_dep, + install : false + ) +) +if build_posix + test('test_libucontext_posix', executable( - 'test_libucontext', - files('test_libucontext.c'), - dependencies : libucontext_dep, + 'test_libucontext_posix', + files('test_libucontext_posix.c'), + dependencies : [libucontext_dep, libucontext_posix_dep], install : false ) ) - if build_posix - test('test_libucontext_posix', - executable( - 'test_libucontext_posix', - files('test_libucontext_posix.c'), - dependencies : [libucontext_dep, libucontext_posix_dep], - install : false - ) - ) - endif endif