git: 096a5c6cd28c - main - libdtrace: Generalize handling of data models a bit

From: Mark Johnston <markj_at_FreeBSD.org>
Date: Sat, 25 Jan 2025 16:02:59 UTC
The branch main has been updated by markj:

URL: https://cgit.FreeBSD.org/src/commit/?id=096a5c6cd28c417456d5ce3598be15e6b656af5c

commit 096a5c6cd28c417456d5ce3598be15e6b656af5c
Author:     Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2025-01-25 15:57:37 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2025-01-25 16:02:41 +0000

    libdtrace: Generalize handling of data models a bit
    
    Make it easier to support data models other than ILP32 and LP64 by
    avoiding constructs which assume that it must be one or the other.
    
    No functional change intended.
    
    MFC after:      2 weeks
    Sponsored by:   Innovate UK
---
 cddl/contrib/opensolaris/cmd/dtrace/dtrace.c            | 7 +++----
 cddl/contrib/opensolaris/lib/libdtrace/common/dt_open.c | 8 +++++++-
 cddl/contrib/opensolaris/lib/libdtrace/common/dtrace.h  | 1 +
 3 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/cddl/contrib/opensolaris/cmd/dtrace/dtrace.c b/cddl/contrib/opensolaris/cmd/dtrace/dtrace.c
index dc68c6ef5f72..162224478ec0 100644
--- a/cddl/contrib/opensolaris/cmd/dtrace/dtrace.c
+++ b/cddl/contrib/opensolaris/cmd/dtrace/dtrace.c
@@ -1378,7 +1378,7 @@ main(int argc, char *argv[])
 					    argv[0], optarg);
 					return (usage(stderr));
 				}
-				g_oflags &= ~DTRACE_O_LP64;
+				g_oflags &= ~DTRACE_O_MODEL_MASK;
 				g_oflags |= DTRACE_O_ILP32;
 				break;
 
@@ -1389,7 +1389,7 @@ main(int argc, char *argv[])
 					    argv[0], optarg);
 					return (usage(stderr));
 				}
-				g_oflags &= ~DTRACE_O_ILP32;
+				g_oflags &= ~DTRACE_O_MODEL_MASK;
 				g_oflags |= DTRACE_O_LP64;
 				break;
 
@@ -1460,8 +1460,7 @@ main(int argc, char *argv[])
 	 * files. We ignore certain errors since we'll catch them later when
 	 * we actually process the object files.
 	 */
-	if (g_mode == DMODE_LINK &&
-	    (g_oflags & (DTRACE_O_ILP32 | DTRACE_O_LP64)) == 0 &&
+	if (g_mode == DMODE_LINK && (g_oflags & DTRACE_O_MODEL_MASK) == 0 &&
 	    elf_version(EV_CURRENT) != EV_NONE) {
 		int fd;
 		Elf *elf;
diff --git a/cddl/contrib/opensolaris/lib/libdtrace/common/dt_open.c b/cddl/contrib/opensolaris/lib/libdtrace/common/dt_open.c
index 8f8d20298e4c..40200771fd4d 100644
--- a/cddl/contrib/opensolaris/lib/libdtrace/common/dt_open.c
+++ b/cddl/contrib/opensolaris/lib/libdtrace/common/dt_open.c
@@ -1073,8 +1073,14 @@ dt_vopen(int version, int flags, int *errp,
 	if (flags & ~DTRACE_O_MASK)
 		return (set_open_errno(dtp, errp, EINVAL));
 
-	if ((flags & DTRACE_O_LP64) && (flags & DTRACE_O_ILP32))
+	switch (flags & DTRACE_O_MODEL_MASK) {
+	case 0: /* native model */
+	case DTRACE_O_ILP32:
+	case DTRACE_O_LP64:
+		break;
+	default:
 		return (set_open_errno(dtp, errp, EINVAL));
+	}
 
 	if (vector == NULL && arg != NULL)
 		return (set_open_errno(dtp, errp, EINVAL));
diff --git a/cddl/contrib/opensolaris/lib/libdtrace/common/dtrace.h b/cddl/contrib/opensolaris/lib/libdtrace/common/dtrace.h
index b380f5eb3313..1f4c5a2efd6b 100644
--- a/cddl/contrib/opensolaris/lib/libdtrace/common/dtrace.h
+++ b/cddl/contrib/opensolaris/lib/libdtrace/common/dtrace.h
@@ -70,6 +70,7 @@ typedef struct dtrace_aggdata dtrace_aggdata_t;
 #define	DTRACE_O_NOSYS		0x02	/* do not load /system/object modules */
 #define	DTRACE_O_LP64		0x04	/* force D compiler to be LP64 */
 #define	DTRACE_O_ILP32		0x08	/* force D compiler to be ILP32 */
+#define	DTRACE_O_MODEL_MASK	(DTRACE_O_LP64 | DTRACE_O_ILP32)
 #define	DTRACE_O_MASK		0x0f	/* mask of valid flags to dtrace_open */
 
 extern dtrace_hdl_t *dtrace_open(int, int, int *);