Commit Graph

65 Commits

Author SHA1 Message Date
kaiw
5bf2cc0b89 Move helper functions _libelf_ar_get_{name,number,string}() and
`_libelf_ar_open()` to a new compilation unit "libelf_ar_util.c"
to break the circular dependency between "elf_memory.o" and
"libelf_ar.o".

Obtained from:	elftoolchain
MFC after:		1 month
2010-07-21 12:54:34 +00:00
kaiw
bc05b1ebb0 Fix a memory leak.
Obtained from:	elftoolchain
MFC after:		1 month
2010-07-21 12:30:58 +00:00
kaiw
82c6a0d5cc * Deprecate elf_getshnum(), elf_getphnum() and elf_getshstrndx() in
favour of `elf_getshdrnum()`, `elf_getphdrnum()` and `elf_getshdrstrndx()`
  respectively.
* Add new manual pages for `elf_getshdrstrndx()`, `elf_getphdrnum()` and
  `elf_getshdrnum()`.
* Add a deprecation warning for `elf_getshstrndx()`, `elf_getphnum()` and
  `elf_getshnum()`.

Obtained from:	elftoolchain
MFC after:		1 month
2010-07-21 12:14:50 +00:00
kaiw
1b382f295a Avoid switching between "unsigned char" and "char" in the C code
generated from "libelf_convert.m4".

Obtained from:	elftoolchain
MFC after:		1 month
2010-07-21 11:26:18 +00:00
kaiw
8207e8cd23 Add support for translating sections of type ELF_T_GNUHASH.
Obtained from:	elftoolchain
MFC after:		1 month
2010-07-21 10:57:22 +00:00
kaiw
d137ff16e7 - Document that the *fsize() functions return a size of 1 for Elf
types that don't have a fixed size.
- The *fsize() functions should return a size of 1, for variable length
  types.
- Redefine symbol ELF_T_LAST to match the current end of the list.

Obtained from:	elftoolchain
MFC after:		1 month
2010-07-21 10:39:29 +00:00
kaiw
49a7d97ce4 Perform additional checks when translating between file and memory
representations of ELF types.

The ELF(3) API allows applications to request a conversion that is
`in-place', i.e., with source and destinations data buffers being
the same.  However, the file and memory sizes of ELF sections that
have additional internal structure, such as those of type `Elf_Note',
or `Elf_GNU_Hash_Header', can be determined only known after the
type-specific headers that comprise the first few words in these
sections are read and translated.

Pass in the size of destination buffer to type translation routines
in "libelf_convert.m4" and have these routines return an error code
if the translated data would not fit inside the destination buffer.

Obtained from:	elftoolchain
MFC after:		1 month
2010-07-21 10:25:02 +00:00
kaiw
929048ea54 Reduce verbosity.
Obtained from:	elftoolchain
MFC after:		1 month
2010-07-21 10:11:46 +00:00
kaiw
a9edf336a0 - Return zero for file sizes of ELF types that have a variable size.
- Neaten a few comments.

Obtained from:	elftoolchain
MFC after:		1 month
2010-07-21 10:08:25 +00:00
kaiw
55d8bc9ed8 Note that the *_fsize() functions are only defined for ELF types that
have a fixed size.

Obtained from:	elftoolchain
MFC after:		1 month
2010-07-21 10:02:59 +00:00
kaiw
2e04fb95e1 Changes for supporting GNU Hash sections.
Obtained from:	elftoolchain
MFC after:		1 month
2010-07-21 09:56:42 +00:00
kaiw
090a9c2514 Add a new ELF type denoting GNU style hash tables.
Obtained from:	elftoolchain
MFC after:		1 month
2010-07-21 09:51:24 +00:00
kaiw
57795d0388 Allow an application that updates only the ELF Ehdr to work.
Obtained from:	elftoolchain
MFC after:		1 month
2010-07-21 09:47:14 +00:00
kaiw
f349ce0e9e Use <unistd.h> to declare the prototype for ftruncate().
Obtained from:	elftoolchain
MFC after:		1 month
2010-07-21 09:33:45 +00:00
kaiw
07c19657cd Bug fix: permit the creation of zero-sized sections.
Obtained from:	elftoolchain
MFC after:		1 month
2010-07-21 09:27:16 +00:00
kaiw
fbd45b20c3 Improve compatibility with other implementations of the ELF(3) API:
when an output file has no program headers, set the 'e_phentsize'
field of the ELF executable header to zero.

Obtained from:	elftoolchain
MFC after:		1 month
2010-07-21 09:20:40 +00:00
kaiw
d52f6374a8 Bug fix: when updating headers using the gelf_update_*() functions,
the appropriate `dirty' bit needs to be set for both the Elf32 and
Elf64 case.

