From: Joseph K. <jk...@us...> - 2008-08-02 14:49:27
|
> I've been trying to port libelf to Debian today, and I managed > make it basically working. There are some issues unclear to me: Thanks. Giridhar (yganag@) had sent in a patch for a prior revision of libelf, enabling compilation for GNU/Linux, GNU/Hurd, and GNU/kFreeBSD. I'll take a stab at merging the information in both patches. kaiw> I found that there are two versions of ELF header files which kaiw> contain ELF structures and other definitions. One is provided by kaiw> GNU libc, the other one is linux/elf.h(includes asm/elf.h, etc, kaiw> provided by kernel? ). I noticed that the one provided by GNU kaiw> libc has more definitions thus maybe better for us to use. But kaiw> asm/elf.h provides arch-dependent defines. kaiw> So, in the patch I included asm/elf.h in _libelf_config.h to get kaiw> arch-dependent defines (ELF_CLASS, ELF_ARCH, ELF_DATA), and kaiw> included elf.h(GNU libc) in libelf.h. This seems ok. kaiw> 2. strlcat/strlcpy kaiw> These two functions are very convenient but unfortunately not inside kaiw> GNU libc. I guess there are two solutions for this: kaiw> a) Use portable strncpy/strncat, as a result, the code will become kaiw> less elegant. kaiw> b) define strlcpy/strlcat. kaiw> In the patch I chose b), I added a file called libelf_util.c which kaiw> defines these two function. (stolen from FreeBSD libc) yganag> For Debian, these definitions are provided in the libbsd yganag> package. For other Linuxes, we would have to define these. The strl*() APIs are cleaner, but I'm wondering if we should just bite the bullet and stick to the portable APIs. For example: Index: elf_errmsg.c =================================================================== --- elf_errmsg.c (revision 209) +++ elf_errmsg.c (working copy) @@ -27,6 +27,7 @@ #include <sys/cdefs.h> #include <libelf.h> +#include <stdio.h> #include <string.h> #include "_libelf.h" @@ -74,11 +75,9 @@ if (error < 0 || error >= ELF_E_NUM) return _libelf_errors[ELF_E_NUM]; if (oserr) { - strlcpy(LIBELF_PRIVATE(msg), _libelf_errors[error], - sizeof(LIBELF_PRIVATE(msg))); - strlcat(LIBELF_PRIVATE(msg), ": ", sizeof(LIBELF_PRIVATE(msg))); - strlcat(LIBELF_PRIVATE(msg), strerror(oserr), - sizeof(LIBELF_PRIVATE(msg))); + (void) snprintf(LIBELF_PRIVATE(msg), + sizeof(LIBELF_PRIVATE(msg)), "%s: %s", + _libelf_errors[error], strerror(oserr)); return (const char *)&LIBELF_PRIVATE(msg); } return _libelf_errors[error]; Comments? kaiw> 3. STAILQ Should we just add missing STAILQ defines like we did kaiw> for NetBSD? Question 1: Is there a package that provides <sys/queue.h> for GNU/Linux? Question 2: is there a way to distinguish between Debian GNU/Linux and the other distributions at compile time? E.g., is a __Debian__ or other pre-processor symbol defined at compile time? kaiw> 4. pmake compatibility kaiw> a) Seems that header files (gelf.h, libelf.h) can not be kaiw> installed. After I typed "pmake install", libraries and manual kaiw> pages got installed, but not header files. If there's a port of NetBSD `bmake', could you try that instead of pmake? http://www.crufty.net/help/sjg/bmake.html kaiw> b) GNU and BSD tsort are probably incompatibible, you can see some kaiw> tsort warnings during compiling, but I don't know if that affects the kaiw> resulting files. What are these warnings? Our Makefiles don't invoke tsort directly so if there are warnings we would need to look at the packaged <bsd.lib.mk>. Koshy |