qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Christian Schoenebeck <qemu_oss@crudebyte.com>
To: qemu-devel@nongnu.org
Cc: Will Cohen <wwcohen@gmail.com>,
	Laurent Vivier <lvivier@redhat.com>,
	Thomas Huth <thuth@redhat.com>, Greg Kurz <groug@kaod.org>,
	hi@alyssa.is, Michael Roitzsch <reactorcontrol@icloud.com>,
	Akihiko Odaki <akihiko.odaki@gmail.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Keno Fischer <keno@juliacomputing.com>
Subject: Re: [PATCH v5 09/11] 9p: darwin: Implement compatibility for mknodat
Date: Wed, 09 Feb 2022 14:50:53 +0100	[thread overview]
Message-ID: <2916980.GZRxgfQXSf@silver> (raw)
In-Reply-To: <CAB26zV1VMZOjyn1h3fLd7N0rGWxLihv3tJDtRYn3P7muO-ehiw@mail.gmail.com>

On Dienstag, 8. Februar 2022 23:57:32 CET Will Cohen wrote:
> > On a second thought: this case a bit special. Are we worried that
> > pthread_fchdir_np() is "not yet" available on macOS, or "no longer"
> > available.
> > Probably both, right?
> > 
> > So maybe it would make sense to replace the API_AVAILABLE() attribute
> > directly
> > with a __attribute__((weak)) attribute. Then the runtime check with the
> > proposed error message would also trigger if a bleeding edge macOS version
> > no
> > longer has pthread_fchdir_np().
> > 
> > Also keep in mind: there are always also the MAC_OS_X_VERSION_MIN_REQUIRED
> > and
> > MAC_OS_X_VERSION_MAX_ALLOWED macros to query the deployment target at
> > compile
> > time to wrap deployment target dependent code accordingly.
> > 
> > On doubt you could just make some tests there by simply "inventing" a non-
> > existent function.
> > 
> > Best regards,
> > Christian Schoenebeck
> 
> I like the idea of switching it to __attribute__((weak)). I should note
> that I'm not sure that I can actually fully test this out since I'm getting
> stuck with the linker noting my undefined fake function during the build,
> but the idea does make logical sense to me for the future fail case and the
> happy case builds again when implemented with actual pthread_fchdir_np:
> 
> [1075/2909] Linking target qemu-nbd
> FAILED: qemu-nbd
> cc -m64 -mcx16  -o qemu-nbd qemu-nbd.p/qemu-nbd.c.o -Wl,-dead_strip_dylibs
> -Wl,-headerpad_max_install_names -Wl,-undefined,error -Wl,-force_load
> libblockdev.fa -Wl,-force_load libblock.fa -Wl,-force_load libcrypto.fa
> -Wl,-force_load libauthz.fa -Wl,-force_load libqom.fa -Wl,-force_load
> libio.fa -fstack-protector-strong
> -Wl,-rpath,/usr/local/Cellar/gnutls/3.7.3/lib
> -Wl,-rpath,/usr/local/Cellar/pixman/0.40.0/lib libqemuutil.a libblockdev.fa
> libblock.fa libcrypto.fa libauthz.fa libqom.fa libio.fa @block.syms
> /usr/local/Cellar/gnutls/3.7.3/lib/libgnutls.dylib -lutil
> -L/usr/local/Cellar/glib/2.70.3/lib -L/usr/local/opt/gettext/lib -lgio-2.0
> -lgobject-2.0 -lglib-2.0 -lintl -L/usr/local/Cellar/glib/2.70.3/lib
> -L/usr/local/opt/gettext/lib -lgio-2.0 -lgobject-2.0 -lglib-2.0 -lintl -lm
> -L/usr/local/Cellar/glib/2.70.3/lib -L/usr/local/opt/gettext/lib
> -lgmodule-2.0 -lglib-2.0 -lintl
> /usr/local/Cellar/pixman/0.40.0/lib/libpixman-1.dylib -lz -lxml2 -framework
> CoreFoundation -framework IOKit -lcurl -L/usr/local/Cellar/glib/2.70.3/lib
> -L/usr/local/opt/gettext/lib -lgmodule-2.0 -lglib-2.0 -lintl -lbz2
> /usr/local/Cellar/libssh/0.9.6/lib/libssh.dylib -lpam
> Undefined symbols for architecture x86_64:
>   "_pthread_fchdir_npfoo", referenced from:
>       _qemu_mknodat in libblockdev.fa(os-posix.c.o)
> ld: symbol(s) not found for architecture x86_64
> clang: error: linker command failed with exit code 1 (use -v to see

Even when "weak" linking, the respective symbol must still at least exist at 
compile time. To make this more clear, the following test works for me:

$ cat a.c
#include <stdio.h>

void aaa(void) {
    printf("aaa\n");
}
$ cat ab.c
#include <stdio.h>

void aaa(void) {
    printf("aaa\n");
}

void bbb(void) {
    printf("bbb\n");
}
$ cat main.c
#include <stdio.h>

void aaa(void);
void bbb(void) __attribute__((weak));

int main() {
    aaa();
    if (bbb)
        bbb();
    else
        printf("bbb() not supported\n");
    return 0;
}
$ clang -dynamiclib ab.c -o foo.1.dylib
$ clang main.c -o weaktest foo.1.dylib
$ ./weaktest
aaa
bbb
$ clang -dynamiclib a.c -o foo.1.dylib
$ ./weaktest
aaa
bbb() not supported
$

> With that caveat re testing in mind, unless there's another recommended
> path forward, I think it makes sense to stick with __attribute__((weak))
> and prepare v6 which incorporates this and all the other feedback from this
> round.

Just make this clear with an appropriate comment why it is weakly linked: to 
guard that function pthread_fchdir_np might simply disappear in future macOS 
versions, as it is simply a private API.

Best regards,
Christian Schoenebeck




  parent reply	other threads:[~2022-02-09 14:54 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-07 22:40 [PATCH v5 00/11] 9p: Add support for darwin Will Cohen
2022-02-07 22:40 ` [PATCH v5 01/11] 9p: linux: Fix a couple Linux assumptions Will Cohen
2022-02-07 22:40 ` [PATCH v5 02/11] 9p: Rename 9p-util -> 9p-util-linux Will Cohen
2022-02-07 22:40 ` [PATCH v5 03/11] 9p: darwin: Handle struct stat(fs) differences Will Cohen
2022-02-07 22:40 ` [PATCH v5 04/11] 9p: darwin: Handle struct dirent differences Will Cohen
2022-02-07 22:40 ` [PATCH v5 05/11] 9p: darwin: Ignore O_{NOATIME, DIRECT} Will Cohen
2022-02-07 22:40 ` [PATCH v5 06/11] 9p: darwin: Move XATTR_SIZE_MAX->P9_XATTR_SIZE_MAX Will Cohen
2022-02-08 12:20   ` Christian Schoenebeck
2022-02-08 13:45     ` Will Cohen
2022-02-07 22:40 ` [PATCH v5 07/11] 9p: darwin: *xattr_nofollow implementations Will Cohen
2022-02-07 22:40 ` [PATCH v5 08/11] 9p: darwin: Compatibility for f/l*xattr Will Cohen
2022-02-07 22:40 ` [PATCH v5 09/11] 9p: darwin: Implement compatibility for mknodat Will Cohen
2022-02-07 22:56   ` Christian Schoenebeck
2022-02-08 13:36     ` Will Cohen
2022-02-08 15:02       ` Christian Schoenebeck
2022-02-08 15:57         ` Will Cohen
2022-02-08 16:11           ` Christian Schoenebeck
2022-02-08 16:19             ` Will Cohen
2022-02-08 18:04               ` Will Cohen
2022-02-08 18:28                 ` Christian Schoenebeck
2022-02-08 19:48                   ` Christian Schoenebeck
2022-02-08 22:57                     ` Will Cohen
2022-02-09 13:33                       ` Akihiko Odaki
2022-02-09 14:08                         ` Christian Schoenebeck
2022-02-09 18:20                           ` Will Cohen
2022-02-09 23:10                             ` Akihiko Odaki
2022-02-10 15:46                               ` Will Cohen
2022-02-09 13:50                       ` Christian Schoenebeck [this message]
2022-02-08 10:55   ` Philippe Mathieu-Daudé via
2022-02-07 22:40 ` [PATCH v5 10/11] 9p: darwin: meson: Allow VirtFS on Darwin Will Cohen
2022-02-07 23:44   ` Christian Schoenebeck
2022-02-07 23:47     ` Will Cohen
2022-02-07 22:40 ` [PATCH v5 11/11] 9p: darwin: Adjust assumption on virtio-9p-test Will Cohen
2022-02-08 10:16   ` Greg Kurz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2916980.GZRxgfQXSf@silver \
    --to=qemu_oss@crudebyte.com \
    --cc=akihiko.odaki@gmail.com \
    --cc=groug@kaod.org \
    --cc=hi@alyssa.is \
    --cc=keno@juliacomputing.com \
    --cc=lvivier@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=reactorcontrol@icloud.com \
    --cc=thuth@redhat.com \
    --cc=wwcohen@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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 NNTP newsgroup(s).