Obtained from:	elftoolchain
MFC after:		1 month
2010-07-21 08:58:52 +00:00
kaiw
19ba81c75a - Correctly handle sections of type SHT_NOBITS. For these sections:
- elf_getdata() and elf_rawdata() should return an "Elf_Data" structure
    that has its "d_buf" member set to NULL and "d_size" member set to
    the nominal 'size' of the section.  [1]
  - Update the manual page for these functions.
- Fix a memory leak in an error handling path inside elf_getdata().
- Use _libelf_allocate_data() in elf_newdata() for consistency.

Obtained from:	elftoolchain
MFC after:		1 month
2010-07-21 08:54:46 +00:00
kaiw
b1a05aa80b Remove a superfluous comment.
Obtained from:	     elftoolchain
MFC after:	     1 month
2010-07-21 08:43:48 +00:00
kaiw
04e875d138 * Improve compatibility with existing application code by permitting the
use of `elf_getbase()` on non-archive members. This change is needed
  for gcc LTO (-flto) to work properly.
* Style fix: paranthesize returned values.
* Document the current behaviour of `elf_getbase()`.

Tested by:	gerald, Steve Kargl (original patch)
Obtained from:	elftoolchain
MFC after:	3 days
2010-06-13 10:58:50 +00:00
uqs
9d8e496fad mdoc: fix parenthesis
Reviewed by:	brueffer
2010-05-11 23:08:31 +00:00
uqs
3960614646 mdoc: order prologue macros consistently by Dd/Dt/Os
Although groff_mdoc(7) gives another impression, this is the ordering
most widely used and also required by mdocml/mandoc.

Reviewed by:	ru
Approved by:	philip, ed (mentors)
2010-04-14 19:08:06 +00:00
brueffer
ea3ef695e2 Remove useless .TE groff macro.
Submitted by:	Joerg Sonnenberger
MFC after:	3 days
2010-01-12 17:38:23 +00:00
ed
09818ac28e Build lib/ with WARNS=6 by default.
Similar to libexec/, do the same with lib/. Make WARNS=6 the norm and
lower it when needed.

I'm setting WARNS?=0 for secure/. It seems secure/ includes the
Makefile.inc provided by lib/. I'm not going to touch that directory.
Most of the code there is contributed anyway.
2010-01-02 09:58:07 +00:00
obrien
bd84277ca7 Don't need to set symbol, default value is OK. 2009-03-12 04:44:09 +00:00
jkoshy
c56ea79de0 Add a README. 2009-01-05 05:14:26 +00:00
jb
82ed3e6d66 Relax the strict type check because gcc as distributed doesn't create
debug strtabs with type SHT_STRTAB. Although we could change FreeBSD's
gcc, we really need to play nicely with gcc as distributed by the FSF.
2008-05-23 07:35:36 +00:00
jb
5b8646dc24 Change the alignment of the NOTE to match what gcc does. 2008-05-23 07:33:45 +00:00
jb
1fbc3c9d60 Add the case for SHT_AMD64_UNWIND. 2008-05-23 07:32:19 +00:00
brueffer
b64d211df2 Fix some "in in" typos in comments.
PR:		121490
Submitted by:	Anatoly Borodin <anatoly.borodin@gmail.com>
Approved by:	rwatson (mentor), jkoshy
MFC after:	3 days
2008-03-26 07:32:08 +00:00
jkoshy
f8600f40e7 Ensure that the section header table is written out in an order
consistent with the section indices returned to the application by
elf_ndxscn().

