/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2010 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/* Copyright (c) 1987, 1988 Microsoft Corporation */
/* All Rights Reserved */
#include <errno.h>
#include <libelf.h>
#include "decl.h"
#include "msg.h"
/*
* Routines for generating a checksum for an elf image. Typically used to create
* a DT_CHECKSUM entry. This checksum is intended to remain constant after
* operations such as strip(1)/mcs(1), thus only allocatable sections are
* processed, and of those, any that might be modified by these external
* commands are skipped.
*/
/*
* update and epilogue sum functions (stolen from libcmd)
*/
static long
{
return (sum);
while (cnt--)
return (sum);
}
static long
{
long _sum;
}
/*
* This module is compiled twice, the second time having
* -D_ELF64 defined. The following set of macros represent
* the differences between the two compilations. Be
* careful *not* to add any class dependent code (anything
* that has elf32 or elf64 in the name) to this code
* without hiding it behind a switchable macro like these.
*/
#if defined(_ELF64)
#else /* else ELF32 */
#endif /* ELF64 */
long
{
long sum = 0;
return (0);
/*
* Determine the data information to retrieve. When called from ld()
* we're processing an ELF_C_IMAGE (memory) image and thus need to use
* elf_getdata(), as there is not yet a file image (or raw data) backing
* this. When called from utilities like elfdump(1) we're processing a
* file image and thus using the elf_rawdata() allows the same byte
* stream to be processed from different architectures - presently this
* is irrelevant, as the checksum simply sums the data bytes, their
* order doesn't matter. But being uncooked is slightly less overhead.
*
* If the file is writable, the raw data will not reflect any
* changes made in the process, so the uncooked version is only
* for readonly files.
*/
else
return (0);
return (0);
/* Exclude strippable sections */
continue;
/*
* Exclude allocable sections that can change:
* - The .dynsym section can contain section symbols
* that strip might remove.
* - The .dynamic section is modified by the setting of
* this checksum value.
* - The .SUNW_dof section uses ftok(3C), which returns
* different values, to define a key for the
* objects in that section.
*/
continue;
data = 0;
}
}