Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 21 Jun 2010 13:47:29 +0000 (UTC)
From:      Kai Wang <kaiw@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org
Subject:   svn commit: r209393 - stable/8/lib/libelf
Message-ID:  <201006211347.o5LDlTg2039634@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kaiw
Date: Mon Jun 21 13:47:29 2010
New Revision: 209393
URL: http://svn.freebsd.org/changeset/base/209393

Log:
  MFC r209122:
  
    * 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()`.

Modified:
  stable/8/lib/libelf/elf_getbase.3
  stable/8/lib/libelf/elf_getbase.c
Directory Properties:
  stable/8/lib/libelf/   (props changed)

Modified: stable/8/lib/libelf/elf_getbase.3
==============================================================================
--- stable/8/lib/libelf/elf_getbase.3	Mon Jun 21 12:50:54 2010	(r209392)
+++ stable/8/lib/libelf/elf_getbase.3	Mon Jun 21 13:47:29 2010	(r209393)
@@ -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
 .Os
 .Dt ELF_GETBASE 3
 .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: stable/8/lib/libelf/elf_getbase.c
==============================================================================
--- stable/8/lib/libelf/elf_getbase.c	Mon Jun 21 12:50:54 2010	(r209392)
+++ stable/8/lib/libelf/elf_getbase.c	Mon Jun 21 13:47:29 2010	(r209393)
@@ -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));
 }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201006211347.o5LDlTg2039634>