On 03.04.2007 [09:01:34 -0500], Adam Litke wrote:
> On Mon, 2007-04-02 at 18:27 -0700, Nishanth Aravamudan wrote:
> > ppc: rework plt detection
> > 
> > We currently emit LONG(0) into the .plt section of relinked ppc binaries
> > to make it appear in the filesz (on-disk) portion of the data/bss
> > segment. This is a problem, however, for powerpc64, where the ABI
> > specifies that the .plt section is NOBITS (x86 and x86_64 mark the .plt
> > PROGBITS). Given that the program is being relinked to begin with,
> > however, it seems logical to simply add a tag, similar to
> > __executable_start, to make finding the "libhuge" filesz easy to find.
> > Do exactly this, via __libhuge_filesz, and skip the extracopy detection
> > if this symbol is defined. Tested on powerpc64.
> 
> Looks good to me... 
> 
> What do you think about adding some comments into the linker scripts
> here so it will be easy to remember what this is for later?

Updated patch below:


ppc: rework plt detection

We currently emit LONG(0) into the .plt section to make it appear in the
filesz (on-disk) portion of the data/bss segment. This is a problem,
however, for powerpc64, where the ABI specifies that the .plt section is
NOBITS (x86 and x86_64 mark the .plt PROGBITS). Given that the program
is being relinked to begin with, however, it seems logical to simply add
a tag, similar to __executable_start, to make finding the "libhuge"
filesz easy to find. Do exactly this, via __libhuge_filesz, and skip the
extracopy detection if this symbol is defined. Tested on powerpc64.

Signed-off-by: Nishanth Aravamudan <[EMAIL PROTECTED]>

diff --git a/elflink.c b/elflink.c
index 5058248..00b403a 100644
--- a/elflink.c
+++ b/elflink.c
@@ -414,6 +414,7 @@ static void get_extracopy(struct seg_info *seg, Elf_Phdr 
*phdr, int phnum)
        int ret, numsyms, found_sym = 0;
        void *start, *end, *start_orig, *end_orig;
        void *sym_start, *sym_end;
+       extern void __libhuge_filesz __attribute__((weak));
 
        end_orig = seg->vaddr + seg->memsz;
        start_orig = seg->vaddr + seg->filesz;
@@ -422,6 +423,13 @@ static void get_extracopy(struct seg_info *seg, Elf_Phdr 
*phdr, int phnum)
        if (!minimal_copy)
                goto bail2;
 
+       if (&__libhuge_filesz) {
+               found_sym = 1;
+               start = start_orig;
+               end = &__libhuge_filesz;
+               goto found;
+       }
+
        /* Find dynamic program header */
        ret = find_dynamic(&dyntab, phdr, phnum);
        if (ret < 0)
@@ -462,6 +470,7 @@ static void get_extracopy(struct seg_info *seg, Elf_Phdr 
*phdr, int phnum)
        if (__debug)
                check_bss(end, end_orig);
 
+found:
        if (found_sym) {
                /* Return the copy window */
                seg->extra_vaddr = start;
diff --git a/ldscripts/elf32ppclinux.xBDT b/ldscripts/elf32ppclinux.xBDT
index f30bd3b..109d556 100644
--- a/ldscripts/elf32ppclinux.xBDT
+++ b/ldscripts/elf32ppclinux.xBDT
@@ -161,9 +161,11 @@ SECTIONS
   .dynamic        : { *(.dynamic) } :dynamic :hdata
   .got            :  { *(.got.plt .got) } :hdata
 /*  . = DATA_SEGMENT_RELRO_END (0, .); */
-  /* Ensure the plt appears in the on-disk portion of the binary so it
-   * will be copied during hugetlb remapping */
-  .plt            :  { *(.plt) LONG(0) } :hdata
+  .plt            :  { *(.plt) } :hdata
+  /* Rather than emit LONG(0) in the .plt section, use a symbol to mark
+   * the end of the need-to-copy data so that it will be copied during
+   * hugetlb remapping */
+  __libhuge_filesz = .;
   .data           :
   {
     *(.data .data.* .gnu.linkonce.d.*)
diff --git a/ldscripts/elf64ppc.xBDT b/ldscripts/elf64ppc.xBDT
index 68abf09..548b707 100644
--- a/ldscripts/elf64ppc.xBDT
+++ b/ldscripts/elf64ppc.xBDT
@@ -179,9 +179,11 @@ SECTIONS
     *(.sbss .sbss.* .gnu.linkonce.sb.*)
     *(.scommon)
   } :hdata
-  /* Ensure the plt appears in the on-disk portion of the binary so it
-   * will be copied during hugetlb remapping */
-  .plt            : { LONG(0) *(.plt) } :hdata
+  .plt            : { *(.plt) } :hdata
+  /* Rather than emit LONG(0) in the .plt section, use a symbol to mark
+   * the end of the need-to-copy data so that it will be copied during
+   * hugetlb remapping */
+  __libhuge_filesz = .;
   .bss            :
   {
    *(.dynbss)

-- 
Nishanth Aravamudan <[EMAIL PROTECTED]>
IBM Linux Technology Center

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Libhugetlbfs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/libhugetlbfs-devel

Reply via email to