Submitted by:		kaiw
2008-03-19 06:06:34 +00:00
jkoshy
af7049a2cd Clarify that the ELF library only sets the sh_entsize field of a
section header entry if the application is not taking charge of ELF
object layout.

Update (c) years, and bump the manual page's date.

Submitted by:		kaiw
2008-03-19 05:07:49 +00:00
jkoshy
35a6571045 - Fix an off-by-one bug in _libelf_insert_section(). [1]
- Update (c) years.

Submitted by:		kaiw [1]
2008-03-03 04:29:25 +00:00
jkoshy
380ba89956 Translate the r_info field of ELF relocation records when converting
between 64 and 32 bit variants.

Submitted by:		kaiw
2008-03-02 06:33:10 +00:00
jkoshy
5c5b24c7a8 Document the return type for gelf_fsize(3).
Submitted by:		kaiw
2008-02-04 18:50:28 +00:00
jkoshy
6bb7675a71 - Allow source descriptors with no data to be used as arguments to the
elf{32,64}_xlateto[fm]() translation functions.  This change makes our
  libelf compatible with other ELF(3) implementations. [1]
- Update manual page to reflect this change.
- Style fixes: wrap a long line.

Submitted by:	jb [1]
2007-11-26 03:09:33 +00:00
jkoshy
02cd3fead5 Sections of type SHT_GNU_versym use ELF type ELF_T_HALF. Update manual
page and code to match.

Submitted by:	jb
MFC After: 	1 day
2007-11-23 11:29:36 +00:00
jkoshy
9392728ba0 Consistently use the word 'flag' to refer to ELF_F_* constants.
MFC after:	1 day
2007-10-22 03:38:43 +00:00
jkoshy
3d86cf4179 Remove references to the 'e_phnum' field of the ELF header. Instead,
point the reader to the elf_getphnum() function.

MFC after:	1 day
2007-10-21 05:15:07 +00:00
jkoshy
0f156735c0 Refer the reader to the elf_update(3) manual page for more information
on application control of ELF object layout.

MFC after:	1 day
2007-10-21 05:08:40 +00:00
jkoshy
3a55a053ea Do not generate unneeded initializers.
Approved by:	re (bmah)
2007-09-09 02:10:53 +00:00
jkoshy
a632b8cbc0 Fix a bug that prevented applications from laying out ELF objects
with section header tables residing in between other sections.

Introduce additional checks for overlaps between section data and
the section header table when the application is performing section
layout.

Document additional error returns.

Reported by:	Kai Wang <kaiw27 at gmail dot com>
Approved by:	re (rwatson)
2007-09-08 08:20:12 +00:00
jkoshy
bbf0406634 Cross-reference the correct manual page.
Approved by:	re (bmah)
2007-07-28 15:35:03 +00:00
deischen
2a7306fdc5 Use C comments since we now preprocess these files with CPP. 2007-04-29 14:05:22 +00:00
jkoshy
9645b900be Describe the contents of the "ar_name" and "ar_rawname" fields of
Elf_Arhdr structures better.
2007-03-27 04:47:50 +00:00
jkoshy
e13fe525e7 Bug fixes to ar(1) archive handling:
- Correctly retrieve the initial (special) members of an archive after
   an archive descriptor is rewound using elf_rand(SARMAG).
 - Do not strip trailing white space from the 'raw' names retrieved
   using elf_getarhdr().

Reported by:	"Hyo geol, Lee" <hyogeollee at gmail dot com>
2007-03-27 04:40:57 +00:00
jkoshy
359932b592 Document the return type of elf_rand(3) correctly. 2007-03-26 16:31:42 +00:00
jkoshy
b5f826c9a6 Correct a typo.
Submitted by:	 Kai Wang <kaiw27 at gmail dot com>
2007-03-19 03:52:20 +00:00
jkoshy
cb00361cdd Add GELF_* accessor macros.
Prodded by:	Sam Arun Raj <samarunraj at gmail dot com>
2007-03-08 04:01:30 +00:00
jkoshy
cf625a0a3b Fix a typo.
Submitted by:	 Kai Wang <kaiw27 at gmail dot com>
2007-03-03 06:13:38 +00:00