Bug 27755 - [powerpc] fails to link binary which does not fit within R_PPC_REL24
Summary: [powerpc] fails to link binary which does not fit within R_PPC_REL24
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.34
: P2 normal
Target Milestone: ---
Assignee: Alan Modra
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-04-20 00:42 UTC by Rin Okuyama
Modified: 2021-05-03 06:18 UTC (History)
1 user (show)

See Also:
Host:
Target: powerpc
Build:
Last reconfirmed: 2021-05-03 00:00:00


Attachments
Fix for this bug (390 bytes, patch)
2021-04-20 00:42 UTC, Rin Okuyama
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Rin Okuyama 2021-04-20 00:42:12 UTC
Created attachment 13386 [details]
Fix for this bug

Try to link binary whose text segment does not fit within R_PPC_REL24
results in infinite recursion in ppc_elf_inline_plt():

% cat test.c
#include <stdio.h>
int main(void) {
        printf("Hello, ");
        __asm volatile(".rept 16777216; nop; .endr");   /* 2^24 nop's */
        printf("World!\n");
        return 0;
}
% cc -mlongcall test.c
... freeze in ld(1) ...

This is due to missing of increment of loop variable in ppc_elf_inline_plt().
See the attached patch for more details.

This bug exists also for HEAD as of today, and was introduced to commit:

https://sourceware.org/git/?p=binutils-gdb.git;a=commitdiff;h=3e04d7655bf63f4e5a0d0354c21aa3fa2ece3681

i.e., first revision where ppc_elf_inline_plt() was added.

With the attached patch, the above test.c successfully links for powerpc.
I've never tested for powerpc64, but it should work also.

----
% ld --version
GNU ld (NetBSD Binutils nb1) 2.34
Copyright (C) 2020 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License version 3 or (at your option) a later version.
This program has absolutely no warranty.
----
% cc --version
powerpc--netbsd-gcc (NetBSD nb1 20210411) 10.3.0
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Comment 1 Alan Modra 2021-05-03 04:06:25 UTC
This was fixed for ppc64 with commit 435edf0bf2312 but I failed to apply the same fix for ppc32.
Comment 2 Rin Okuyama 2021-05-03 04:58:57 UTC
Thanks for comment. I overlooked it. Please apply the same for ppc32.
Comment 3 Sourceware Commits 2021-05-03 06:05:13 UTC
The master branch has been updated by Alan Modra <amodra@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=337d0bf887a3ed6b6b2123fecfec0736640edcaf

commit 337d0bf887a3ed6b6b2123fecfec0736640edcaf
Author: Alan Modra <amodra@gmail.com>
Date:   Mon May 3 13:37:00 2021 +0930

    PR27755, powerpc-ld infinite loop
    
            PR 27755
            * elf32-ppc.c (ppc_elf_inline_plt): Do increment rel in loop.
Comment 4 Rin Okuyama 2021-05-03 06:12:15 UTC
Alan, thank you very much for your kind response!
Comment 5 Sourceware Commits 2021-05-03 06:13:01 UTC
The binutils-2_36-branch branch has been updated by Alan Modra <amodra@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=ec2451f91e2f786a819f94ab6aa8704869c48a54

commit ec2451f91e2f786a819f94ab6aa8704869c48a54
Author: Alan Modra <amodra@gmail.com>
Date:   Mon May 3 13:37:00 2021 +0930

    PR27755, powerpc-ld infinite loop
    
            PR 27755
            * elf32-ppc.c (ppc_elf_inline_plt): Do increment rel in loop.
    
    (cherry picked from commit 337d0bf887a3ed6b6b2123fecfec0736640edcaf)
Comment 6 Sourceware Commits 2021-05-03 06:16:14 UTC
The binutils-2_35-branch branch has been updated by Alan Modra <amodra@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=3437a8bad8a4f217e84d6e583b59a4a7f16e5a72

commit 3437a8bad8a4f217e84d6e583b59a4a7f16e5a72
Author: Alan Modra <amodra@gmail.com>
Date:   Mon May 3 13:37:00 2021 +0930

    PR27755, powerpc-ld infinite loop
    
            PR 27755
            * elf32-ppc.c (ppc_elf_inline_plt): Do increment rel in loop.
    
    (cherry picked from commit 337d0bf887a3ed6b6b2123fecfec0736640edcaf)
Comment 7 Sourceware Commits 2021-05-03 06:17:13 UTC
The binutils-2_34-branch branch has been updated by Alan Modra <amodra@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=c4e78c0868a22971680217a41fdb73516a26813d

commit c4e78c0868a22971680217a41fdb73516a26813d
Author: Alan Modra <amodra@gmail.com>
Date:   Mon May 3 13:37:00 2021 +0930

    PR27755, powerpc-ld infinite loop
    
            PR 27755
            * elf32-ppc.c (ppc_elf_inline_plt): Do increment rel in loop.
    
    (cherry picked from commit 337d0bf887a3ed6b6b2123fecfec0736640edcaf)
Comment 8 Alan Modra 2021-05-03 06:18:56 UTC
Fixed 2.34, 2.35, 2.36 and mainline.