Commit Graph

59 Commits

Author SHA1 Message Date
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
dumbbell
d110653fb0 Fix a bug with the release of section's raw data. Both release loops
were using translated data linked list, leading to a memory leak.

Jkoshy's testsuite was used to check for non-regression.
2007-02-21 08:14:22 +00:00
jkoshy
594130bd7c Document the additional error returns possible when handling ELF objects
that require extended numbering.
2006-12-25 02:24:39 +00:00
jkoshy
26d8253ac6 Keep shadow copies of the e_shnum', e_phnum' and `e_shstrndx'
members of the ELF Executable Header inside the library-private
`struct _Elf' descriptor and only update the underlying Elf{32,64}_Ehdr
structure on an elf_update(3) call.  These fields of the Ehdr
structure are technically `out of bounds' for an application program
per the ELF(3) API, but we've seen applications that initialize
a new Ehdr structure using memcpy(), messing up the library's
invariants. [1]

Implement elf_getphnum() and handle ELF objects with more than
64K program header table entries.

Reported by:	jb [1]
2006-12-25 02:22:22 +00:00
jkoshy
44313eba34 Use strncpy() instead of strlcpy() when copying members of
a `struct ar_hdr'.  These members do not use NUL-termination
while strlcpy() expects its source buffer to be NUL-terminated.
2006-12-25 02:06:32 +00:00
jkoshy
4df7e1dc11 Correct a logic error. 2006-12-24 09:45:10 +00:00
jkoshy
25bc13b736 Use <osreldate.h> rather than the OS version reported by the kernel
to determine which Elf Types are to be handled.  Change the M4
templates to wrap an `#if __FreeBSD_version >= NNN'/`#endif' pair
around the generated code for each ELF data type, where `NNN' is
the OS version where the ELF type was added to the source tree.

This change allows cross-builds of old sources on newer FreeBSD
systems to work correctly.

Problem reported by:	ru
2006-12-18 05:40:01 +00:00