Page MenuHomeFreeBSD

[PowerPC] force applications linked with lib CSU to have .got
ClosedPublic

Authored by alfredo on Aug 30 2019, 6:39 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sat, Apr 20, 3:56 PM
Unknown Object (File)
Fri, Apr 19, 7:37 PM
Unknown Object (File)
Fri, Apr 19, 7:37 PM
Unknown Object (File)
Fri, Apr 19, 7:33 PM
Unknown Object (File)
Fri, Apr 19, 7:33 PM
Unknown Object (File)
Fri, Apr 19, 7:33 PM
Unknown Object (File)
Fri, Apr 19, 7:33 PM
Unknown Object (File)
Wed, Apr 17, 9:56 AM

Details

Summary

This forces applications linked with lib CSU to have a .got, fixing binaries linked with LLD9 after secure-plt was enabled on FreeBSD.

The following comment by Fangrui Song was extracted from: https://bugs.llvm.org/show_bug.cgi?id=43116#c11

"FreeBSD rtld-elf powerpc doesn't have GOT-generating relocations in its crt files but it supports lazy binding PLT. In the -fno-pie -no-pie crt files, I think there should be a
.reloc 0, R_PPC_NONE, _GLOBAL_OFFSET_TABLE_
to make it clear .got is needed."

Test Plan

Test 32 bit "hello world" applications on PowerPC64

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

alfredo edited the test plan for this revision. (Show Details)

Interesting thought. That seems to me like it should also help a lot with the logic in ld.bfd as well.

Can you instead add something like the following to crt1.c?

#if !defined(GCRT) && !defined(PIC)
__asm__(".text\n"
             "\t.global _GLOBAL_OFFSET_TABLE\n"
            "\t.reloc 0, R_PPC_NONE, _GLOBAL_OFFSET_TABLE_");
#endif

Can you instead add something like the following to crt1.c?

#if !defined(GCRT) && !defined(PIC)
__asm__(".text\n"
             "\t.global _GLOBAL_OFFSET_TABLE\n"
            "\t.reloc 0, R_PPC_NONE, _GLOBAL_OFFSET_TABLE_");
#endif

I don't know GCRT but !defined(PIC) looks good to me. PIC code should already have some GOT-generating relocations.

@i_maskray.me, you're right. It should just be

#ifndef PIC
...

I was going purely by the diff.

patch updated with suggestions from reviewers.
It looks much cleaner now :)

For reference, these are the first lines of the generated crt1.s

        .text
        .file   "crt1.c"
                                        # Start of file scope inline assembly
        .ident  "$FreeBSD$"
        .ident  "$FreeBSD$"
        .ident  "$FreeBSD$"
        .globl  _GLOBAL_OFFSET_TABLE
        .reloc 0, R_PPC_NONE, _GLOBAL_OFFSET_TABLE_

                                        # End of file scope inline assembly
        .file   1 "/usr/obj/root/src/freebsd/powerpc.powerpc64/obj-lib32" "tmp/usr/include/machine/_types.h"
        .file   2 "/usr/obj/root/src/freebsd/powerpc.powerpc64/obj-lib32" "tmp/usr/include/sys/_stdint.h"
        .file   3 "/root/src/freebsd/lib/csu/common" "crtbrand.c"
        .file   4 "/root/src/freebsd/lib/csu/common" "ignore_init.c"
        .file   5 "/root/src/freebsd/lib/csu/powerpc" "crt1.c"
        .globl  _start                  # -- Begin function _start
        .p2align        2
        .type   _start,@function
_start:                                 # @_start

I like it, except for the typo :)

lib/csu/powerpc/crt1.c
108 ↗(On Diff #61733)

Should be _GLOBAL_OFFSET_TABLE_ (missing trailing _)

lib/csu/powerpc/crt1.c
108 ↗(On Diff #61733)

I ended up hitting this typo as well, please update when you get the chance.

update fixing missing "_" in line:
.global _GLOBAL_OFFSET_TABLE_

alfredo marked an inline comment as done.

It's important to not that it requires a modern compiler, so it shouldn't land before powerpc flag day.

marking as "Plan Changes" to avoid accidental commit.

In D21476#475382, @alfredo.junior_eldorado.org.br wrote:

It's important to not that it requires a modern compiler, so it shouldn't land before powerpc flag day.

marking as "Plan Changes" to avoid accidental commit.

It seems above comment isn't true. This patch caused no harm no powerpc and powerpc64 build. Tests using a ISO image shown powerpc64 working fine, so it can commited before flag day.

This revision is now accepted and ready to land.Sep 28 2019, 3:50 AM

Updates "if" clause. The comment regarding this got unnoticed by me until now.

This revision now requires review to proceed.Oct 8 2019, 6:50 PM
This revision is now accepted and ready to land.Oct 9 2019, 9:21 PM