From owner-p4-projects@FreeBSD.ORG Thu Oct 26 23:06:40 2006 Return-Path: X-Original-To: p4-projects@freebsd.org Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 38BBB16A417; Thu, 26 Oct 2006 23:06:40 +0000 (UTC) X-Original-To: perforce@freebsd.org Delivered-To: perforce@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 1721616A403 for ; Thu, 26 Oct 2006 23:06:40 +0000 (UTC) (envelope-from jb@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id D799E43D45 for ; Thu, 26 Oct 2006 23:06:39 +0000 (GMT) (envelope-from jb@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.6/8.13.6) with ESMTP id k9QN6dqm052295 for ; Thu, 26 Oct 2006 23:06:39 GMT (envelope-from jb@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.6/8.13.4/Submit) id k9QN6dOt052292 for perforce@freebsd.org; Thu, 26 Oct 2006 23:06:39 GMT (envelope-from jb@freebsd.org) Date: Thu, 26 Oct 2006 23:06:39 GMT Message-Id: <200610262306.k9QN6dOt052292@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to jb@freebsd.org using -f From: John Birrell To: Perforce Change Reviews Cc: Subject: PERFORCE change 108538 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 26 Oct 2006 23:06:40 -0000 http://perforce.freebsd.org/chv.cgi?CH=108538 Change 108538 by jb@jb_freebsd8 on 2006/10/26 23:05:52 IFlibbsdelf Affected files ... .. //depot/projects/dtrace/src/lib/libelf/elf_update.3#2 integrate .. //depot/projects/dtrace/src/lib/libelf/elf_update.c#3 integrate .. //depot/projects/dtrace/src/lib/libelf/gelf_newehdr.3#7 integrate .. //depot/projects/dtrace/src/lib/libelf/libelf_ehdr.c#6 integrate Differences ... ==== //depot/projects/dtrace/src/lib/libelf/elf_update.3#2 (text+ko) ==== @@ -72,7 +72,14 @@ .It "Executable Header" The ELF executable header is described in .Xr elf 5 . -.Bl -tag -width "e_ident[EI_DATA]" -compact +The following members of the ELF executable header are the application's +responsibility: +.Pp +.Bl -tag -width "e_ident[EI_OSABI]" -compact +.It Va e_entry +Set to the desired entry address for executables. +.It Va e_flags +Set to the desired processor specific flags. .It Va "e_ident[EI_DATA]" Must be set to one of .Dv ELFDATA2LSB @@ -81,30 +88,30 @@ .It Va "e_ident[EI_OSABI]" Set to the OS ABI desired. For -.Os -executable, this field should be set to +.Fx +executables, this field should be set to .Dv ELFOSABI_FREEBSD . +.It Va e_machine +Set to the desired machine architecture, one of the +.Dv EM_* +values in +.In sys/elf_common.h . +.It Va e_phoff +If the application is managing the object's layout, it must +set this field to the file offset of the ELF program header table. +.It Va e_shoff +If the application is managing the object's layout, it must +set this field to the file offset of the ELF section header table. +.It Va e_shstrndx +Set to the index of the string table containing +section names. .It Va e_type -The type of the ELF object, one of the +Set to the type of the ELF object, one of the .Dv ET_* -values. -.It Va e_machine -The desired machine architecture. +values in +.In sys/elf_common.h . .It Va e_version Set to the desired version of the ELF object. -Currently only -.Dv EV_CURRENT -is supported. -.It Va e_entry -Set to the desired entry address. -.It Va e_phoff -If the application is managing the object's layout. -.It Va e_shoff -If the application is managing the object's layout. -.It Va e_flags -Set to the desired processor specific flags. -.It Va e_shstrndx -Set to the index of the string table. .El .It "Program Header" All fields of the entries in the program header table are @@ -112,32 +119,40 @@ .It "Section Header" The ELF section header is described in .Xr elf 5 . +The following members of the ELF section header are the +application's responsibility: +.Pp .Bl -tag -width "sh_addralign" -compact -.It Va sh_name -Set to the index of the section in the string table. -.It Va sh_type -Set to the type of the section. +.It Va sh_addr +Set to the physical memory address where the section should reside. +.It Va sh_addralign +If the application is managing the file layout, it must set this +field to the desired alignment for the section's contents. +This value must be a power of two. +.It Va sh_entsize +Set to the size of each entry, for sections containing fixed size +elements. +For section contents of types known to the library, the application +may leave this field as zero. .It Va sh_flags Set to the desired section flags. -.It Va sh_addr -Set the physical memory address where the section should reside. +.It Va sh_info +Set as described in +.Xr elf 5 . +.It Va sh_link +Set as described in +.Xr elf 5 . +.It Va sh_name +Set to the index of the section's name in the string table containing +section names. .It Va sh_offset -Set to the file offset of the section's data if the application is managing -the layout. +If the application is managing the file layout, it must set this +field to the file offset of the section's contents. .It Va sh_size -Set to the size of the section's data if the application is managing -the layout. -.It Va sh_link -As described in -.Xr elf 5 . -.It Va sh_info -As described in -.Xr elf 5 . -.It Va sh_addralign -Set to the desired alignment constraint if the application is managing -the file layout. -.It Va sh_entsize -Set to the size of each entry, for sections containing fixed size elements. +If the application is managing the file layout, it must set this +field to the file size of the section's contents. +.It Va sh_type +Set to the type of the section. .El .El .Pp ==== //depot/projects/dtrace/src/lib/libelf/elf_update.c#3 (text+ko) ==== @@ -76,7 +76,7 @@ int ec; Elf_Data *d, *td; unsigned int elftype; - uint64_t sh_align, sh_offset, sh_size; + uint64_t sh_align, sh_entsize, sh_offset, sh_size; uint64_t scn_size, scn_alignment; /* @@ -100,15 +100,17 @@ ec = e->e_class; if (ec == ELFCLASS32) { - elftype = _libelf_xlate_shtype(s->s_shdr.s_shdr32.sh_type); - sh_align = (uint64_t) s->s_shdr.s_shdr32.sh_addralign; - sh_size = (uint64_t) s->s_shdr.s_shdr32.sh_size; - sh_offset = (uint64_t) s->s_shdr.s_shdr32.sh_offset; + elftype = _libelf_xlate_shtype(s->s_shdr.s_shdr32.sh_type); + sh_align = (uint64_t) s->s_shdr.s_shdr32.sh_addralign; + sh_entsize = (uint64_t) s->s_shdr.s_shdr32.sh_entsize; + sh_offset = (uint64_t) s->s_shdr.s_shdr32.sh_offset; + sh_size = (uint64_t) s->s_shdr.s_shdr32.sh_size; } else { - elftype = _libelf_xlate_shtype(s->s_shdr.s_shdr64.sh_type); - sh_align = s->s_shdr.s_shdr64.sh_addralign; - sh_size = s->s_shdr.s_shdr64.sh_size; - sh_offset = s->s_shdr.s_shdr64.sh_offset; + elftype = _libelf_xlate_shtype(s->s_shdr.s_shdr64.sh_type); + sh_align = s->s_shdr.s_shdr64.sh_addralign; + sh_entsize = s->s_shdr.s_shdr64.sh_entsize; + sh_offset = s->s_shdr.s_shdr64.sh_offset; + sh_size = s->s_shdr.s_shdr64.sh_size; } if (elftype > ELF_T_LAST) { @@ -164,17 +166,23 @@ if (scn_alignment > sh_align) sh_align = scn_alignment; + if (sh_entsize == 0) + sh_entsize = _libelf_fsize(elftype, ec, e->e_version, + 1); + sh_size = scn_size; sh_offset = roundup(*rc, sh_align); if (ec == ELFCLASS32) { + s->s_shdr.s_shdr32.sh_addralign = (uint32_t) sh_align; + s->s_shdr.s_shdr32.sh_entsize = (uint32_t) sh_entsize; s->s_shdr.s_shdr32.sh_offset = (uint32_t) sh_offset; s->s_shdr.s_shdr32.sh_size = (uint32_t) sh_size; - s->s_shdr.s_shdr32.sh_addralign = (uint32_t) sh_align; } else { + s->s_shdr.s_shdr64.sh_addralign = sh_align; + s->s_shdr.s_shdr64.sh_entsize = sh_entsize; s->s_shdr.s_shdr64.sh_offset = sh_offset; s->s_shdr.s_shdr64.sh_size = sh_size; - s->s_shdr.s_shdr64.sh_addralign = sh_align; } } @@ -342,6 +350,8 @@ return ((off_t) -1); } + e->e_byteorder = eh_byteorder; + #define INITIALIZE_EHDR(E,EC,V) do { \ (E)->e_ident[EI_MAG0] = ELFMAG0; \ (E)->e_ident[EI_MAG1] = ELFMAG1; \ @@ -392,7 +402,8 @@ phoff = roundup(rc, align); rc = phoff + fsz * phnum; - } + } else + phoff = 0; /* * Compute the layout of the sections associated with the @@ -424,7 +435,8 @@ shoff = roundup(rc, align); rc = shoff + fsz * shnum; - } + } else + shoff = 0; /* * Update the `e_phoff' and `e_shoff' fields if the library is @@ -432,11 +444,11 @@ */ if ((e->e_flags & ELF_F_LAYOUT) == 0) { if (ec == ELFCLASS32) { - eh32->e_phoff = phoff; - eh32->e_shoff = shoff; + eh32->e_phoff = (uint32_t) phoff; + eh32->e_shoff = (uint32_t) shoff; } else { - eh64->e_phoff = phoff; - eh64->e_shoff = shoff; + eh64->e_phoff = (uint64_t) phoff; + eh64->e_shoff = (uint64_t) shoff; } } @@ -724,15 +736,25 @@ * read-only. */ - if (munmap(e->e_rawfile, e->e_rawsize) < 0 || - write(e->e_fd, newfile, newsize) != newsize || - lseek(e->e_fd, 0, SEEK_SET) < 0 || - (e->e_rawfile = mmap(NULL, e->e_rawsize, PROT_READ, MAP_PRIVATE, - e->e_fd, (off_t) 0)) == MAP_FAILED) { + if (e->e_rawfile && munmap(e->e_rawfile, e->e_rawsize) < 0) { + LIBELF_SET_ERROR(IO, errno); + goto error; + } + + if (write(e->e_fd, newfile, newsize) != newsize || + lseek(e->e_fd, 0, SEEK_SET) < 0) { LIBELF_SET_ERROR(IO, errno); goto error; } - e->e_rawsize = newsize; + + if (e->e_cmd != ELF_C_WRITE) { + if ((e->e_rawfile = mmap(NULL, newsize, PROT_READ, MAP_PRIVATE, + e->e_fd, (off_t) 0)) == MAP_FAILED) { + LIBELF_SET_ERROR(IO, errno); + goto error; + } + e->e_rawsize = newsize; + } /* * Reset flags, remove existing section descriptors and ==== //depot/projects/dtrace/src/lib/libelf/gelf_newehdr.3#7 (text+ko) ==== @@ -75,8 +75,8 @@ it returns the value returned by .Fn elf64_newehdr "elf" . .Pp -If a fresh header structure is allocated, the following members of the -structure will be set to zero except the following: +If a fresh header structure is allocated, the members of the +structure are initialized as follows: .Bl -tag -width indent .It Va "e_ident[EI_MAG0..EI_MAG3]" Identification bytes at offsets @@ -109,12 +109,13 @@ .Dv EM_NONE . .It Va e_type is set to -.Dv ELF_K_ELF . +.Dv ELF_K_NONE . .It Va e_version is set to the ELF library's operating version set by a prior call to .Xr elf_version 3 . .El .Pp +Other members of the header are set to zero. The application is responsible for changing these values as needed before calling .Fn elf_update . ==== //depot/projects/dtrace/src/lib/libelf/libelf_ehdr.c#6 (text+ko) ==== @@ -46,8 +46,8 @@ eh->e_ident[EI_DATA] = ELFDATANONE; \ eh->e_ident[EI_VERSION] = LIBELF_PRIVATE(version); \ eh->e_machine = EM_NONE; \ - eh->e_type = ELF_K_ELF; \ - eh->e_version = EV_NONE; \ + eh->e_type = ELF_K_NONE; \ + eh->e_version = LIBELF_PRIVATE(version); \ } while (0) void *