Skip to content

Commit 0d0f845

Browse files
akihikodakiMark Wielaard
authored and
Mark Wielaard
committed
libelf: gelf_newehdr and gelf_newehdr should return void *.
unsigned long int is not always capable to have pointer in some cases (LLP64, for example). Return a void pointer instead. Other libelf implementations will also make this change (or already have). Also update the documentation to state what is created and that NULL is returned on error (don't document that the returned value is a pointer to the actual header created). Signed-off-by: Akihiko Odaki <[email protected]> Signed-off-by: Mark Wielaard <[email protected]>
1 parent ee22502 commit 0d0f845

File tree

4 files changed

+22
-10
lines changed

4 files changed

+22
-10
lines changed

libelf/ChangeLog

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
2016-10-11 Akihiko Odaki <[email protected]>
2+
Mark Wielaard <[email protected]>
3+
4+
* gelf.h (gelf_newehdr): Change return type to void *.
5+
(gelf_newphdr): Likewise.
6+
* gelf_newehdr.c (gelf_newehdr): Likewise.
7+
* gelf_newphdr.c (gelf_newphdr): Likewise.
8+
19
2016-10-21 Mark Wielaard <[email protected]>
210

311
* elf_getdata.c (__libelf_set_rawdata_wrlock): Sanity check

libelf/gelf.h

+8-4
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,10 @@ extern GElf_Ehdr *gelf_getehdr (Elf *__elf, GElf_Ehdr *__dest);
165165
/* Update the ELF header. */
166166
extern int gelf_update_ehdr (Elf *__elf, GElf_Ehdr *__src);
167167

168-
/* Create new ELF header if none exists. */
169-
extern unsigned long int gelf_newehdr (Elf *__elf, int __class);
168+
/* Create new ELF header if none exists. Creates an Elf32_Ehdr if CLASS
169+
is ELFCLASS32 or an Elf64_Ehdr if CLASS is ELFCLASS64. Returns NULL
170+
on error. */
171+
extern void *gelf_newehdr (Elf *__elf, int __class);
170172

171173
/* Get section at OFFSET. */
172174
extern Elf_Scn *gelf_offscn (Elf *__elf, GElf_Off __offset);
@@ -183,8 +185,10 @@ extern GElf_Phdr *gelf_getphdr (Elf *__elf, int __ndx, GElf_Phdr *__dst);
183185
/* Update the program header. */
184186
extern int gelf_update_phdr (Elf *__elf, int __ndx, GElf_Phdr *__src);
185187

186-
/* Create new program header with PHNUM entries. */
187-
extern unsigned long int gelf_newphdr (Elf *__elf, size_t __phnum);
188+
/* Create new program header with PHNUM entries. Creates either an
189+
Elf32_Phdr or an Elf64_Phdr depending on whether the given ELF is
190+
ELFCLASS32 or ELFCLASS64. Returns NULL on error. */
191+
extern void *gelf_newphdr (Elf *__elf, size_t __phnum);
188192

189193
/* Get compression header of section if any. Returns NULL and sets
190194
elf_errno if the section isn't compressed or an error occurred. */

libelf/gelf_newehdr.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@
3737
#include "libelfP.h"
3838

3939

40-
unsigned long int
40+
void *
4141
gelf_newehdr (Elf *elf, int class)
4242
{
4343
return (class == ELFCLASS32
44-
? (unsigned long int) INTUSE(elf32_newehdr) (elf)
45-
: (unsigned long int) INTUSE(elf64_newehdr) (elf));
44+
? (void *) INTUSE(elf32_newehdr) (elf)
45+
: (void *) INTUSE(elf64_newehdr) (elf));
4646
}

libelf/gelf_newphdr.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@
3737
#include "libelfP.h"
3838

3939

40-
unsigned long int
40+
void *
4141
gelf_newphdr ( Elf *elf, size_t phnum)
4242
{
4343
return (elf->class == ELFCLASS32
44-
? (unsigned long int) INTUSE(elf32_newphdr) (elf, phnum)
45-
: (unsigned long int) INTUSE(elf64_newphdr) (elf, phnum));
44+
? (void *) INTUSE(elf32_newphdr) (elf, phnum)
45+
: (void *) INTUSE(elf64_newphdr) (elf, phnum));
4646
}

0 commit comments

Comments
 (0)