Download raw body.
ctfconv nits
Hey, Martin, while looking at ctfconv, I've noticed some really
bizarre separate compilation nits.
Specifically: declaring the functions for elf.c and parse.c directly
into ctfconv.c means there is zero check that the actual declarations
match, which is not how it's done.
So I've written a small patch to adhere to usual style guidelines
for separate compilation.
While there, I've given the include guards some uniformized names,
to the notable exception of elf.h, since we have both the system
elf.h and ctfconv's elf.h, and using the same macro wouldn't work.
Patch follows.
Another question I have is, why the setlocale near line 85
of ctfconv. ? I would expect ctfconv to yield the exact same result
independently of the user locale. The default "C" locale is perfect
for that, so that setlocale line looks utterly bizarre, and potentially
dangerous if you ever need to use a locale-aware function.
Index: ctfconv.c
===================================================================
RCS file: /build/data/openbsd/cvs/src/usr.bin/ctfconv/ctfconv.c,v
diff -u -p -r1.20 ctfconv.c
--- ctfconv.c 2 Oct 2022 11:56:43 -0000 1.20
+++ ctfconv.c 29 May 2025 16:46:59 -0000
@@ -37,6 +37,8 @@
#include "itype.h"
#include "xmalloc.h"
+#include "elf.h"
+#include "parse.h"
#ifndef nitems
#define nitems(_a) (sizeof((_a)) / sizeof((_a)[0]))
@@ -57,18 +59,7 @@ void dump_type(struct itype *);
void dump_func(struct itype *, int *);
void dump_obj(struct itype *, int *);
-/* elf.c */
-int iself(const char *, size_t);
-int elf_getshstab(const char *, size_t, const char **, size_t *);
-ssize_t elf_getsymtab(const char *, size_t, const char *, size_t,
- const Elf_Sym **, size_t *, const char **, size_t *);
-ssize_t elf_getsection(char *, size_t, const char *, const char *,
- size_t, const char **, size_t *);
-/* parse.c */
-void dwarf_parse(const char *, size_t, const char *, size_t);
-
-const char *ctf_enc2name(unsigned short);
/* lists of parsed types and functions */
struct itype_queue itypeq = TAILQ_HEAD_INITIALIZER(itypeq);
Index: dwarf.h
===================================================================
RCS file: /build/data/openbsd/cvs/src/usr.bin/ctfconv/dwarf.h,v
diff -u -p -r1.3 dwarf.h
--- dwarf.h 21 Feb 2024 13:16:14 -0000 1.3
+++ dwarf.h 29 May 2025 16:49:22 -0000
@@ -973,4 +973,4 @@
#define DW_EH_PE_aligned 0x50
#define DW_EH_PE_omit 0xff
-#endif /* !_DWARF_H_ */
+#endif /* _DWARF_H_ */
Index: elf.c
===================================================================
RCS file: /build/data/openbsd/cvs/src/usr.bin/ctfconv/elf.c,v
diff -u -p -r1.10 elf.c
--- elf.c 14 Aug 2022 14:54:13 -0000 1.10
+++ elf.c 29 May 2025 16:47:23 -0000
@@ -24,6 +24,7 @@
#include <elf.h>
#include <err.h>
#include <string.h>
+#include "elf.h"
static int elf_reloc_size(unsigned long);
static void elf_reloc_apply(const char *, size_t, const char *, size_t,
Index: elf.h
===================================================================
RCS file: elf.h
diff -N elf.h
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ elf.h 29 May 2025 16:51:03 -0000
@@ -0,0 +1,28 @@
+/* $OpenBSD: ctfconv.c,v 1.20 2022/10/02 11:56:43 mpi Exp $ */
+
+/*
+ * Copyright (c) 2016-2017 Martin Pieuchot
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/* XXX different guard because of system include */
+#ifndef _UELF_H_
+#define _UELF_H_
+int iself(const char *, size_t);
+int elf_getshstab(const char *, size_t, const char **, size_t *);
+ssize_t elf_getsymtab(const char *, size_t, const char *, size_t,
+ const Elf_Sym **, size_t *, const char **, size_t *);
+ssize_t elf_getsection(char *, size_t, const char *, const char *,
+ size_t, const char **, size_t *);
+#endif /* _UELF_H_ */
Index: hash.h
===================================================================
RCS file: /build/data/openbsd/cvs/src/usr.bin/ctfconv/hash.h,v
diff -u -p -r1.2 hash.h
--- hash.h 11 Aug 2017 14:58:56 -0000 1.2
+++ hash.h 29 May 2025 16:50:03 -0000
@@ -16,6 +16,8 @@
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#ifndef _HASH_H_
+#define _HASH_H_
struct hash;
struct hash_entry {
@@ -30,3 +32,5 @@ void *hash_next(struct hash *, unsigned
struct hash_entry *hash_find(struct hash *, const char *, unsigned int *);
void *hash_remove(struct hash *, unsigned int);
void hash_insert(struct hash *, unsigned int, struct hash_entry *, const char *);
+
+#endif /* _HASH_H_ */
Index: itype.h
===================================================================
RCS file: /build/data/openbsd/cvs/src/usr.bin/ctfconv/itype.h,v
diff -u -p -r1.5 itype.h
--- itype.h 11 Nov 2019 19:10:35 -0000 1.5
+++ itype.h 29 May 2025 16:50:11 -0000
@@ -102,4 +102,4 @@ struct itype *it_dup(struct itype *);
const char *it_name(struct itype *);
const char *im_name(struct imember *);
-#endif /*_ITTYPE_H_ */
+#endif /* _ITTYPE_H_ */
Index: parse.c
===================================================================
RCS file: /build/data/openbsd/cvs/src/usr.bin/ctfconv/parse.c,v
diff -u -p -r1.20 parse.c
--- parse.c 22 Feb 2024 13:17:18 -0000 1.20
+++ parse.c 29 May 2025 16:47:34 -0000
@@ -37,6 +37,7 @@
#include "dwarf.h"
#include "dw.h"
#include "pool.h"
+#include "parse.h"
#ifdef DEBUG
#include <stdio.h>
Index: parse.h
===================================================================
RCS file: parse.h
diff -N parse.h
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ parse.h 29 May 2025 16:50:16 -0000
@@ -0,0 +1,23 @@
+/* $OpenBSD: ctfconv.c,v 1.20 2022/10/02 11:56:43 mpi Exp $ */
+
+/*
+ * Copyright (c) 2016-2017 Martin Pieuchot
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+#ifndef _PARSE_H_
+#define _PARSE_H_
+void dwarf_parse(const char *, size_t, const char *, size_t);
+
+const char *ctf_enc2name(unsigned short);
+#endif /* _PARSE_H_ */
Index: xmalloc.h
===================================================================
RCS file: /build/data/openbsd/cvs/src/usr.bin/ctfconv/xmalloc.h,v
diff -u -p -r1.1 xmalloc.h
--- xmalloc.h 11 Aug 2017 14:21:24 -0000 1.1
+++ xmalloc.h 29 May 2025 16:50:31 -0000
@@ -16,8 +16,8 @@
* called by a name other than "ssh" or "Secure Shell".
*/
-#ifndef XMALLOC_H
-#define XMALLOC_H
+#ifndef _XMALLOC_H
+#define _XMALLOC_H
void *xmalloc(size_t);
void *xcalloc(size_t, size_t);
@@ -25,4 +25,4 @@ void *xrealloc(void *, size_t);
void *xreallocarray(void *, size_t, size_t);
char *xstrdup(const char *);
-#endif /* XMALLOC_H */
+#endif /* _XMALLOC_H */
ctfconv nits