On Tue, 4 Jul 2017 11:48:27 +0200
Martin Pieuchot <[email protected]> wrote:

> Hello,
>
> I think that moving towards <elf.h> is a good thing.  However are you
> sure that <sys/exec_elf.h> provides all the definitions required by
> <elf.h>?

Not yet. At least a lot of machine related definitions are missing, but they 
are not required if neither base nor ports need them. In patch below I'm adding 
just EM_PPC64 which I know is needed and worked around by GHC. I'm also killing 
comment as I've verified those or fixed/removed those not in correct way 
alligned with spec.

> Are you sure it doesn't provide any other definition that
> would make code written on OpenBSD non portable?

PT_OPENBSD_* and NT_OPENBSD_* are there. The first I moved to ifdef 
ELF_OPENBSD_EXTENSION. The second is used only by kernel hence _KERNEL. 
Otherwise a lot of <type>_DEFINED_ from sys/types.h leak in, but the question 
is if this hurts or not.

> What would it take to convert base programs to <elf.h>?

Base is quite clean except few exceptions. I used ELF_OPENBSD_EXTENSION for 
those. Anyway, both toolchains (bintils+gcc/llvm+clang) seem to live their own 
ELF lifes without even attempting to include system elf.h/elf_abi.h so they are 
clean and not touched.

> If base starts to provide <elf.h> you also need to make sure it doesn't
> break any port.

Both elf.h/elf_abi.h so far points to the exactly same definitions, hence if 
there is port which is broken, then it'll be broken at compile time. Quite 
easily discoverable by building all ports. Not yet done on my side though.

> I would welcome such move since it would make easier to port programs
> from OpenBSD to other platforms.  However it's not as easy as including
> a header in another.  Are you ready to tackle the above mentioned
> issues?

Don't know about complexity of this. Anyway, below is another step which fixes 
machine definition (obvious issues), adds mentioned EM_PPC64 and _KERNEL ifdefs 
NT_OPENBSD and also uses ELF_OPENBSD_EXTENSION to filter out PT_OPENBSD. 
However later is questionable since PT_GNU is there without any #ifdef. So I 
can see several ways how to improve on this. For example:

- move #define ELF_OPENBSD_EXTENSION to elf_abi.h and remove from base 
progs/libs. This way elf.h will be portable and elf_abi.h OBSD specific with an 
option to rename to elf_obsd.h or so in the future.
- if you don't like ELF_OPENBSD_EXTENSION I'm free to rename to whatever is 
preferred.
- if you don't like ELF_OBSD_EXT at all and prefer separate file then I'll need 
to proceed with way described above with differenting elf.h and elf_abi.h -- or 
so.

Comments welcome! Thanks,

Karel

diff --git a/sys/arch/amd64/stand/libsa/elf32.c 
b/sys/arch/amd64/stand/libsa/elf32.c
index f943067411c..896cd68bcb0 100644
--- a/sys/arch/amd64/stand/libsa/elf32.c
+++ b/sys/arch/amd64/stand/libsa/elf32.c
@@ -27,6 +27,8 @@
 #undef ELFSIZE
 #define ELFSIZE  32
 
+#define ELF_OPENBSD_EXTENSION
 #include <sys/exec_elf.h>
+#undef ELF_OPENBSD_EXTENSION
 
 #include "../../../../lib/libsa/loadfile_elf.c"
diff --git a/sys/arch/amd64/stand/libsa/elf64.c 
b/sys/arch/amd64/stand/libsa/elf64.c
index d7d11c843c4..49bdaa62fed 100644
--- a/sys/arch/amd64/stand/libsa/elf64.c
+++ b/sys/arch/amd64/stand/libsa/elf64.c
@@ -27,6 +27,8 @@
 #undef ELFSIZE
 #define ELFSIZE  64
 
+#define ELF_OPENBSD_EXTENSION
 #include <sys/exec_elf.h>
+#undef ELF_OPENBSD_EXTENSION
 
 #include "../../../../lib/libsa/loadfile_elf.c"
diff --git a/sys/sys/exec_elf.h b/sys/sys/exec_elf.h
index 77c13a0372c..95f21d9d44a 100644
--- a/sys/sys/exec_elf.h
+++ b/sys/sys/exec_elf.h
@@ -177,16 +177,12 @@ typedef struct {
 #define EM_486         6               /* Intel 80486 - unused? */
 #define EM_860         7               /* Intel 80860 */
 #define EM_MIPS                8               /* MIPS R3000 Big-Endian only */
-/*
- * Don't know if EM_MIPS_RS4_BE,
- * EM_SPARC64, EM_PARISC,
- * or EM_PPC are ABI compliant
- */
-#define EM_MIPS_RS4_BE 10              /* MIPS R4000 Big-Endian */
-#define EM_SPARC64     11              /* SPARC v9 64-bit unofficial */
+#define EM_MIPS_RS3_LE 10              /* MIPS R3000 Little-Endian */
+       /* 11 - 14 reserved for future use */
 #define EM_PARISC      15              /* HPPA */
 #define EM_SPARC32PLUS 18              /* Enhanced instruction set SPARC */
 #define EM_PPC         20              /* PowerPC */
+#define EM_PPC64       21              /* PowerPC 64 */
 #define EM_ARM         40              /* Advanced RISC Machines ARM */
 #define EM_ALPHA       41              /* DEC ALPHA */
 #define        EM_SH           42              /* Hitachi/Renesas Super-H */
@@ -431,10 +427,14 @@ typedef struct {
 #define PT_GNU_EH_FRAME                0x6474e550      /* Exception handling 
info */
 #define PT_GNU_RELRO           0x6474e552      /* Read-only after relocation */
 
+#if defined(_KERNEL) || defined(_DYN_LOADER) || defined(ELF_OPENBSD_EXTENSION)
+
 #define PT_OPENBSD_RANDOMIZE   0x65a3dbe6      /* fill with random data */
 #define PT_OPENBSD_WXNEEDED    0x65a3dbe7      /* program performs W^X 
violations */
 #define PT_OPENBSD_BOOTDATA    0x65a41be6      /* section for boot arguments */
 
+#endif
+
 /* Segment flags - p_flags */
 #define PF_X           0x1             /* Executable */
 #define PF_W           0x2             /* Writable */
@@ -587,6 +587,8 @@ typedef struct {
  * bump the version.
  */
 
+#if defined(_KERNEL)
+
 #define NT_OPENBSD_PROCINFO    10
 #define NT_OPENBSD_AUXV                11
 
@@ -619,6 +621,8 @@ struct elfcore_procinfo {
        int8_t          cpi_name[32];   /* copy of pr->ps_comm */
 };
 
+#endif
+
 /*
  * XXX - these _KERNEL items aren't part of the ABI!
  */
diff --git a/usr.sbin/vmd/loadfile_elf.c b/usr.sbin/vmd/loadfile_elf.c
index 1fefec9a642..df7e814b3fa 100644
--- a/usr.sbin/vmd/loadfile_elf.c
+++ b/usr.sbin/vmd/loadfile_elf.c
@@ -85,7 +85,9 @@
 #include <sys/ioctl.h>
 #include <sys/reboot.h>
 #include <sys/exec.h>
+#define ELF_OPENBSD_EXTENSION
 #include <sys/exec_elf.h>
+#undef ELF_OPENBSD_EXTENSION
 
 #include <stdio.h>
 #include <string.h>

Reply via email to