* 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
This commit is contained in:
Kai Wang 2010-06-13 10:58:50 +00:00
parent b38f7723eb
commit b2c6fcf986
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=209122
2 changed files with 19 additions and 13 deletions

View File

@ -1,4 +1,4 @@
.\" Copyright (c) 2006 Joseph Koshy. All rights reserved.
.\" Copyright (c) 2006,2008,2010 Joseph Koshy. All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
@ -23,7 +23,7 @@
.\"
.\" $FreeBSD$
.\"
.Dd June 11, 2006
.Dd June 6, 2010
.Dt ELF_GETBASE 3
.Os
.Sh NAME
@ -38,17 +38,21 @@
.Sh DESCRIPTION
Function
.Fn elf_getbase
returns the file offset in the containing archive of the first byte of
the file referenced by ELF descriptor
returns the file offset to the first byte of the object referenced by ELF
descriptor
.Ar elf .
.Pp
For descriptors referencing members of archives, the returned offset is
the file offset of the member in its containing archive.
For descriptors to regular objects, the returned offset is (vacuously)
zero.
.Sh RETURN VALUES
Function
.Fn elf_getbase
returns a valid file offset into the containing archive if successful.
It returns -1 if argument
.Ar elf
is NULL or is not a member of an
archive.
returns a valid file offset if successful, or
.Pq Vt off_t
.Li -1
in case of an error.
.Sh ERRORS
Function
.Fn elf_getbase
@ -57,7 +61,7 @@ may fail with the following errors:
.It Bq Er ELF_E_ARGUMENT
Argument
.Ar elf
is not an ELF descriptor for an archive member.
was NULL.
.El
.Sh SEE ALSO
.Xr elf 3 ,

View File

@ -34,12 +34,14 @@ __FBSDID("$FreeBSD$");
off_t
elf_getbase(Elf *e)
{
if (e == NULL ||
e->e_parent == NULL) {
if (e == NULL) {
LIBELF_SET_ERROR(ARGUMENT, 0);
return (off_t) -1;
return ((off_t) -1);
}
if (e->e_parent == NULL)
return ((off_t) 0);
return ((off_t) ((uintptr_t) e->e_rawfile -
(uintptr_t) e->e_parent->e_rawfile));
}