From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.1 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 26091 invoked from network); 6 Jul 2023 10:48:42 -0000 Received: from second.openwall.net (193.110.157.125) by inbox.vuxu.org with ESMTPUTF8; 6 Jul 2023 10:48:42 -0000 Received: (qmail 13559 invoked by uid 550); 6 Jul 2023 10:48:37 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 13527 invoked from network); 6 Jul 2023 10:48:37 -0000 X-Proofpoint-ORIG-GUID: UzoPEyXwJFy_BqA4xnLHjfvxfSvdVYeg X-Proofpoint-GUID: UzoPEyXwJFy_BqA4xnLHjfvxfSvdVYeg X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.591,18.0.957 definitions=2023-07-06_06:2023-07-06,2023-07-06 signatures=0 X-Proofpoint-Spam-Details: rule=interactive_user_notspam policy=interactive_user score=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 adultscore=0 malwarescore=0 mlxscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2307060095 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=apple.com; h=from : content-type : mime-version : date : subject : message-id : to; s=20180706; bh=4Lnqf+fKhKjR0gOgbSFp1FQm6SFxbqAm3eN6VBy8S04=; b=wsfF4S+xTF01AnIuDYidTCzXHsFN/JyojYlIJMg8HRvUavTtoXrRCBssHEhCsR4lq2tw oIw/g/6/nRY65SjmPoIwS3QTEGxOQZjk9DiyqSVqg8FP0vl4CqWUgr97qKaKdqAIAKsi oaSwdSCDGL5+fzBYD4i8HhjjM/RrPVx7vohCvDYvEL4ZIEnazohVYL1T1NycoFTOSUN+ pGLYBnQSibDG9TjB079FvuSTSBkr4IGccskICXdnlI2n7hGPr46892kawixH/guQLzIi 3UbIWQUeWFerk/x8+8OX1zzYWZVFv6eZcE8cPb409t9QVsH9yS0xq9GU3IwQpMbgKUvk Dw== X-Va-A: X-Va-T-CD: 14dc138f66d48087821ca031f1b11e6a X-Va-E-CD: cd7d2058a820f570bdb37ab0bf40afcb X-Va-R-CD: 34c572957dd7f6c48ceaa5caa1322ca7 X-Va-ID: bdef7d2d-2083-4596-894c-29eb4818cf59 X-Va-CD: 0 X-V-A: X-V-T-CD: 14dc138f66d48087821ca031f1b11e6a X-V-E-CD: cd7d2058a820f570bdb37ab0bf40afcb X-V-R-CD: 34c572957dd7f6c48ceaa5caa1322ca7 X-V-ID: baefbf5c-dfd6-4392-9cfd-347c231c613c X-V-CD: 0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.591,18.0.957 definitions=2023-07-06_06:2023-07-06,2023-07-06 signatures=0 Authentication-results: corp.apple.com; spf=softfail smtp.mailfrom=ahoughton@apple.com; dmarc=quarantine header.from=apple.com From: Alastair Houghton Content-type: multipart/mixed; boundary="Apple-Mail=_5CF852AE-EF90-490B-9F03-EA999FCF993D" MIME-version: 1.0 (Mac OS X Mail 16.0 \(3767.100.2\)) Date: Thu, 06 Jul 2023 11:48:04 +0100 Message-id: <309EDCC9-2402-46B5-BDBD-B96677E470DD@apple.com> To: musl@lists.openwall.com X-Mailer: Apple Mail (2.3767.100.2) Subject: [musl] __MUSL__ macro --Apple-Mail=_5CF852AE-EF90-490B-9F03-EA999FCF993D Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 Hi all, Before I start, I=E2=80=99m aware of but I *still* want to add __MUSL__ (see attached patch). Let me explain what we=E2=80=99re doing, why we want it and why we think = musl *should* have it. We=E2=80=99re trying to add support for musl to = Swift > and its attendant = core libraries, and there are a number of things about musl that = presently differ from other platforms/C libraries we support. Examples include the use of `union`s in `pthread_mutex_t` et al (which = means that we can=E2=80=99t write a C++ `constexpr` function that = returns one, even if all it does is return `PTHREAD_MUTEX_INITIALIZER`), = the fact that it doesn=E2=80=99t have the `d_namlen` member of `struct = dirent`, or the fact that `dladdr()` is a no-op when statically linked. I=E2=80=99m aware that there are other solutions for some of these cases = - but for instance the `dladdr()` issue is not something you can test at = configuration time when cross-compiling, since there=E2=80=99s no way to = know what the result would be without running a program on the target = system (which you don=E2=80=99t necessarily have available at = configuration time in that case). Likewise, configuration time tests = are slow and aren=E2=80=99t even a thing in some of the projects we = need to add support in, whereas we do generally have the ability to use = the preprocessor. You might say we should just bite the bullet and add configuration steps = to all of the other projects, but that is honestly a non-starter; the = owners of those projects are not likely to accept patches to add such a = thing, even as a short-term fix, and the patches to do so would be = non-trivial in a number of cases also. In the longer term we don=E2=80=99= t want higher level projects to need to do this kind of thing and the = lower level ones could in many cases do some kind of configuration time = testing, but that=E2=80=99s a longer term goal and it doesn=E2=80=99t = help us to add musl support in the interim, which we would like to do. I=E2=80=99ve attached a proposed patch that adds `__MUSL__` (set to the = major version) and `__MUSL_MINOR__` (set to the minor version) as well = as `__MUSL_PREREQ()` (which works the same way `__GLIBC_PREREQ()` does). Kind regards, Alastair Houghton --Apple-Mail=_5CF852AE-EF90-490B-9F03-EA999FCF993D Content-Disposition: attachment; filename=musl-version.patch Content-Type: application/octet-stream; x-unix-mode=0644; name="musl-version.patch" Content-Transfer-Encoding: 7bit diff --git a/Makefile b/Makefile index e8cc4436..ea91b9be 100644 --- a/Makefile +++ b/Makefile @@ -34,7 +34,7 @@ CRT_OBJS = $(filter obj/crt/%,$(ALL_OBJS)) AOBJS = $(LIBC_OBJS) LOBJS = $(LIBC_OBJS:.o=.lo) -GENH = obj/include/bits/alltypes.h obj/include/bits/syscall.h +GENH = obj/include/bits/alltypes.h obj/include/bits/syscall.h obj/include/features.h GENH_INT = obj/src/internal/version.h IMPH = $(addprefix $(srcdir)/, src/internal/stdio_impl.h src/internal/pthread_impl.h src/internal/locale_impl.h src/internal/libc.h) @@ -95,6 +95,17 @@ $(ALL_LIBS) $(ALL_TOOLS) $(ALL_OBJS) $(ALL_OBJS:%.o=%.lo) $(GENH) $(GENH_INT): | $(OBJ_DIRS): mkdir -p $@ +MUSL_VERSION:=$(shell cd $(srcdir) && sh tools/version.sh) +empty:= +space:=$(empty) $(empty) +musl_ver_parts:=$(subst -git-,$(space),$(subst .,$(space),$(MUSL_VERSION))) +MUSL_MAJOR:=$(word 1, $(musl_ver_parts)) +MUSL_MINOR:=$(word 2, $(musl_ver_parts)) +MUSL_PATCH:=$(word 3, $(musl_ver_parts)) + +obj/include/features.h: $(srcdir)/include/features.h.in $(wildcard $(srcdir)/VERSION $(srcdir)/.git) + sed -e "s/@MUSL_MAJOR@/$(MUSL_MAJOR)/g;s/@MUSL_MINOR@/$(MUSL_MINOR)/g;s/@MUSL_PATCH@/$(MUSL_PATCH)/g" $< > $@ + obj/include/bits/alltypes.h: $(srcdir)/arch/$(ARCH)/bits/alltypes.h.in $(srcdir)/include/alltypes.h.in $(srcdir)/tools/mkalltypes.sed sed -f $(srcdir)/tools/mkalltypes.sed $(srcdir)/arch/$(ARCH)/bits/alltypes.h.in $(srcdir)/include/alltypes.h.in > $@ @@ -103,7 +114,7 @@ obj/include/bits/syscall.h: $(srcdir)/arch/$(ARCH)/bits/syscall.h.in sed -n -e s/__NR_/SYS_/p < $< >> $@ obj/src/internal/version.h: $(wildcard $(srcdir)/VERSION $(srcdir)/.git) - printf '#define VERSION "%s"\n' "$$(cd $(srcdir); sh tools/version.sh)" > $@ + printf '#define VERSION "%s"\n' "$(MUSL_VERSION)" > $@ obj/src/internal/version.o obj/src/internal/version.lo: obj/src/internal/version.h @@ -209,6 +220,9 @@ $(DESTDIR)$(includedir)/bits/%: obj/include/bits/% $(DESTDIR)$(includedir)/%: $(srcdir)/include/% $(INSTALL) -D -m 644 $< $@ +$(DESTDIR)$(includedir)/%: obj/include/% + $(INSTALL) -D -m 644 $< $@ + $(DESTDIR)$(LDSO_PATHNAME): $(DESTDIR)$(libdir)/libc.so $(INSTALL) -D -l $(libdir)/libc.so $@ || true diff --git a/include/features.h b/include/features.h.in similarity index 80% rename from include/features.h rename to include/features.h.in index 85cfb72a..07662804 100644 --- a/include/features.h +++ b/include/features.h.in @@ -1,6 +1,13 @@ #ifndef _FEATURES_H #define _FEATURES_H +#define __MUSL__ @MUSL_MAJOR@ +#define __MUSL_MINOR__ @MUSL_MINOR@ +#define __MUSL_PATCH__ @MUSL_PATCH@ + +#define __MUSL_PREREQ(maj, min) \ + ((__MUSL__ << 16) + __MUSL_MINOR >= ((maj) << 16) + (min)) + #if defined(_ALL_SOURCE) && !defined(_GNU_SOURCE) #define _GNU_SOURCE 1 #endif --Apple-Mail=_5CF852AE-EF90-490B-9F03-EA999FCF993D--