This is a batch of fixes that allows FreeBSD/PowerPC64 use LLVM as themain compiler/linker. The commit list bellow refers to hashs found at LLVM Project repo https://github.com/llvm/llvm-project/tree/master, currently tagged as LLVM 9.X. The changes were backported to 8.x
LLVM commit list:
From 9529c563eb54e0937d6945e142a693d03b4b6893 Mon Sep 17 00:00:00 2001
From: Fangrui Song <maskray@google.com>
Date: Fri, 10 May 2019 17:09:25 +0000
Subject: [PATCH] [MC][ELF] Copy top 3 bits of st_other to .symver aliases
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
On PowerPC64 ELFv2 ABI, the top 3 bits of st_other encode the local
entry offset. A versioned symbol alias created by .symver should copy
the bits from the source symbol.
This partly fixes PR41048. A full fix needs tracking of .set assignments
and updating st_other fields when finish() is called, see D56586.
Patch by Alfredo Dal'Ava Júnior
Revision: https://reviews.llvm.org/D59436
llvm-svn: 360442
From 6cdd68e386d98c0535e9f977849f376e1e6f55a2 Mon Sep 17 00:00:00 2001
From: Fangrui Song <maskray@google.com>
Date: Fri, 10 May 2019 05:51:00 +0000
Subject: [PATCH] [PPC64] Define getThunkSectionSpacing() based on the range of
R_PPC64_REL24
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Suggested by Sean Fertile and Peter Smith.
Thunk section spacing decrease the total number of thunks. I measured a
decrease of 1% or less in some large programs, with no perceivable
slowdown in link time. Override getThunkSectionSpacing() to enable it.
0x2000000 is the farthest point R_PPC64_REL24 can reach. I tried several
numbers and found 0x2000000 works the best. Numbers near 0x2000000 work
as well but let's just use the simpler number.
As demonstrated by the updated tests, this essentially changes placement
of most thunks to the end of the output section. We leverage this
property to fix PR40740 reported by Alfredo Dal'Ava Júnior:
The output section .init consists of input sections from several object
files (crti.o crtbegin.o crtend.o crtn.o). Sections other than the last
one do not have a terminator. With this patch, we create the thunk after
the last .init input section and thus fix the issue. This is not
foolproof but works quite well for such sections (with no terminator) in
practice.
Revision: https://reviews.llvm.org/D61720
llvm-svn: 360405
From 9efdd7ac5e914d3c9fa1ef33781acea43d98c913 Mon Sep 17 00:00:00 2001
From: Rui Ueyama <ruiu@google.com>
Date: Fri, 15 Feb 2019 23:11:18 +0000
Subject: [PATCH] [PPC64] Preserve LocalEntry when linking
On PowerPC64, it is necessary to keep the LocalEntry bits in st_other,
especially when -r is used. Otherwise, when the resulting object is used
in a posterior linking, LocalEntry info will be unavailable and
functions may be called through the wrong entrypoint.
Patch by Leandro Lupori.
Revision: https://reviews.llvm.org/D56782
llvm-svn: 354184
From cd36a2857ea172d70a7a841f4b622a5f408944a9 Mon Sep 17 00:00:00 2001
From: Fangrui Song <maskray@google.com>
Date: Tue, 21 May 2019 10:41:25 +0000
Subject: [PATCH] [PPC64] Update LocalEntry from assigned symbols
On PowerPC64 ELFv2 ABI, functions may have 2 entry points: global and local.
The local entry point location of a function is stored in the st_other field of the symbol, as an offset relative to the global entry point.
In order to make symbol assignments (e.g. .equ/.set) work properly with this, PPCTargetELFStreamer already copies the local entry bits from the source symbol to the destination one, on emitAssignment(). The problem is that this copy is performed only at the assignment location, where the source symbol may not yet have processed the .localentry directive, that sets the local entry. This may cause the destination symbol to end up with wrong local entry information. Other symbol info is not affected by this because, in this case, the destination symbol value is actually a symbol reference.
This change keeps track of these assignments, and update all needed st_other fields when finish() is called.
Patch by Leandro Lupori!
Revision: https://reviews.llvm.org/D56586
llvm-svn: 361237
From 61504079515f76ca094bb836c4d53b41064220d6 Mon Sep 17 00:00:00 2001
From: Fangrui Song <maskray@google.com>
Date: Fri, 10 May 2019 16:24:57 +0000
Subject: [PATCH] [llvm-objdump] Print st_other
Add support for ".hidden" ".internal" ".protected" and " 0x%02x" for
other st_other bits used by some architectures.
Revision: https://reviews.llvm.org/D61718
llvm-svn: 360439
From 44266b9e115ad172b1f6a88d15d4e7579812c0fc Mon Sep 17 00:00:00 2001
From: Martin Storsjo <martin@martin.st>
Date: Thu, 16 May 2019 06:49:13 +0000
Subject: [PATCH] [PPC64][libunwind] Fix r2 not properly restored
This change makes each unwind step inspect the instruction at the
return address and, if needed, read r2 from its saved location and
modify the context appropriately.
The unwind logic is able to handle both ELFv1 and ELFv2 stacks.
Reported by Bug 41050
Patch by Leandro Lupori!
Revision: https://reviews.llvm.org/D59694
llvm-svn: 360861
From 905af40cc6ce0d246e42bf7db456d8ca944caaf6 Mon Sep 17 00:00:00 2001
From: Martin Storsjo <martin@martin.st>
Date: Thu, 16 May 2019 06:49:20 +0000
Subject: [PATCH] [PPC] Fix 32-bit build of libunwind
Clang integrated assembler was unable to build libunwind PPC32 assembly code,
present in functions used to save/restore register context.
This change consists in replacing the assembly style used in libunwind source,
to one that is compatible with both Clang integrated assembler as well as
GNU assembler.
Patch by Leandro Lupori!
Revision: https://reviews.llvm.org/D61792
llvm-svn: 360862
From 1c61471ab1cba735f57824ec8a38db845e60ab84
From: Fangrui Song <maskray@google.com>
Date: Wed May 22 07:29:59 2019 +0000
[PPC64] Parse -elfv1 -elfv2 when specified on target triple
Summary:
For big-endian powerpc64, the default ABI is ELFv1. OpenPower ABI ELFv2 is supported when -mabi=elfv2 is specified. FreeBSD support for
PowerPC64 ELFv2 ABI with LLVM is in progress[1]. This patch adds an alternative way to specify ELFv2 ABI on target triple [2].
The following results are expected:
ELFv1 when using:
-target powerpc64-unknown-freebsd12.0
-target powerpc64-unknown-freebsd12.0 -mabi=elfv1
-target powerpc64-unknown-freebsd12.0-elfv1
ELFv2 when using:
-target powerpc64-unknown-freebsd12.0 -mabi=elfv2
-target powerpc64-unknown-freebsd12.0-elfv2
[1] https://wiki.freebsd.org/powerpc/llvm-elfv2
[2] https://clang.llvm.org/docs/CrossCompilation.html
Patch by Alfredo Dal'Ava J<C3><BA>nior!
Revision: https://reviews.llvm.org/D61950
llvm-svn: 361355