Author: kaiw
Date: Sun Jun 13 10:58:50 2010
New Revision: 209122
URL: http://svn.freebsd.org/changeset/base/209122

Log:
  * 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

Modified:
  head/lib/libelf/elf_getbase.3
  head/lib/libelf/elf_getbase.c

Modified: head/lib/libelf/elf_getbase.3
==============================================================================
--- head/lib/libelf/elf_getbase.3       Sun Jun 13 07:30:51 2010        
(r209121)
+++ head/lib/libelf/elf_getbase.3       Sun Jun 13 10:58:50 2010        
(r209122)
@@ -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 ,

Modified: head/lib/libelf/elf_getbase.c
==============================================================================
--- head/lib/libelf/elf_getbase.c       Sun Jun 13 07:30:51 2010        
(r209121)
+++ head/lib/libelf/elf_getbase.c       Sun Jun 13 10:58:50 2010        
(r209122)
@@ -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));
 }
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to