<div dir="ltr"><div dir="ltr">On Thu, Jul 11, 2019 at 6:14 AM Shoaib Meenai <<a href="mailto:smeenai@fb.com">smeenai@fb.com</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Would it have been preferable to wait until <a href="https://reviews.llvm.org/D64123" rel="noreferrer" target="_blank">https://reviews.llvm.org/D64123</a> was shipped and/or wait after the branch cut?<br></blockquote><div><br></div><div><a href="https://reviews.llvm.org/D64123">https://reviews.llvm.org/D64123</a> was not intended to be submit, as that tool is for one-time use for converting lld source files. I uploaded the patch so that people who want to run the tool can apply, build and run it locally. For LLVM and Clang, I think I need to create a more comprehensive tool (perhaps based on clang-tidy) because of the size of the source tree, and that may be worth to be submitted, though.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
Do you have plans for doing the same for LLD COFF and WASM?<br></blockquote><div><br></div><div>Yes, I did it already.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
On 7/9/19, 10:00 PM, "llvm-commits on behalf of Rui Ueyama via llvm-commits" <<a href="mailto:llvm-commits-bounces@lists.llvm.org" target="_blank">llvm-commits-bounces@lists.llvm.org</a> on behalf of <a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>> wrote:<br>
<br>
Author: ruiu<br>
Date: Tue Jul 9 22:00:37 2019<br>
New Revision: 365595<br>
<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject-3Frev-3D365595-26view-3Drev&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=wqTgCRPiAjNC5Rq0SnDKS5zZ6aodGwtCQH1Vld_r5Ek&e=" rel="noreferrer" target="_blank">https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject-3Frev-3D365595-26view-3Drev&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=wqTgCRPiAjNC5Rq0SnDKS5zZ6aodGwtCQH1Vld_r5Ek&e=</a> <br>
Log:<br>
[Coding style change] Rename variables so that they start with a lowercase letter<br>
<br>
This patch is mechanically generated by clang-llvm-rename tool that I wrote<br>
using Clang Refactoring Engine just for creating this patch. You can see the<br>
source code of the tool at <a href="https://urldefense.proofpoint.com/v2/url?u=https-3A__reviews.llvm.org_D64123&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=VxGujZlYIyFLpJNWaMTK8u7WOocmQLIu6n9zrBBDLiU&e=" rel="noreferrer" target="_blank">https://urldefense.proofpoint.com/v2/url?u=https-3A__reviews.llvm.org_D64123&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=VxGujZlYIyFLpJNWaMTK8u7WOocmQLIu6n9zrBBDLiU&e=</a> . There's no manual<br>
post-processing; you can generate the same patch by re-running the tool against<br>
lld's code base.<br>
<br>
Here is the main discussion thread to change the LLVM coding style:<br>
<a href="https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.llvm.org_pipermail_llvm-2Ddev_2019-2DFebruary_130083.html&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=RXNHRWMvDBxvLShou_cCnBDQOPg1UZW_ZReoG-h5qRQ&e=" rel="noreferrer" target="_blank">https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.llvm.org_pipermail_llvm-2Ddev_2019-2DFebruary_130083.html&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=RXNHRWMvDBxvLShou_cCnBDQOPg1UZW_ZReoG-h5qRQ&e=</a> <br>
In the discussion thread, I proposed we use lld as a testbed for variable<br>
naming scheme change, and this patch does that.<br>
<br>
I chose to rename variables so that they are in camelCase, just because that<br>
is a minimal change to make variables to start with a lowercase letter.<br>
<br>
Note to downstream patch maintainers: if you are maintaining a downstream lld<br>
repo, just rebasing ahead of this commit would cause massive merge conflicts<br>
because this patch essentially changes every line in the lld subdirectory. But<br>
there's a remedy.<br>
<br>
clang-llvm-rename tool is a batch tool, so you can rename variables in your<br>
downstream repo with the tool. Given that, here is how to rebase your repo to<br>
a commit after the mass renaming:<br>
<br>
1. rebase to the commit just before the mass variable renaming,<br>
2. apply the tool to your downstream repo to mass-rename variables locally, and<br>
3. rebase again to the head.<br>
<br>
Most changes made by the tool should be identical for a downstream repo and<br>
for the head, so at the step 3, almost all changes should be merged and<br>
disappear. I'd expect that there would be some lines that you need to merge by<br>
hand, but that shouldn't be too many.<br>
<br>
Differential Revision: <a href="https://urldefense.proofpoint.com/v2/url?u=https-3A__reviews.llvm.org_D64121&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=OKovn1r-sI6ax8FmjrtKgtOytgB2cD7SxzGUTJ2P-cM&e=" rel="noreferrer" target="_blank">https://urldefense.proofpoint.com/v2/url?u=https-3A__reviews.llvm.org_D64121&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=OKovn1r-sI6ax8FmjrtKgtOytgB2cD7SxzGUTJ2P-cM&e=</a> <br>
<br>
Modified:<br>
lld/trunk/ELF/AArch64ErrataFix.cpp<br>
lld/trunk/ELF/AArch64ErrataFix.h<br>
lld/trunk/ELF/Arch/AArch64.cpp<br>
lld/trunk/ELF/Arch/AMDGPU.cpp<br>
lld/trunk/ELF/Arch/ARM.cpp<br>
lld/trunk/ELF/Arch/AVR.cpp<br>
lld/trunk/ELF/Arch/Hexagon.cpp<br>
lld/trunk/ELF/Arch/MSP430.cpp<br>
lld/trunk/ELF/Arch/Mips.cpp<br>
lld/trunk/ELF/Arch/MipsArchTree.cpp<br>
lld/trunk/ELF/Arch/PPC.cpp<br>
lld/trunk/ELF/Arch/PPC64.cpp<br>
lld/trunk/ELF/Arch/RISCV.cpp<br>
lld/trunk/ELF/Arch/SPARCV9.cpp<br>
lld/trunk/ELF/Arch/X86.cpp<br>
lld/trunk/ELF/Arch/X86_64.cpp<br>
lld/trunk/ELF/CallGraphSort.cpp<br>
lld/trunk/ELF/Config.h<br>
lld/trunk/ELF/DWARF.cpp<br>
lld/trunk/ELF/DWARF.h<br>
lld/trunk/ELF/Driver.cpp<br>
lld/trunk/ELF/Driver.h<br>
lld/trunk/ELF/DriverUtils.cpp<br>
lld/trunk/ELF/EhFrame.cpp<br>
lld/trunk/ELF/EhFrame.h<br>
lld/trunk/ELF/ICF.cpp<br>
lld/trunk/ELF/InputFiles.cpp<br>
lld/trunk/ELF/InputFiles.h<br>
lld/trunk/ELF/InputSection.cpp<br>
lld/trunk/ELF/InputSection.h<br>
lld/trunk/ELF/LTO.cpp<br>
lld/trunk/ELF/LTO.h<br>
lld/trunk/ELF/LinkerScript.cpp<br>
lld/trunk/ELF/LinkerScript.h<br>
lld/trunk/ELF/MapFile.cpp<br>
lld/trunk/ELF/MarkLive.cpp<br>
lld/trunk/ELF/OutputSections.cpp<br>
lld/trunk/ELF/OutputSections.h<br>
lld/trunk/ELF/Relocations.cpp<br>
lld/trunk/ELF/Relocations.h<br>
lld/trunk/ELF/ScriptLexer.cpp<br>
lld/trunk/ELF/ScriptLexer.h<br>
lld/trunk/ELF/ScriptParser.cpp<br>
lld/trunk/ELF/ScriptParser.h<br>
lld/trunk/ELF/SymbolTable.cpp<br>
lld/trunk/ELF/SymbolTable.h<br>
lld/trunk/ELF/Symbols.cpp<br>
lld/trunk/ELF/Symbols.h<br>
lld/trunk/ELF/SyntheticSections.cpp<br>
lld/trunk/ELF/SyntheticSections.h<br>
lld/trunk/ELF/Target.cpp<br>
lld/trunk/ELF/Target.h<br>
lld/trunk/ELF/Thunks.cpp<br>
lld/trunk/ELF/Thunks.h<br>
lld/trunk/ELF/Writer.cpp<br>
lld/trunk/ELF/Writer.h<br>
<br>
Modified: lld/trunk/ELF/AArch64ErrataFix.cpp<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_ELF_AArch64ErrataFix.cpp-3Frev-3D365595-26r1-3D365594-26r2-3D365595-26view-3Ddiff&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=yZ7pbztjcMNajAStaXuE3ZgIj9FgBoapqVmYAtBzt-I&e=" rel="noreferrer" target="_blank">https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_ELF_AArch64ErrataFix.cpp-3Frev-3D365595-26r1-3D365594-26r2-3D365595-26view-3Ddiff&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=yZ7pbztjcMNajAStaXuE3ZgIj9FgBoapqVmYAtBzt-I&e=</a> <br>
==============================================================================<br>
--- lld/trunk/ELF/AArch64ErrataFix.cpp (original)<br>
+++ lld/trunk/ELF/AArch64ErrataFix.cpp Tue Jul 9 22:00:37 2019<br>
@@ -56,8 +56,8 @@ using namespace lld::elf;<br>
<br>
// ADRP<br>
// | 1 | immlo (2) | 1 | 0 0 0 0 | immhi (19) | Rd (5) |<br>
-static bool isADRP(uint32_t Instr) {<br>
- return (Instr & 0x9f000000) == 0x90000000;<br>
+static bool isADRP(uint32_t instr) {<br>
+ return (instr & 0x9f000000) == 0x90000000;<br>
}<br>
<br>
// Load and store bit patterns from ARMv8-A ARM ARM.<br>
@@ -66,8 +66,8 @@ static bool isADRP(uint32_t Instr) {<br>
<br>
// All loads and stores have 1 (at bit postion 27), (0 at bit position 25).<br>
// | op0 x op1 (2) | 1 op2 0 op3 (2) | x | op4 (5) | xxxx | op5 (2) | x (10) |<br>
-static bool isLoadStoreClass(uint32_t Instr) {<br>
- return (Instr & 0x0a000000) == 0x08000000;<br>
+static bool isLoadStoreClass(uint32_t instr) {<br>
+ return (instr & 0x0a000000) == 0x08000000;<br>
}<br>
<br>
// LDN/STN multiple no offset<br>
@@ -82,20 +82,20 @@ static bool isLoadStoreClass(uint32_t In<br>
// opcode == 0110 ST1 3 registers.<br>
// opcode == 0111 ST1 1 register.<br>
// opcode == 1010 ST1 2 registers.<br>
-static bool isST1MultipleOpcode(uint32_t Instr) {<br>
- return (Instr & 0x0000f000) == 0x00002000 ||<br>
- (Instr & 0x0000f000) == 0x00006000 ||<br>
- (Instr & 0x0000f000) == 0x00007000 ||<br>
- (Instr & 0x0000f000) == 0x0000a000;<br>
+static bool isST1MultipleOpcode(uint32_t instr) {<br>
+ return (instr & 0x0000f000) == 0x00002000 ||<br>
+ (instr & 0x0000f000) == 0x00006000 ||<br>
+ (instr & 0x0000f000) == 0x00007000 ||<br>
+ (instr & 0x0000f000) == 0x0000a000;<br>
}<br>
<br>
-static bool isST1Multiple(uint32_t Instr) {<br>
- return (Instr & 0xbfff0000) == 0x0c000000 && isST1MultipleOpcode(Instr);<br>
+static bool isST1Multiple(uint32_t instr) {<br>
+ return (instr & 0xbfff0000) == 0x0c000000 && isST1MultipleOpcode(instr);<br>
}<br>
<br>
// Writes to Rn (writeback).<br>
-static bool isST1MultiplePost(uint32_t Instr) {<br>
- return (Instr & 0xbfe00000) == 0x0c800000 && isST1MultipleOpcode(Instr);<br>
+static bool isST1MultiplePost(uint32_t instr) {<br>
+ return (instr & 0xbfe00000) == 0x0c800000 && isST1MultipleOpcode(instr);<br>
}<br>
<br>
// LDN/STN single no offset<br>
@@ -110,41 +110,41 @@ static bool isST1MultiplePost(uint32_t I<br>
// opcode == 000 ST1 8-bit.<br>
// opcode == 010 ST1 16-bit.<br>
// opcode == 100 ST1 32 or 64-bit (Size determines which).<br>
-static bool isST1SingleOpcode(uint32_t Instr) {<br>
- return (Instr & 0x0040e000) == 0x00000000 ||<br>
- (Instr & 0x0040e000) == 0x00004000 ||<br>
- (Instr & 0x0040e000) == 0x00008000;<br>
+static bool isST1SingleOpcode(uint32_t instr) {<br>
+ return (instr & 0x0040e000) == 0x00000000 ||<br>
+ (instr & 0x0040e000) == 0x00004000 ||<br>
+ (instr & 0x0040e000) == 0x00008000;<br>
}<br>
<br>
-static bool isST1Single(uint32_t Instr) {<br>
- return (Instr & 0xbfff0000) == 0x0d000000 && isST1SingleOpcode(Instr);<br>
+static bool isST1Single(uint32_t instr) {<br>
+ return (instr & 0xbfff0000) == 0x0d000000 && isST1SingleOpcode(instr);<br>
}<br>
<br>
// Writes to Rn (writeback).<br>
-static bool isST1SinglePost(uint32_t Instr) {<br>
- return (Instr & 0xbfe00000) == 0x0d800000 && isST1SingleOpcode(Instr);<br>
+static bool isST1SinglePost(uint32_t instr) {<br>
+ return (instr & 0xbfe00000) == 0x0d800000 && isST1SingleOpcode(instr);<br>
}<br>
<br>
-static bool isST1(uint32_t Instr) {<br>
- return isST1Multiple(Instr) || isST1MultiplePost(Instr) ||<br>
- isST1Single(Instr) || isST1SinglePost(Instr);<br>
+static bool isST1(uint32_t instr) {<br>
+ return isST1Multiple(instr) || isST1MultiplePost(instr) ||<br>
+ isST1Single(instr) || isST1SinglePost(instr);<br>
}<br>
<br>
// Load/store exclusive<br>
// | size (2) 00 | 1000 | o2 L o1 | Rs (5) | o0 | Rt2 (5) | Rn (5) | Rt (5) |<br>
// L == 0 for Stores.<br>
-static bool isLoadStoreExclusive(uint32_t Instr) {<br>
- return (Instr & 0x3f000000) == 0x08000000;<br>
+static bool isLoadStoreExclusive(uint32_t instr) {<br>
+ return (instr & 0x3f000000) == 0x08000000;<br>
}<br>
<br>
-static bool isLoadExclusive(uint32_t Instr) {<br>
- return (Instr & 0x3f400000) == 0x08400000;<br>
+static bool isLoadExclusive(uint32_t instr) {<br>
+ return (instr & 0x3f400000) == 0x08400000;<br>
}<br>
<br>
// Load register literal<br>
// | opc (2) 01 | 1 V 00 | imm19 | Rt (5) |<br>
-static bool isLoadLiteral(uint32_t Instr) {<br>
- return (Instr & 0x3b000000) == 0x18000000;<br>
+static bool isLoadLiteral(uint32_t instr) {<br>
+ return (instr & 0x3b000000) == 0x18000000;<br>
}<br>
<br>
// Load/store no-allocate pair<br>
@@ -152,8 +152,8 @@ static bool isLoadLiteral(uint32_t Instr<br>
// | opc (2) 10 | 1 V 00 | 0 L | imm7 | Rt2 (5) | Rn (5) | Rt (5) |<br>
// L == 0 for stores.<br>
// Never writes to register<br>
-static bool isSTNP(uint32_t Instr) {<br>
- return (Instr & 0x3bc00000) == 0x28000000;<br>
+static bool isSTNP(uint32_t instr) {<br>
+ return (instr & 0x3bc00000) == 0x28000000;<br>
}<br>
<br>
// Load/store register pair<br>
@@ -161,69 +161,69 @@ static bool isSTNP(uint32_t Instr) {<br>
// | opc (2) 10 | 1 V 00 | 1 L | imm7 | Rt2 (5) | Rn (5) | Rt (5) |<br>
// L == 0 for stores, V == 0 for Scalar, V == 1 for Simd/FP<br>
// Writes to Rn.<br>
-static bool isSTPPost(uint32_t Instr) {<br>
- return (Instr & 0x3bc00000) == 0x28800000;<br>
+static bool isSTPPost(uint32_t instr) {<br>
+ return (instr & 0x3bc00000) == 0x28800000;<br>
}<br>
<br>
// (offset)<br>
// | opc (2) 10 | 1 V 01 | 0 L | imm7 | Rt2 (5) | Rn (5) | Rt (5) |<br>
-static bool isSTPOffset(uint32_t Instr) {<br>
- return (Instr & 0x3bc00000) == 0x29000000;<br>
+static bool isSTPOffset(uint32_t instr) {<br>
+ return (instr & 0x3bc00000) == 0x29000000;<br>
}<br>
<br>
// (pre-index)<br>
// | opc (2) 10 | 1 V 01 | 1 L | imm7 | Rt2 (5) | Rn (5) | Rt (5) |<br>
// Writes to Rn.<br>
-static bool isSTPPre(uint32_t Instr) {<br>
- return (Instr & 0x3bc00000) == 0x29800000;<br>
+static bool isSTPPre(uint32_t instr) {<br>
+ return (instr & 0x3bc00000) == 0x29800000;<br>
}<br>
<br>
-static bool isSTP(uint32_t Instr) {<br>
- return isSTPPost(Instr) || isSTPOffset(Instr) || isSTPPre(Instr);<br>
+static bool isSTP(uint32_t instr) {<br>
+ return isSTPPost(instr) || isSTPOffset(instr) || isSTPPre(instr);<br>
}<br>
<br>
// Load/store register (unscaled immediate)<br>
// | size (2) 11 | 1 V 00 | opc (2) 0 | imm9 | 00 | Rn (5) | Rt (5) |<br>
// V == 0 for Scalar, V == 1 for Simd/FP.<br>
-static bool isLoadStoreUnscaled(uint32_t Instr) {<br>
- return (Instr & 0x3b000c00) == 0x38000000;<br>
+static bool isLoadStoreUnscaled(uint32_t instr) {<br>
+ return (instr & 0x3b000c00) == 0x38000000;<br>
}<br>
<br>
// Load/store register (immediate post-indexed)<br>
// | size (2) 11 | 1 V 00 | opc (2) 0 | imm9 | 01 | Rn (5) | Rt (5) |<br>
-static bool isLoadStoreImmediatePost(uint32_t Instr) {<br>
- return (Instr & 0x3b200c00) == 0x38000400;<br>
+static bool isLoadStoreImmediatePost(uint32_t instr) {<br>
+ return (instr & 0x3b200c00) == 0x38000400;<br>
}<br>
<br>
// Load/store register (unprivileged)<br>
// | size (2) 11 | 1 V 00 | opc (2) 0 | imm9 | 10 | Rn (5) | Rt (5) |<br>
-static bool isLoadStoreUnpriv(uint32_t Instr) {<br>
- return (Instr & 0x3b200c00) == 0x38000800;<br>
+static bool isLoadStoreUnpriv(uint32_t instr) {<br>
+ return (instr & 0x3b200c00) == 0x38000800;<br>
}<br>
<br>
// Load/store register (immediate pre-indexed)<br>
// | size (2) 11 | 1 V 00 | opc (2) 0 | imm9 | 11 | Rn (5) | Rt (5) |<br>
-static bool isLoadStoreImmediatePre(uint32_t Instr) {<br>
- return (Instr & 0x3b200c00) == 0x38000c00;<br>
+static bool isLoadStoreImmediatePre(uint32_t instr) {<br>
+ return (instr & 0x3b200c00) == 0x38000c00;<br>
}<br>
<br>
// Load/store register (register offset)<br>
// | size (2) 11 | 1 V 00 | opc (2) 1 | Rm (5) | option (3) S | 10 | Rn | Rt |<br>
-static bool isLoadStoreRegisterOff(uint32_t Instr) {<br>
- return (Instr & 0x3b200c00) == 0x38200800;<br>
+static bool isLoadStoreRegisterOff(uint32_t instr) {<br>
+ return (instr & 0x3b200c00) == 0x38200800;<br>
}<br>
<br>
// Load/store register (unsigned immediate)<br>
// | size (2) 11 | 1 V 01 | opc (2) | imm12 | Rn (5) | Rt (5) |<br>
-static bool isLoadStoreRegisterUnsigned(uint32_t Instr) {<br>
- return (Instr & 0x3b000000) == 0x39000000;<br>
+static bool isLoadStoreRegisterUnsigned(uint32_t instr) {<br>
+ return (instr & 0x3b000000) == 0x39000000;<br>
}<br>
<br>
// Rt is always in bit position 0 - 4.<br>
-static uint32_t getRt(uint32_t Instr) { return (Instr & 0x1f); }<br>
+static uint32_t getRt(uint32_t instr) { return (instr & 0x1f); }<br>
<br>
// Rn is always in bit position 5 - 9.<br>
-static uint32_t getRn(uint32_t Instr) { return (Instr >> 5) & 0x1f; }<br>
+static uint32_t getRn(uint32_t instr) { return (instr >> 5) & 0x1f; }<br>
<br>
// C4.1.2 Branches, Exception Generating and System instructions<br>
// | op0 (3) 1 | 01 op1 (4) | x (22) |<br>
@@ -232,41 +232,41 @@ static uint32_t getRn(uint32_t Instr) {<br>
// op0 == x00 101 op1 == xxxx Unconditional Branch immediate.<br>
// op0 == x01 101 op1 == 0xxx Compare and branch immediate.<br>
// op0 == x01 101 op1 == 1xxx Test and branch immediate.<br>
-static bool isBranch(uint32_t Instr) {<br>
- return ((Instr & 0xfe000000) == 0xd6000000) || // Cond branch.<br>
- ((Instr & 0xfe000000) == 0x54000000) || // Uncond branch reg.<br>
- ((Instr & 0x7c000000) == 0x14000000) || // Uncond branch imm.<br>
- ((Instr & 0x7c000000) == 0x34000000); // Compare and test branch.<br>
+static bool isBranch(uint32_t instr) {<br>
+ return ((instr & 0xfe000000) == 0xd6000000) || // Cond branch.<br>
+ ((instr & 0xfe000000) == 0x54000000) || // Uncond branch reg.<br>
+ ((instr & 0x7c000000) == 0x14000000) || // Uncond branch imm.<br>
+ ((instr & 0x7c000000) == 0x34000000); // Compare and test branch.<br>
}<br>
<br>
-static bool isV8SingleRegisterNonStructureLoadStore(uint32_t Instr) {<br>
- return isLoadStoreUnscaled(Instr) || isLoadStoreImmediatePost(Instr) ||<br>
- isLoadStoreUnpriv(Instr) || isLoadStoreImmediatePre(Instr) ||<br>
- isLoadStoreRegisterOff(Instr) || isLoadStoreRegisterUnsigned(Instr);<br>
+static bool isV8SingleRegisterNonStructureLoadStore(uint32_t instr) {<br>
+ return isLoadStoreUnscaled(instr) || isLoadStoreImmediatePost(instr) ||<br>
+ isLoadStoreUnpriv(instr) || isLoadStoreImmediatePre(instr) ||<br>
+ isLoadStoreRegisterOff(instr) || isLoadStoreRegisterUnsigned(instr);<br>
}<br>
<br>
// Note that this function refers to v8.0 only and does not include the<br>
// additional load and store instructions added for in later revisions of<br>
// the architecture such as the Atomic memory operations introduced<br>
// in v8.1.<br>
-static bool isV8NonStructureLoad(uint32_t Instr) {<br>
- if (isLoadExclusive(Instr))<br>
+static bool isV8NonStructureLoad(uint32_t instr) {<br>
+ if (isLoadExclusive(instr))<br>
return true;<br>
- if (isLoadLiteral(Instr))<br>
+ if (isLoadLiteral(instr))<br>
return true;<br>
- else if (isV8SingleRegisterNonStructureLoadStore(Instr)) {<br>
+ else if (isV8SingleRegisterNonStructureLoadStore(instr)) {<br>
// For Load and Store single register, Loads are derived from a<br>
// combination of the Size, V and Opc fields.<br>
- uint32_t Size = (Instr >> 30) & 0xff;<br>
- uint32_t V = (Instr >> 26) & 0x1;<br>
- uint32_t Opc = (Instr >> 22) & 0x3;<br>
+ uint32_t size = (instr >> 30) & 0xff;<br>
+ uint32_t v = (instr >> 26) & 0x1;<br>
+ uint32_t opc = (instr >> 22) & 0x3;<br>
// For the load and store instructions that we are decoding.<br>
// Opc == 0 are all stores.<br>
// Opc == 1 with a couple of exceptions are loads. The exceptions are:<br>
// Size == 00 (0), V == 1, Opc == 10 (2) which is a store and<br>
// Size == 11 (3), V == 0, Opc == 10 (2) which is a prefetch.<br>
- return Opc != 0 && !(Size == 0 && V == 1 && Opc == 2) &&<br>
- !(Size == 3 && V == 0 && Opc == 2);<br>
+ return opc != 0 && !(size == 0 && v == 1 && opc == 2) &&<br>
+ !(size == 3 && v == 0 && opc == 2);<br>
}<br>
return false;<br>
}<br>
@@ -275,18 +275,18 @@ static bool isV8NonStructureLoad(uint32_<br>
// needed for errata 843419.<br>
<br>
// Instruction with writeback updates the index register after the load/store.<br>
-static bool hasWriteback(uint32_t Instr) {<br>
- return isLoadStoreImmediatePre(Instr) || isLoadStoreImmediatePost(Instr) ||<br>
- isSTPPre(Instr) || isSTPPost(Instr) || isST1SinglePost(Instr) ||<br>
- isST1MultiplePost(Instr);<br>
+static bool hasWriteback(uint32_t instr) {<br>
+ return isLoadStoreImmediatePre(instr) || isLoadStoreImmediatePost(instr) ||<br>
+ isSTPPre(instr) || isSTPPost(instr) || isST1SinglePost(instr) ||<br>
+ isST1MultiplePost(instr);<br>
}<br>
<br>
// For the load and store class of instructions, a load can write to the<br>
// destination register, a load and a store can write to the base register when<br>
// the instruction has writeback.<br>
-static bool doesLoadStoreWriteToReg(uint32_t Instr, uint32_t Reg) {<br>
- return (isV8NonStructureLoad(Instr) && getRt(Instr) == Reg) ||<br>
- (hasWriteback(Instr) && getRn(Instr) == Reg);<br>
+static bool doesLoadStoreWriteToReg(uint32_t instr, uint32_t reg) {<br>
+ return (isV8NonStructureLoad(instr) && getRt(instr) == reg) ||<br>
+ (hasWriteback(instr) && getRn(instr) == reg);<br>
}<br>
<br>
// Scanner for Cortex-A53 errata 843419<br>
@@ -318,18 +318,18 @@ static bool doesLoadStoreWriteToReg(uint<br>
// Return true if the Instruction sequence Adrp, Instr2, and Instr4 match<br>
// the erratum sequence. The Adrp, Instr2 and Instr4 correspond to 1.), 2.),<br>
// and 4.) in the Scanner for Cortex-A53 errata comment above.<br>
-static bool is843419ErratumSequence(uint32_t Instr1, uint32_t Instr2,<br>
- uint32_t Instr4) {<br>
- if (!isADRP(Instr1))<br>
+static bool is843419ErratumSequence(uint32_t instr1, uint32_t instr2,<br>
+ uint32_t instr4) {<br>
+ if (!isADRP(instr1))<br>
return false;<br>
<br>
- uint32_t Rn = getRt(Instr1);<br>
- return isLoadStoreClass(Instr2) &&<br>
- (isLoadStoreExclusive(Instr2) || isLoadLiteral(Instr2) ||<br>
- isV8SingleRegisterNonStructureLoadStore(Instr2) || isSTP(Instr2) ||<br>
- isSTNP(Instr2) || isST1(Instr2)) &&<br>
- !doesLoadStoreWriteToReg(Instr2, Rn) &&<br>
- isLoadStoreRegisterUnsigned(Instr4) && getRn(Instr4) == Rn;<br>
+ uint32_t rn = getRt(instr1);<br>
+ return isLoadStoreClass(instr2) &&<br>
+ (isLoadStoreExclusive(instr2) || isLoadLiteral(instr2) ||<br>
+ isV8SingleRegisterNonStructureLoadStore(instr2) || isSTP(instr2) ||<br>
+ isSTNP(instr2) || isST1(instr2)) &&<br>
+ !doesLoadStoreWriteToReg(instr2, rn) &&<br>
+ isLoadStoreRegisterUnsigned(instr4) && getRn(instr4) == rn;<br>
}<br>
<br>
// Scan the instruction sequence starting at Offset Off from the base of<br>
@@ -338,89 +338,89 @@ static bool is843419ErratumSequence(uint<br>
// instructions we've scanned.<br>
// Return the offset of the load or store instruction in IS that we want to<br>
// patch or 0 if no patch required.<br>
-static uint64_t scanCortexA53Errata843419(InputSection *IS, uint64_t &Off,<br>
- uint64_t Limit) {<br>
- uint64_t ISAddr = IS->getVA(0);<br>
+static uint64_t scanCortexA53Errata843419(InputSection *isec, uint64_t &off,<br>
+ uint64_t limit) {<br>
+ uint64_t isecAddr = isec->getVA(0);<br>
<br>
// Advance Off so that (ISAddr + Off) modulo 0x1000 is at least 0xff8.<br>
- uint64_t InitialPageOff = (ISAddr + Off) & 0xfff;<br>
- if (InitialPageOff < 0xff8)<br>
- Off += 0xff8 - InitialPageOff;<br>
+ uint64_t initialPageOff = (isecAddr + off) & 0xfff;<br>
+ if (initialPageOff < 0xff8)<br>
+ off += 0xff8 - initialPageOff;<br>
<br>
- bool OptionalAllowed = Limit - Off > 12;<br>
- if (Off >= Limit || Limit - Off < 12) {<br>
+ bool optionalAllowed = limit - off > 12;<br>
+ if (off >= limit || limit - off < 12) {<br>
// Need at least 3 4-byte sized instructions to trigger erratum.<br>
- Off = Limit;<br>
+ off = limit;<br>
return 0;<br>
}<br>
<br>
- uint64_t PatchOff = 0;<br>
- const uint8_t *Buf = IS->data().begin();<br>
- const ulittle32_t *InstBuf = reinterpret_cast<const ulittle32_t *>(Buf + Off);<br>
- uint32_t Instr1 = *InstBuf++;<br>
- uint32_t Instr2 = *InstBuf++;<br>
- uint32_t Instr3 = *InstBuf++;<br>
- if (is843419ErratumSequence(Instr1, Instr2, Instr3)) {<br>
- PatchOff = Off + 8;<br>
- } else if (OptionalAllowed && !isBranch(Instr3)) {<br>
- uint32_t Instr4 = *InstBuf++;<br>
- if (is843419ErratumSequence(Instr1, Instr2, Instr4))<br>
- PatchOff = Off + 12;<br>
+ uint64_t patchOff = 0;<br>
+ const uint8_t *buf = isec->data().begin();<br>
+ const ulittle32_t *instBuf = reinterpret_cast<const ulittle32_t *>(buf + off);<br>
+ uint32_t instr1 = *instBuf++;<br>
+ uint32_t instr2 = *instBuf++;<br>
+ uint32_t instr3 = *instBuf++;<br>
+ if (is843419ErratumSequence(instr1, instr2, instr3)) {<br>
+ patchOff = off + 8;<br>
+ } else if (optionalAllowed && !isBranch(instr3)) {<br>
+ uint32_t instr4 = *instBuf++;<br>
+ if (is843419ErratumSequence(instr1, instr2, instr4))<br>
+ patchOff = off + 12;<br>
}<br>
- if (((ISAddr + Off) & 0xfff) == 0xff8)<br>
- Off += 4;<br>
+ if (((isecAddr + off) & 0xfff) == 0xff8)<br>
+ off += 4;<br>
else<br>
- Off += 0xffc;<br>
- return PatchOff;<br>
+ off += 0xffc;<br>
+ return patchOff;<br>
}<br>
<br>
class lld::elf::Patch843419Section : public SyntheticSection {<br>
public:<br>
- Patch843419Section(InputSection *P, uint64_t Off);<br>
+ Patch843419Section(InputSection *p, uint64_t off);<br>
<br>
- void writeTo(uint8_t *Buf) override;<br>
+ void writeTo(uint8_t *buf) override;<br>
<br>
size_t getSize() const override { return 8; }<br>
<br>
uint64_t getLDSTAddr() const;<br>
<br>
// The Section we are patching.<br>
- const InputSection *Patchee;<br>
+ const InputSection *patchee;<br>
// The offset of the instruction in the Patchee section we are patching.<br>
- uint64_t PatcheeOffset;<br>
+ uint64_t patcheeOffset;<br>
// A label for the start of the Patch that we can use as a relocation target.<br>
- Symbol *PatchSym;<br>
+ Symbol *patchSym;<br>
};<br>
<br>
-lld::elf::Patch843419Section::Patch843419Section(InputSection *P, uint64_t Off)<br>
+lld::elf::Patch843419Section::Patch843419Section(InputSection *p, uint64_t off)<br>
: SyntheticSection(SHF_ALLOC | SHF_EXECINSTR, SHT_PROGBITS, 4,<br>
".text.patch"),<br>
- Patchee(P), PatcheeOffset(Off) {<br>
- this->Parent = P->getParent();<br>
- PatchSym = addSyntheticLocal(<br>
+ patchee(p), patcheeOffset(off) {<br>
+ this->parent = p->getParent();<br>
+ patchSym = addSyntheticLocal(<br>
Saver.save("__CortexA53843419_" + utohexstr(getLDSTAddr())), STT_FUNC, 0,<br>
getSize(), *this);<br>
addSyntheticLocal(Saver.save("$x"), STT_NOTYPE, 0, 0, *this);<br>
}<br>
<br>
uint64_t lld::elf::Patch843419Section::getLDSTAddr() const {<br>
- return Patchee->getVA(PatcheeOffset);<br>
+ return patchee->getVA(patcheeOffset);<br>
}<br>
<br>
-void lld::elf::Patch843419Section::writeTo(uint8_t *Buf) {<br>
+void lld::elf::Patch843419Section::writeTo(uint8_t *buf) {<br>
// Copy the instruction that we will be replacing with a branch in the<br>
// Patchee Section.<br>
- write32le(Buf, read32le(Patchee->data().begin() + PatcheeOffset));<br>
+ write32le(buf, read32le(patchee->data().begin() + patcheeOffset));<br>
<br>
// Apply any relocation transferred from the original PatcheeSection.<br>
// For a SyntheticSection Buf already has OutSecOff added, but relocateAlloc<br>
// also adds OutSecOff so we need to subtract to avoid double counting.<br>
- this->relocateAlloc(Buf - OutSecOff, Buf - OutSecOff + getSize());<br>
+ this->relocateAlloc(buf - outSecOff, buf - outSecOff + getSize());<br>
<br>
// Return address is the next instruction after the one we have just copied.<br>
- uint64_t S = getLDSTAddr() + 4;<br>
- uint64_t P = PatchSym->getVA() + 4;<br>
- Target->relocateOne(Buf + 4, R_AARCH64_JUMP26, S - P);<br>
+ uint64_t s = getLDSTAddr() + 4;<br>
+ uint64_t p = patchSym->getVA() + 4;<br>
+ target->relocateOne(buf + 4, R_AARCH64_JUMP26, s - p);<br>
}<br>
<br>
void AArch64Err843419Patcher::init() {<br>
@@ -434,47 +434,47 @@ void AArch64Err843419Patcher::init() {<br>
// within sections. If there is no next symbol then the half open interval is<br>
// [Symbol Value, End of section). The type, code or data, is determined by<br>
// the mapping symbol name, $x for code, $d for data.<br>
- auto IsCodeMapSymbol = [](const Symbol *B) {<br>
- return B->getName() == "$x" || B->getName().startswith("$x.");<br>
+ auto isCodeMapSymbol = [](const Symbol *b) {<br>
+ return b->getName() == "$x" || b->getName().startswith("$x.");<br>
};<br>
- auto IsDataMapSymbol = [](const Symbol *B) {<br>
- return B->getName() == "$d" || B->getName().startswith("$d.");<br>
+ auto isDataMapSymbol = [](const Symbol *b) {<br>
+ return b->getName() == "$d" || b->getName().startswith("$d.");<br>
};<br>
<br>
// Collect mapping symbols for every executable InputSection.<br>
- for (InputFile *File : ObjectFiles) {<br>
- auto *F = cast<ObjFile<ELF64LE>>(File);<br>
- for (Symbol *B : F->getLocalSymbols()) {<br>
- auto *Def = dyn_cast<Defined>(B);<br>
- if (!Def)<br>
+ for (InputFile *file : objectFiles) {<br>
+ auto *f = cast<ObjFile<ELF64LE>>(file);<br>
+ for (Symbol *b : f->getLocalSymbols()) {<br>
+ auto *def = dyn_cast<Defined>(b);<br>
+ if (!def)<br>
continue;<br>
- if (!IsCodeMapSymbol(Def) && !IsDataMapSymbol(Def))<br>
+ if (!isCodeMapSymbol(def) && !isDataMapSymbol(def))<br>
continue;<br>
- if (auto *Sec = dyn_cast_or_null<InputSection>(Def->Section))<br>
- if (Sec->Flags & SHF_EXECINSTR)<br>
- SectionMap[Sec].push_back(Def);<br>
+ if (auto *sec = dyn_cast_or_null<InputSection>(def->section))<br>
+ if (sec->flags & SHF_EXECINSTR)<br>
+ sectionMap[sec].push_back(def);<br>
}<br>
}<br>
// For each InputSection make sure the mapping symbols are in sorted in<br>
// ascending order and free from consecutive runs of mapping symbols with<br>
// the same type. For example we must remove the redundant $d.1 from $x.0<br>
// $d.0 $d.1 $x.1.<br>
- for (auto &KV : SectionMap) {<br>
- std::vector<const Defined *> &MapSyms = KV.second;<br>
- if (MapSyms.size() <= 1)<br>
+ for (auto &kv : sectionMap) {<br>
+ std::vector<const Defined *> &mapSyms = kv.second;<br>
+ if (mapSyms.size() <= 1)<br>
continue;<br>
- llvm::stable_sort(MapSyms, [](const Defined *A, const Defined *B) {<br>
- return A->Value < B->Value;<br>
+ llvm::stable_sort(mapSyms, [](const Defined *a, const Defined *b) {<br>
+ return a->value < b->value;<br>
});<br>
- MapSyms.erase(<br>
- std::unique(MapSyms.begin(), MapSyms.end(),<br>
- [=](const Defined *A, const Defined *B) {<br>
- return (IsCodeMapSymbol(A) && IsCodeMapSymbol(B)) ||<br>
- (IsDataMapSymbol(A) && IsDataMapSymbol(B));<br>
+ mapSyms.erase(<br>
+ std::unique(mapSyms.begin(), mapSyms.end(),<br>
+ [=](const Defined *a, const Defined *b) {<br>
+ return (isCodeMapSymbol(a) && isCodeMapSymbol(b)) ||<br>
+ (isDataMapSymbol(a) && isDataMapSymbol(b));<br>
}),<br>
- MapSyms.end());<br>
+ mapSyms.end());<br>
}<br>
- Initialized = true;<br>
+ initialized = true;<br>
}<br>
<br>
// Insert the PatchSections we have created back into the<br>
@@ -483,60 +483,60 @@ void AArch64Err843419Patcher::init() {<br>
// executable sections, although we may need to insert them earlier if the<br>
// InputSectionDescription is larger than the maximum branch range.<br>
void AArch64Err843419Patcher::insertPatches(<br>
- InputSectionDescription &ISD, std::vector<Patch843419Section *> &Patches) {<br>
- uint64_t ISLimit;<br>
- uint64_t PrevISLimit = ISD.Sections.front()->OutSecOff;<br>
- uint64_t PatchUpperBound = PrevISLimit + Target->getThunkSectionSpacing();<br>
- uint64_t OutSecAddr = ISD.Sections.front()->getParent()->Addr;<br>
+ InputSectionDescription &isd, std::vector<Patch843419Section *> &patches) {<br>
+ uint64_t isecLimit;<br>
+ uint64_t prevISLimit = isd.sections.front()->outSecOff;<br>
+ uint64_t patchUpperBound = prevISLimit + target->getThunkSectionSpacing();<br>
+ uint64_t outSecAddr = isd.sections.front()->getParent()->addr;<br>
<br>
// Set the OutSecOff of patches to the place where we want to insert them.<br>
// We use a similar strategy to Thunk placement. Place patches roughly<br>
// every multiple of maximum branch range.<br>
- auto PatchIt = Patches.begin();<br>
- auto PatchEnd = Patches.end();<br>
- for (const InputSection *IS : ISD.Sections) {<br>
- ISLimit = IS->OutSecOff + IS->getSize();<br>
- if (ISLimit > PatchUpperBound) {<br>
- while (PatchIt != PatchEnd) {<br>
- if ((*PatchIt)->getLDSTAddr() - OutSecAddr >= PrevISLimit)<br>
+ auto patchIt = patches.begin();<br>
+ auto patchEnd = patches.end();<br>
+ for (const InputSection *isec : isd.sections) {<br>
+ isecLimit = isec->outSecOff + isec->getSize();<br>
+ if (isecLimit > patchUpperBound) {<br>
+ while (patchIt != patchEnd) {<br>
+ if ((*patchIt)->getLDSTAddr() - outSecAddr >= prevISLimit)<br>
break;<br>
- (*PatchIt)->OutSecOff = PrevISLimit;<br>
- ++PatchIt;<br>
+ (*patchIt)->outSecOff = prevISLimit;<br>
+ ++patchIt;<br>
}<br>
- PatchUpperBound = PrevISLimit + Target->getThunkSectionSpacing();<br>
+ patchUpperBound = prevISLimit + target->getThunkSectionSpacing();<br>
}<br>
- PrevISLimit = ISLimit;<br>
+ prevISLimit = isecLimit;<br>
}<br>
- for (; PatchIt != PatchEnd; ++PatchIt) {<br>
- (*PatchIt)->OutSecOff = ISLimit;<br>
+ for (; patchIt != patchEnd; ++patchIt) {<br>
+ (*patchIt)->outSecOff = isecLimit;<br>
}<br>
<br>
// merge all patch sections. We use the OutSecOff assigned above to<br>
// determine the insertion point. This is ok as we only merge into an<br>
// InputSectionDescription once per pass, and at the end of the pass<br>
// assignAddresses() will recalculate all the OutSecOff values.<br>
- std::vector<InputSection *> Tmp;<br>
- Tmp.reserve(ISD.Sections.size() + Patches.size());<br>
- auto MergeCmp = [](const InputSection *A, const InputSection *B) {<br>
- if (A->OutSecOff < B->OutSecOff)<br>
+ std::vector<InputSection *> tmp;<br>
+ tmp.reserve(isd.sections.size() + patches.size());<br>
+ auto mergeCmp = [](const InputSection *a, const InputSection *b) {<br>
+ if (a->outSecOff < b->outSecOff)<br>
return true;<br>
- if (A->OutSecOff == B->OutSecOff && isa<Patch843419Section>(A) &&<br>
- !isa<Patch843419Section>(B))<br>
+ if (a->outSecOff == b->outSecOff && isa<Patch843419Section>(a) &&<br>
+ !isa<Patch843419Section>(b))<br>
return true;<br>
return false;<br>
};<br>
- std::merge(ISD.Sections.begin(), ISD.Sections.end(), Patches.begin(),<br>
- Patches.end(), std::back_inserter(Tmp), MergeCmp);<br>
- ISD.Sections = std::move(Tmp);<br>
+ std::merge(isd.sections.begin(), isd.sections.end(), patches.begin(),<br>
+ patches.end(), std::back_inserter(tmp), mergeCmp);<br>
+ isd.sections = std::move(tmp);<br>
}<br>
<br>
// Given an erratum sequence that starts at address AdrpAddr, with an<br>
// instruction that we need to patch at PatcheeOffset from the start of<br>
// InputSection IS, create a Patch843419 Section and add it to the<br>
// Patches that we need to insert.<br>
-static void implementPatch(uint64_t AdrpAddr, uint64_t PatcheeOffset,<br>
- InputSection *IS,<br>
- std::vector<Patch843419Section *> &Patches) {<br>
+static void implementPatch(uint64_t adrpAddr, uint64_t patcheeOffset,<br>
+ InputSection *isec,<br>
+ std::vector<Patch843419Section *> &patches) {<br>
// There may be a relocation at the same offset that we are patching. There<br>
// are four cases that we need to consider.<br>
// Case 1: R_AARCH64_JUMP26 branch relocation. We have already patched this<br>
@@ -551,29 +551,29 @@ static void implementPatch(uint64_t Adrp<br>
// and replace the relocation with a R_AARCH_JUMP26 branch relocation.<br>
// Case 4: No relocation. We must create a new R_AARCH64_JUMP26 branch<br>
// relocation at the offset.<br>
- auto RelIt = llvm::find_if(IS->Relocations, [=](const Relocation &R) {<br>
- return R.Offset == PatcheeOffset;<br>
+ auto relIt = llvm::find_if(isec->relocations, [=](const Relocation &r) {<br>
+ return r.offset == patcheeOffset;<br>
});<br>
- if (RelIt != IS->Relocations.end() &&<br>
- (RelIt->Type == R_AARCH64_JUMP26 || RelIt->Expr == R_RELAX_TLS_IE_TO_LE))<br>
+ if (relIt != isec->relocations.end() &&<br>
+ (relIt->type == R_AARCH64_JUMP26 || relIt->expr == R_RELAX_TLS_IE_TO_LE))<br>
return;<br>
<br>
log("detected cortex-a53-843419 erratum sequence starting at " +<br>
- utohexstr(AdrpAddr) + " in unpatched output.");<br>
+ utohexstr(adrpAddr) + " in unpatched output.");<br>
<br>
- auto *PS = make<Patch843419Section>(IS, PatcheeOffset);<br>
- Patches.push_back(PS);<br>
+ auto *ps = make<Patch843419Section>(isec, patcheeOffset);<br>
+ patches.push_back(ps);<br>
<br>
- auto MakeRelToPatch = [](uint64_t Offset, Symbol *PatchSym) {<br>
- return Relocation{R_PC, R_AARCH64_JUMP26, Offset, 0, PatchSym};<br>
+ auto makeRelToPatch = [](uint64_t offset, Symbol *patchSym) {<br>
+ return Relocation{R_PC, R_AARCH64_JUMP26, offset, 0, patchSym};<br>
};<br>
<br>
- if (RelIt != IS->Relocations.end()) {<br>
- PS->Relocations.push_back(<br>
- {RelIt->Expr, RelIt->Type, 0, RelIt->Addend, RelIt->Sym});<br>
- *RelIt = MakeRelToPatch(PatcheeOffset, PS->PatchSym);<br>
+ if (relIt != isec->relocations.end()) {<br>
+ ps->relocations.push_back(<br>
+ {relIt->expr, relIt->type, 0, relIt->addend, relIt->sym});<br>
+ *relIt = makeRelToPatch(patcheeOffset, ps->patchSym);<br>
} else<br>
- IS->Relocations.push_back(MakeRelToPatch(PatcheeOffset, PS->PatchSym));<br>
+ isec->relocations.push_back(makeRelToPatch(patcheeOffset, ps->patchSym));<br>
}<br>
<br>
// Scan all the instructions in InputSectionDescription, for each instance of<br>
@@ -581,40 +581,40 @@ static void implementPatch(uint64_t Adrp<br>
// Patch843419Sections that need to be applied to ISD.<br>
std::vector<Patch843419Section *><br>
AArch64Err843419Patcher::patchInputSectionDescription(<br>
- InputSectionDescription &ISD) {<br>
- std::vector<Patch843419Section *> Patches;<br>
- for (InputSection *IS : ISD.Sections) {<br>
+ InputSectionDescription &isd) {<br>
+ std::vector<Patch843419Section *> patches;<br>
+ for (InputSection *isec : isd.sections) {<br>
// LLD doesn't use the erratum sequence in SyntheticSections.<br>
- if (isa<SyntheticSection>(IS))<br>
+ if (isa<SyntheticSection>(isec))<br>
continue;<br>
// Use SectionMap to make sure we only scan code and not inline data.<br>
// We have already sorted MapSyms in ascending order and removed consecutive<br>
// mapping symbols of the same type. Our range of executable instructions to<br>
// scan is therefore [CodeSym->Value, DataSym->Value) or [CodeSym->Value,<br>
// section size).<br>
- std::vector<const Defined *> &MapSyms = SectionMap[IS];<br>
+ std::vector<const Defined *> &mapSyms = sectionMap[isec];<br>
<br>
- auto CodeSym = llvm::find_if(MapSyms, [&](const Defined *MS) {<br>
- return MS->getName().startswith("$x");<br>
+ auto codeSym = llvm::find_if(mapSyms, [&](const Defined *ms) {<br>
+ return ms->getName().startswith("$x");<br>
});<br>
<br>
- while (CodeSym != MapSyms.end()) {<br>
- auto DataSym = std::next(CodeSym);<br>
- uint64_t Off = (*CodeSym)->Value;<br>
- uint64_t Limit =<br>
- (DataSym == MapSyms.end()) ? IS->data().size() : (*DataSym)->Value;<br>
-<br>
- while (Off < Limit) {<br>
- uint64_t StartAddr = IS->getVA(Off);<br>
- if (uint64_t PatcheeOffset = scanCortexA53Errata843419(IS, Off, Limit))<br>
- implementPatch(StartAddr, PatcheeOffset, IS, Patches);<br>
+ while (codeSym != mapSyms.end()) {<br>
+ auto dataSym = std::next(codeSym);<br>
+ uint64_t off = (*codeSym)->value;<br>
+ uint64_t limit =<br>
+ (dataSym == mapSyms.end()) ? isec->data().size() : (*dataSym)->value;<br>
+<br>
+ while (off < limit) {<br>
+ uint64_t startAddr = isec->getVA(off);<br>
+ if (uint64_t patcheeOffset = scanCortexA53Errata843419(isec, off, limit))<br>
+ implementPatch(startAddr, patcheeOffset, isec, patches);<br>
}<br>
- if (DataSym == MapSyms.end())<br>
+ if (dataSym == mapSyms.end())<br>
break;<br>
- CodeSym = std::next(DataSym);<br>
+ codeSym = std::next(dataSym);<br>
}<br>
}<br>
- return Patches;<br>
+ return patches;<br>
}<br>
<br>
// For each InputSectionDescription make one pass over the executable sections<br>
@@ -630,22 +630,22 @@ AArch64Err843419Patcher::patchInputSecti<br>
// Ouptut and Input Sections may have been changed.<br>
// Returns false if no patches were required and no changes were made.<br>
bool AArch64Err843419Patcher::createFixes() {<br>
- if (Initialized == false)<br>
+ if (initialized == false)<br>
init();<br>
<br>
- bool AddressesChanged = false;<br>
- for (OutputSection *OS : OutputSections) {<br>
- if (!(OS->Flags & SHF_ALLOC) || !(OS->Flags & SHF_EXECINSTR))<br>
+ bool addressesChanged = false;<br>
+ for (OutputSection *os : outputSections) {<br>
+ if (!(os->flags & SHF_ALLOC) || !(os->flags & SHF_EXECINSTR))<br>
continue;<br>
- for (BaseCommand *BC : OS->SectionCommands)<br>
- if (auto *ISD = dyn_cast<InputSectionDescription>(BC)) {<br>
- std::vector<Patch843419Section *> Patches =<br>
- patchInputSectionDescription(*ISD);<br>
- if (!Patches.empty()) {<br>
- insertPatches(*ISD, Patches);<br>
- AddressesChanged = true;<br>
+ for (BaseCommand *bc : os->sectionCommands)<br>
+ if (auto *isd = dyn_cast<InputSectionDescription>(bc)) {<br>
+ std::vector<Patch843419Section *> patches =<br>
+ patchInputSectionDescription(*isd);<br>
+ if (!patches.empty()) {<br>
+ insertPatches(*isd, patches);<br>
+ addressesChanged = true;<br>
}<br>
}<br>
}<br>
- return AddressesChanged;<br>
+ return addressesChanged;<br>
}<br>
<br>
Modified: lld/trunk/ELF/AArch64ErrataFix.h<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_ELF_AArch64ErrataFix.h-3Frev-3D365595-26r1-3D365594-26r2-3D365595-26view-3Ddiff&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=DunXNA51Ka7T3QRwJHC5nHWMUhAzYpv9XZhFxml81_U&e=" rel="noreferrer" target="_blank">https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_ELF_AArch64ErrataFix.h-3Frev-3D365595-26r1-3D365594-26r2-3D365595-26view-3Ddiff&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=DunXNA51Ka7T3QRwJHC5nHWMUhAzYpv9XZhFxml81_U&e=</a> <br>
==============================================================================<br>
--- lld/trunk/ELF/AArch64ErrataFix.h (original)<br>
+++ lld/trunk/ELF/AArch64ErrataFix.h Tue Jul 9 22:00:37 2019<br>
@@ -29,19 +29,19 @@ public:<br>
<br>
private:<br>
std::vector<Patch843419Section *><br>
- patchInputSectionDescription(InputSectionDescription &ISD);<br>
+ patchInputSectionDescription(InputSectionDescription &isd);<br>
<br>
- void insertPatches(InputSectionDescription &ISD,<br>
- std::vector<Patch843419Section *> &Patches);<br>
+ void insertPatches(InputSectionDescription &isd,<br>
+ std::vector<Patch843419Section *> &patches);<br>
<br>
void init();<br>
<br>
// A cache of the mapping symbols defined by the InputSecion sorted in order<br>
// of ascending value with redundant symbols removed. These describe<br>
// the ranges of code and data in an executable InputSection.<br>
- std::map<InputSection *, std::vector<const Defined *>> SectionMap;<br>
+ std::map<InputSection *, std::vector<const Defined *>> sectionMap;<br>
<br>
- bool Initialized = false;<br>
+ bool initialized = false;<br>
};<br>
<br>
} // namespace elf<br>
<br>
Modified: lld/trunk/ELF/Arch/AArch64.cpp<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_ELF_Arch_AArch64.cpp-3Frev-3D365595-26r1-3D365594-26r2-3D365595-26view-3Ddiff&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=cRSmhekDLtI0tq-Xmu7wXoCPXBOsNVYV8Bp5bxj9iQg&e=" rel="noreferrer" target="_blank">https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_ELF_Arch_AArch64.cpp-3Frev-3D365595-26r1-3D365594-26r2-3D365595-26view-3Ddiff&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=cRSmhekDLtI0tq-Xmu7wXoCPXBOsNVYV8Bp5bxj9iQg&e=</a> <br>
==============================================================================<br>
--- lld/trunk/ELF/Arch/AArch64.cpp (original)<br>
+++ lld/trunk/ELF/Arch/AArch64.cpp Tue Jul 9 22:00:37 2019<br>
@@ -23,59 +23,59 @@ using namespace lld::elf;<br>
// Page(Expr) is the page address of the expression Expr, defined<br>
// as (Expr & ~0xFFF). (This applies even if the machine page size<br>
// supported by the platform has a different value.)<br>
-uint64_t elf::getAArch64Page(uint64_t Expr) {<br>
- return Expr & ~static_cast<uint64_t>(0xFFF);<br>
+uint64_t elf::getAArch64Page(uint64_t expr) {<br>
+ return expr & ~static_cast<uint64_t>(0xFFF);<br>
}<br>
<br>
namespace {<br>
class AArch64 : public TargetInfo {<br>
public:<br>
AArch64();<br>
- RelExpr getRelExpr(RelType Type, const Symbol &S,<br>
- const uint8_t *Loc) const override;<br>
- RelType getDynRel(RelType Type) const override;<br>
- void writeGotPlt(uint8_t *Buf, const Symbol &S) const override;<br>
- void writePltHeader(uint8_t *Buf) const override;<br>
- void writePlt(uint8_t *Buf, uint64_t GotPltEntryAddr, uint64_t PltEntryAddr,<br>
- int32_t Index, unsigned RelOff) const override;<br>
- bool needsThunk(RelExpr Expr, RelType Type, const InputFile *File,<br>
- uint64_t BranchAddr, const Symbol &S) const override;<br>
+ RelExpr getRelExpr(RelType type, const Symbol &s,<br>
+ const uint8_t *loc) const override;<br>
+ RelType getDynRel(RelType type) const override;<br>
+ void writeGotPlt(uint8_t *buf, const Symbol &s) const override;<br>
+ void writePltHeader(uint8_t *buf) const override;<br>
+ void writePlt(uint8_t *buf, uint64_t gotPltEntryAddr, uint64_t pltEntryAddr,<br>
+ int32_t index, unsigned relOff) const override;<br>
+ bool needsThunk(RelExpr expr, RelType type, const InputFile *file,<br>
+ uint64_t branchAddr, const Symbol &s) const override;<br>
uint32_t getThunkSectionSpacing() const override;<br>
- bool inBranchRange(RelType Type, uint64_t Src, uint64_t Dst) const override;<br>
- bool usesOnlyLowPageBits(RelType Type) const override;<br>
- void relocateOne(uint8_t *Loc, RelType Type, uint64_t Val) const override;<br>
- RelExpr adjustRelaxExpr(RelType Type, const uint8_t *Data,<br>
- RelExpr Expr) const override;<br>
- void relaxTlsGdToLe(uint8_t *Loc, RelType Type, uint64_t Val) const override;<br>
- void relaxTlsGdToIe(uint8_t *Loc, RelType Type, uint64_t Val) const override;<br>
- void relaxTlsIeToLe(uint8_t *Loc, RelType Type, uint64_t Val) const override;<br>
+ bool inBranchRange(RelType type, uint64_t src, uint64_t dst) const override;<br>
+ bool usesOnlyLowPageBits(RelType type) const override;<br>
+ void relocateOne(uint8_t *loc, RelType type, uint64_t val) const override;<br>
+ RelExpr adjustRelaxExpr(RelType type, const uint8_t *data,<br>
+ RelExpr expr) const override;<br>
+ void relaxTlsGdToLe(uint8_t *loc, RelType type, uint64_t val) const override;<br>
+ void relaxTlsGdToIe(uint8_t *loc, RelType type, uint64_t val) const override;<br>
+ void relaxTlsIeToLe(uint8_t *loc, RelType type, uint64_t val) const override;<br>
};<br>
} // namespace<br>
<br>
AArch64::AArch64() {<br>
- CopyRel = R_AARCH64_COPY;<br>
- RelativeRel = R_AARCH64_RELATIVE;<br>
- IRelativeRel = R_AARCH64_IRELATIVE;<br>
- GotRel = R_AARCH64_GLOB_DAT;<br>
- NoneRel = R_AARCH64_NONE;<br>
- PltRel = R_AARCH64_JUMP_SLOT;<br>
- SymbolicRel = R_AARCH64_ABS64;<br>
- TlsDescRel = R_AARCH64_TLSDESC;<br>
- TlsGotRel = R_AARCH64_TLS_TPREL64;<br>
- PltEntrySize = 16;<br>
- PltHeaderSize = 32;<br>
- DefaultMaxPageSize = 65536;<br>
+ copyRel = R_AARCH64_COPY;<br>
+ relativeRel = R_AARCH64_RELATIVE;<br>
+ iRelativeRel = R_AARCH64_IRELATIVE;<br>
+ gotRel = R_AARCH64_GLOB_DAT;<br>
+ noneRel = R_AARCH64_NONE;<br>
+ pltRel = R_AARCH64_JUMP_SLOT;<br>
+ symbolicRel = R_AARCH64_ABS64;<br>
+ tlsDescRel = R_AARCH64_TLSDESC;<br>
+ tlsGotRel = R_AARCH64_TLS_TPREL64;<br>
+ pltEntrySize = 16;<br>
+ pltHeaderSize = 32;<br>
+ defaultMaxPageSize = 65536;<br>
<br>
// Align to the 2 MiB page size (known as a superpage or huge page).<br>
// FreeBSD automatically promotes 2 MiB-aligned allocations.<br>
- DefaultImageBase = 0x200000;<br>
+ defaultImageBase = 0x200000;<br>
<br>
- NeedsThunks = true;<br>
+ needsThunks = true;<br>
}<br>
<br>
-RelExpr AArch64::getRelExpr(RelType Type, const Symbol &S,<br>
- const uint8_t *Loc) const {<br>
- switch (Type) {<br>
+RelExpr AArch64::getRelExpr(RelType type, const Symbol &s,<br>
+ const uint8_t *loc) const {<br>
+ switch (type) {<br>
case R_AARCH64_TLSDESC_ADR_PAGE21:<br>
return R_AARCH64_TLSDESC_PAGE;<br>
case R_AARCH64_TLSDESC_LD64_LO12:<br>
@@ -117,18 +117,18 @@ RelExpr AArch64::getRelExpr(RelType Type<br>
}<br>
}<br>
<br>
-RelExpr AArch64::adjustRelaxExpr(RelType Type, const uint8_t *Data,<br>
- RelExpr Expr) const {<br>
- if (Expr == R_RELAX_TLS_GD_TO_IE) {<br>
- if (Type == R_AARCH64_TLSDESC_ADR_PAGE21)<br>
+RelExpr AArch64::adjustRelaxExpr(RelType type, const uint8_t *data,<br>
+ RelExpr expr) const {<br>
+ if (expr == R_RELAX_TLS_GD_TO_IE) {<br>
+ if (type == R_AARCH64_TLSDESC_ADR_PAGE21)<br>
return R_AARCH64_RELAX_TLS_GD_TO_IE_PAGE_PC;<br>
return R_RELAX_TLS_GD_TO_IE_ABS;<br>
}<br>
- return Expr;<br>
+ return expr;<br>
}<br>
<br>
-bool AArch64::usesOnlyLowPageBits(RelType Type) const {<br>
- switch (Type) {<br>
+bool AArch64::usesOnlyLowPageBits(RelType type) const {<br>
+ switch (type) {<br>
default:<br>
return false;<br>
case R_AARCH64_ADD_ABS_LO12_NC:<br>
@@ -145,18 +145,18 @@ bool AArch64::usesOnlyLowPageBits(RelTyp<br>
}<br>
}<br>
<br>
-RelType AArch64::getDynRel(RelType Type) const {<br>
- if (Type == R_AARCH64_ABS64)<br>
- return Type;<br>
+RelType AArch64::getDynRel(RelType type) const {<br>
+ if (type == R_AARCH64_ABS64)<br>
+ return type;<br>
return R_AARCH64_NONE;<br>
}<br>
<br>
-void AArch64::writeGotPlt(uint8_t *Buf, const Symbol &) const {<br>
- write64le(Buf, In.Plt->getVA());<br>
+void AArch64::writeGotPlt(uint8_t *buf, const Symbol &) const {<br>
+ write64le(buf, in.plt->getVA());<br>
}<br>
<br>
-void AArch64::writePltHeader(uint8_t *Buf) const {<br>
- const uint8_t PltData[] = {<br>
+void AArch64::writePltHeader(uint8_t *buf) const {<br>
+ const uint8_t pltData[] = {<br>
0xf0, 0x7b, 0xbf, 0xa9, // stp x16, x30, [sp,#-16]!<br>
0x10, 0x00, 0x00, 0x90, // adrp x16, Page(&(.plt.got[2]))<br>
0x11, 0x02, 0x40, 0xf9, // ldr x17, [x16, Offset(&(.plt.got[2]))]<br>
@@ -166,42 +166,42 @@ void AArch64::writePltHeader(uint8_t *Bu<br>
0x1f, 0x20, 0x03, 0xd5, // nop<br>
0x1f, 0x20, 0x03, 0xd5 // nop<br>
};<br>
- memcpy(Buf, PltData, sizeof(PltData));<br>
+ memcpy(buf, pltData, sizeof(pltData));<br>
<br>
- uint64_t Got = In.GotPlt->getVA();<br>
- uint64_t Plt = In.Plt->getVA();<br>
- relocateOne(Buf + 4, R_AARCH64_ADR_PREL_PG_HI21,<br>
- getAArch64Page(Got + 16) - getAArch64Page(Plt + 4));<br>
- relocateOne(Buf + 8, R_AARCH64_LDST64_ABS_LO12_NC, Got + 16);<br>
- relocateOne(Buf + 12, R_AARCH64_ADD_ABS_LO12_NC, Got + 16);<br>
+ uint64_t got = in.gotPlt->getVA();<br>
+ uint64_t plt = in.plt->getVA();<br>
+ relocateOne(buf + 4, R_AARCH64_ADR_PREL_PG_HI21,<br>
+ getAArch64Page(got + 16) - getAArch64Page(plt + 4));<br>
+ relocateOne(buf + 8, R_AARCH64_LDST64_ABS_LO12_NC, got + 16);<br>
+ relocateOne(buf + 12, R_AARCH64_ADD_ABS_LO12_NC, got + 16);<br>
}<br>
<br>
-void AArch64::writePlt(uint8_t *Buf, uint64_t GotPltEntryAddr,<br>
- uint64_t PltEntryAddr, int32_t Index,<br>
- unsigned RelOff) const {<br>
- const uint8_t Inst[] = {<br>
+void AArch64::writePlt(uint8_t *buf, uint64_t gotPltEntryAddr,<br>
+ uint64_t pltEntryAddr, int32_t index,<br>
+ unsigned relOff) const {<br>
+ const uint8_t inst[] = {<br>
0x10, 0x00, 0x00, 0x90, // adrp x16, Page(&(.plt.got[n]))<br>
0x11, 0x02, 0x40, 0xf9, // ldr x17, [x16, Offset(&(.plt.got[n]))]<br>
0x10, 0x02, 0x00, 0x91, // add x16, x16, Offset(&(.plt.got[n]))<br>
0x20, 0x02, 0x1f, 0xd6 // br x17<br>
};<br>
- memcpy(Buf, Inst, sizeof(Inst));<br>
+ memcpy(buf, inst, sizeof(inst));<br>
<br>
- relocateOne(Buf, R_AARCH64_ADR_PREL_PG_HI21,<br>
- getAArch64Page(GotPltEntryAddr) - getAArch64Page(PltEntryAddr));<br>
- relocateOne(Buf + 4, R_AARCH64_LDST64_ABS_LO12_NC, GotPltEntryAddr);<br>
- relocateOne(Buf + 8, R_AARCH64_ADD_ABS_LO12_NC, GotPltEntryAddr);<br>
+ relocateOne(buf, R_AARCH64_ADR_PREL_PG_HI21,<br>
+ getAArch64Page(gotPltEntryAddr) - getAArch64Page(pltEntryAddr));<br>
+ relocateOne(buf + 4, R_AARCH64_LDST64_ABS_LO12_NC, gotPltEntryAddr);<br>
+ relocateOne(buf + 8, R_AARCH64_ADD_ABS_LO12_NC, gotPltEntryAddr);<br>
}<br>
<br>
-bool AArch64::needsThunk(RelExpr Expr, RelType Type, const InputFile *File,<br>
- uint64_t BranchAddr, const Symbol &S) const {<br>
+bool AArch64::needsThunk(RelExpr expr, RelType type, const InputFile *file,<br>
+ uint64_t branchAddr, const Symbol &s) const {<br>
// ELF for the ARM 64-bit architecture, section Call and Jump relocations<br>
// only permits range extension thunks for R_AARCH64_CALL26 and<br>
// R_AARCH64_JUMP26 relocation types.<br>
- if (Type != R_AARCH64_CALL26 && Type != R_AARCH64_JUMP26)<br>
+ if (type != R_AARCH64_CALL26 && type != R_AARCH64_JUMP26)<br>
return false;<br>
- uint64_t Dst = (Expr == R_PLT_PC) ? S.getPltVA() : S.getVA();<br>
- return !inBranchRange(Type, BranchAddr, Dst);<br>
+ uint64_t dst = (expr == R_PLT_PC) ? s.getPltVA() : s.getVA();<br>
+ return !inBranchRange(type, branchAddr, dst);<br>
}<br>
<br>
uint32_t AArch64::getThunkSectionSpacing() const {<br>
@@ -211,70 +211,70 @@ uint32_t AArch64::getThunkSectionSpacing<br>
return (128 * 1024 * 1024) - 0x30000;<br>
}<br>
<br>
-bool AArch64::inBranchRange(RelType Type, uint64_t Src, uint64_t Dst) const {<br>
- if (Type != R_AARCH64_CALL26 && Type != R_AARCH64_JUMP26)<br>
+bool AArch64::inBranchRange(RelType type, uint64_t src, uint64_t dst) const {<br>
+ if (type != R_AARCH64_CALL26 && type != R_AARCH64_JUMP26)<br>
return true;<br>
// The AArch64 call and unconditional branch instructions have a range of<br>
// +/- 128 MiB.<br>
- uint64_t Range = 128 * 1024 * 1024;<br>
- if (Dst > Src) {<br>
+ uint64_t range = 128 * 1024 * 1024;<br>
+ if (dst > src) {<br>
// Immediate of branch is signed.<br>
- Range -= 4;<br>
- return Dst - Src <= Range;<br>
+ range -= 4;<br>
+ return dst - src <= range;<br>
}<br>
- return Src - Dst <= Range;<br>
+ return src - dst <= range;<br>
}<br>
<br>
-static void write32AArch64Addr(uint8_t *L, uint64_t Imm) {<br>
- uint32_t ImmLo = (Imm & 0x3) << 29;<br>
- uint32_t ImmHi = (Imm & 0x1FFFFC) << 3;<br>
- uint64_t Mask = (0x3 << 29) | (0x1FFFFC << 3);<br>
- write32le(L, (read32le(L) & ~Mask) | ImmLo | ImmHi);<br>
+static void write32AArch64Addr(uint8_t *l, uint64_t imm) {<br>
+ uint32_t immLo = (imm & 0x3) << 29;<br>
+ uint32_t immHi = (imm & 0x1FFFFC) << 3;<br>
+ uint64_t mask = (0x3 << 29) | (0x1FFFFC << 3);<br>
+ write32le(l, (read32le(l) & ~mask) | immLo | immHi);<br>
}<br>
<br>
// Return the bits [Start, End] from Val shifted Start bits.<br>
// For instance, getBits(0xF0, 4, 8) returns 0xF.<br>
-static uint64_t getBits(uint64_t Val, int Start, int End) {<br>
- uint64_t Mask = ((uint64_t)1 << (End + 1 - Start)) - 1;<br>
- return (Val >> Start) & Mask;<br>
+static uint64_t getBits(uint64_t val, int start, int end) {<br>
+ uint64_t mask = ((uint64_t)1 << (end + 1 - start)) - 1;<br>
+ return (val >> start) & mask;<br>
}<br>
<br>
-static void or32le(uint8_t *P, int32_t V) { write32le(P, read32le(P) | V); }<br>
+static void or32le(uint8_t *p, int32_t v) { write32le(p, read32le(p) | v); }<br>
<br>
// Update the immediate field in a AARCH64 ldr, str, and add instruction.<br>
-static void or32AArch64Imm(uint8_t *L, uint64_t Imm) {<br>
- or32le(L, (Imm & 0xFFF) << 10);<br>
+static void or32AArch64Imm(uint8_t *l, uint64_t imm) {<br>
+ or32le(l, (imm & 0xFFF) << 10);<br>
}<br>
<br>
-void AArch64::relocateOne(uint8_t *Loc, RelType Type, uint64_t Val) const {<br>
- switch (Type) {<br>
+void AArch64::relocateOne(uint8_t *loc, RelType type, uint64_t val) const {<br>
+ switch (type) {<br>
case R_AARCH64_ABS16:<br>
case R_AARCH64_PREL16:<br>
- checkIntUInt(Loc, Val, 16, Type);<br>
- write16le(Loc, Val);<br>
+ checkIntUInt(loc, val, 16, type);<br>
+ write16le(loc, val);<br>
break;<br>
case R_AARCH64_ABS32:<br>
case R_AARCH64_PREL32:<br>
- checkIntUInt(Loc, Val, 32, Type);<br>
- write32le(Loc, Val);<br>
+ checkIntUInt(loc, val, 32, type);<br>
+ write32le(loc, val);<br>
break;<br>
case R_AARCH64_ABS64:<br>
case R_AARCH64_PREL64:<br>
- write64le(Loc, Val);<br>
+ write64le(loc, val);<br>
break;<br>
case R_AARCH64_ADD_ABS_LO12_NC:<br>
- or32AArch64Imm(Loc, Val);<br>
+ or32AArch64Imm(loc, val);<br>
break;<br>
case R_AARCH64_ADR_GOT_PAGE:<br>
case R_AARCH64_ADR_PREL_PG_HI21:<br>
case R_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:<br>
case R_AARCH64_TLSDESC_ADR_PAGE21:<br>
- checkInt(Loc, Val, 33, Type);<br>
- write32AArch64Addr(Loc, Val >> 12);<br>
+ checkInt(loc, val, 33, type);<br>
+ write32AArch64Addr(loc, val >> 12);<br>
break;<br>
case R_AARCH64_ADR_PREL_LO21:<br>
- checkInt(Loc, Val, 21, Type);<br>
- write32AArch64Addr(Loc, Val);<br>
+ checkInt(loc, val, 21, type);<br>
+ write32AArch64Addr(loc, val);<br>
break;<br>
case R_AARCH64_JUMP26:<br>
// Normally we would just write the bits of the immediate field, however<br>
@@ -284,75 +284,75 @@ void AArch64::relocateOne(uint8_t *Loc,<br>
// opcode and the immediate (0 001 | 01 imm26) we can do this<br>
// transformation by placing a R_AARCH64_JUMP26 relocation at the offset of<br>
// the instruction we want to patch.<br>
- write32le(Loc, 0x14000000);<br>
+ write32le(loc, 0x14000000);<br>
LLVM_FALLTHROUGH;<br>
case R_AARCH64_CALL26:<br>
- checkInt(Loc, Val, 28, Type);<br>
- or32le(Loc, (Val & 0x0FFFFFFC) >> 2);<br>
+ checkInt(loc, val, 28, type);<br>
+ or32le(loc, (val & 0x0FFFFFFC) >> 2);<br>
break;<br>
case R_AARCH64_CONDBR19:<br>
case R_AARCH64_LD_PREL_LO19:<br>
- checkAlignment(Loc, Val, 4, Type);<br>
- checkInt(Loc, Val, 21, Type);<br>
- or32le(Loc, (Val & 0x1FFFFC) << 3);<br>
+ checkAlignment(loc, val, 4, type);<br>
+ checkInt(loc, val, 21, type);<br>
+ or32le(loc, (val & 0x1FFFFC) << 3);<br>
break;<br>
case R_AARCH64_LDST8_ABS_LO12_NC:<br>
case R_AARCH64_TLSLE_LDST8_TPREL_LO12_NC:<br>
- or32AArch64Imm(Loc, getBits(Val, 0, 11));<br>
+ or32AArch64Imm(loc, getBits(val, 0, 11));<br>
break;<br>
case R_AARCH64_LDST16_ABS_LO12_NC:<br>
case R_AARCH64_TLSLE_LDST16_TPREL_LO12_NC:<br>
- checkAlignment(Loc, Val, 2, Type);<br>
- or32AArch64Imm(Loc, getBits(Val, 1, 11));<br>
+ checkAlignment(loc, val, 2, type);<br>
+ or32AArch64Imm(loc, getBits(val, 1, 11));<br>
break;<br>
case R_AARCH64_LDST32_ABS_LO12_NC:<br>
case R_AARCH64_TLSLE_LDST32_TPREL_LO12_NC:<br>
- checkAlignment(Loc, Val, 4, Type);<br>
- or32AArch64Imm(Loc, getBits(Val, 2, 11));<br>
+ checkAlignment(loc, val, 4, type);<br>
+ or32AArch64Imm(loc, getBits(val, 2, 11));<br>
break;<br>
case R_AARCH64_LDST64_ABS_LO12_NC:<br>
case R_AARCH64_LD64_GOT_LO12_NC:<br>
case R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC:<br>
case R_AARCH64_TLSLE_LDST64_TPREL_LO12_NC:<br>
case R_AARCH64_TLSDESC_LD64_LO12:<br>
- checkAlignment(Loc, Val, 8, Type);<br>
- or32AArch64Imm(Loc, getBits(Val, 3, 11));<br>
+ checkAlignment(loc, val, 8, type);<br>
+ or32AArch64Imm(loc, getBits(val, 3, 11));<br>
break;<br>
case R_AARCH64_LDST128_ABS_LO12_NC:<br>
case R_AARCH64_TLSLE_LDST128_TPREL_LO12_NC:<br>
- checkAlignment(Loc, Val, 16, Type);<br>
- or32AArch64Imm(Loc, getBits(Val, 4, 11));<br>
+ checkAlignment(loc, val, 16, type);<br>
+ or32AArch64Imm(loc, getBits(val, 4, 11));<br>
break;<br>
case R_AARCH64_MOVW_UABS_G0_NC:<br>
- or32le(Loc, (Val & 0xFFFF) << 5);<br>
+ or32le(loc, (val & 0xFFFF) << 5);<br>
break;<br>
case R_AARCH64_MOVW_UABS_G1_NC:<br>
- or32le(Loc, (Val & 0xFFFF0000) >> 11);<br>
+ or32le(loc, (val & 0xFFFF0000) >> 11);<br>
break;<br>
case R_AARCH64_MOVW_UABS_G2_NC:<br>
- or32le(Loc, (Val & 0xFFFF00000000) >> 27);<br>
+ or32le(loc, (val & 0xFFFF00000000) >> 27);<br>
break;<br>
case R_AARCH64_MOVW_UABS_G3:<br>
- or32le(Loc, (Val & 0xFFFF000000000000) >> 43);<br>
+ or32le(loc, (val & 0xFFFF000000000000) >> 43);<br>
break;<br>
case R_AARCH64_TSTBR14:<br>
- checkInt(Loc, Val, 16, Type);<br>
- or32le(Loc, (Val & 0xFFFC) << 3);<br>
+ checkInt(loc, val, 16, type);<br>
+ or32le(loc, (val & 0xFFFC) << 3);<br>
break;<br>
case R_AARCH64_TLSLE_ADD_TPREL_HI12:<br>
- checkUInt(Loc, Val, 24, Type);<br>
- or32AArch64Imm(Loc, Val >> 12);<br>
+ checkUInt(loc, val, 24, type);<br>
+ or32AArch64Imm(loc, val >> 12);<br>
break;<br>
case R_AARCH64_TLSLE_ADD_TPREL_LO12_NC:<br>
case R_AARCH64_TLSDESC_ADD_LO12:<br>
- or32AArch64Imm(Loc, Val);<br>
+ or32AArch64Imm(loc, val);<br>
break;<br>
default:<br>
- error(getErrorLocation(Loc) + "unrecognized relocation " + toString(Type));<br>
+ error(getErrorLocation(loc) + "unrecognized relocation " + toString(type));<br>
}<br>
}<br>
<br>
-void AArch64::relaxTlsGdToLe(uint8_t *Loc, RelType Type, uint64_t Val) const {<br>
+void AArch64::relaxTlsGdToLe(uint8_t *loc, RelType type, uint64_t val) const {<br>
// TLSDESC Global-Dynamic relocation are in the form:<br>
// adrp x0, :tlsdesc:v [R_AARCH64_TLSDESC_ADR_PAGE21]<br>
// ldr x1, [x0, #:tlsdesc_lo12:v [R_AARCH64_TLSDESC_LD64_LO12]<br>
@@ -364,25 +364,25 @@ void AArch64::relaxTlsGdToLe(uint8_t *Lo<br>
// movk x0, #0x10<br>
// nop<br>
// nop<br>
- checkUInt(Loc, Val, 32, Type);<br>
+ checkUInt(loc, val, 32, type);<br>
<br>
- switch (Type) {<br>
+ switch (type) {<br>
case R_AARCH64_TLSDESC_ADD_LO12:<br>
case R_AARCH64_TLSDESC_CALL:<br>
- write32le(Loc, 0xd503201f); // nop<br>
+ write32le(loc, 0xd503201f); // nop<br>
return;<br>
case R_AARCH64_TLSDESC_ADR_PAGE21:<br>
- write32le(Loc, 0xd2a00000 | (((Val >> 16) & 0xffff) << 5)); // movz<br>
+ write32le(loc, 0xd2a00000 | (((val >> 16) & 0xffff) << 5)); // movz<br>
return;<br>
case R_AARCH64_TLSDESC_LD64_LO12:<br>
- write32le(Loc, 0xf2800000 | ((Val & 0xffff) << 5)); // movk<br>
+ write32le(loc, 0xf2800000 | ((val & 0xffff) << 5)); // movk<br>
return;<br>
default:<br>
llvm_unreachable("unsupported relocation for TLS GD to LE relaxation");<br>
}<br>
}<br>
<br>
-void AArch64::relaxTlsGdToIe(uint8_t *Loc, RelType Type, uint64_t Val) const {<br>
+void AArch64::relaxTlsGdToIe(uint8_t *loc, RelType type, uint64_t val) const {<br>
// TLSDESC Global-Dynamic relocation are in the form:<br>
// adrp x0, :tlsdesc:v [R_AARCH64_TLSDESC_ADR_PAGE21]<br>
// ldr x1, [x0, #:tlsdesc_lo12:v [R_AARCH64_TLSDESC_LD64_LO12]<br>
@@ -395,37 +395,37 @@ void AArch64::relaxTlsGdToIe(uint8_t *Lo<br>
// nop<br>
// nop<br>
<br>
- switch (Type) {<br>
+ switch (type) {<br>
case R_AARCH64_TLSDESC_ADD_LO12:<br>
case R_AARCH64_TLSDESC_CALL:<br>
- write32le(Loc, 0xd503201f); // nop<br>
+ write32le(loc, 0xd503201f); // nop<br>
break;<br>
case R_AARCH64_TLSDESC_ADR_PAGE21:<br>
- write32le(Loc, 0x90000000); // adrp<br>
- relocateOne(Loc, R_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21, Val);<br>
+ write32le(loc, 0x90000000); // adrp<br>
+ relocateOne(loc, R_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21, val);<br>
break;<br>
case R_AARCH64_TLSDESC_LD64_LO12:<br>
- write32le(Loc, 0xf9400000); // ldr<br>
- relocateOne(Loc, R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC, Val);<br>
+ write32le(loc, 0xf9400000); // ldr<br>
+ relocateOne(loc, R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC, val);<br>
break;<br>
default:<br>
llvm_unreachable("unsupported relocation for TLS GD to LE relaxation");<br>
}<br>
}<br>
<br>
-void AArch64::relaxTlsIeToLe(uint8_t *Loc, RelType Type, uint64_t Val) const {<br>
- checkUInt(Loc, Val, 32, Type);<br>
+void AArch64::relaxTlsIeToLe(uint8_t *loc, RelType type, uint64_t val) const {<br>
+ checkUInt(loc, val, 32, type);<br>
<br>
- if (Type == R_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21) {<br>
+ if (type == R_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21) {<br>
// Generate MOVZ.<br>
- uint32_t RegNo = read32le(Loc) & 0x1f;<br>
- write32le(Loc, (0xd2a00000 | RegNo) | (((Val >> 16) & 0xffff) << 5));<br>
+ uint32_t regNo = read32le(loc) & 0x1f;<br>
+ write32le(loc, (0xd2a00000 | regNo) | (((val >> 16) & 0xffff) << 5));<br>
return;<br>
}<br>
- if (Type == R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC) {<br>
+ if (type == R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC) {<br>
// Generate MOVK.<br>
- uint32_t RegNo = read32le(Loc) & 0x1f;<br>
- write32le(Loc, (0xf2800000 | RegNo) | ((Val & 0xffff) << 5));<br>
+ uint32_t regNo = read32le(loc) & 0x1f;<br>
+ write32le(loc, (0xf2800000 | regNo) | ((val & 0xffff) << 5));<br>
return;<br>
}<br>
llvm_unreachable("invalid relocation for TLS IE to LE relaxation");<br>
@@ -470,19 +470,19 @@ namespace {<br>
class AArch64BtiPac final : public AArch64 {<br>
public:<br>
AArch64BtiPac();<br>
- void writePltHeader(uint8_t *Buf) const override;<br>
- void writePlt(uint8_t *Buf, uint64_t GotPltEntryAddr, uint64_t PltEntryAddr,<br>
- int32_t Index, unsigned RelOff) const override;<br>
+ void writePltHeader(uint8_t *buf) const override;<br>
+ void writePlt(uint8_t *buf, uint64_t gotPltEntryAddr, uint64_t pltEntryAddr,<br>
+ int32_t index, unsigned relOff) const override;<br>
<br>
private:<br>
- bool BtiHeader; // bti instruction needed in PLT Header<br>
- bool BtiEntry; // bti instruction needed in PLT Entry<br>
- bool PacEntry; // autia1716 instruction needed in PLT Entry<br>
+ bool btiHeader; // bti instruction needed in PLT Header<br>
+ bool btiEntry; // bti instruction needed in PLT Entry<br>
+ bool pacEntry; // autia1716 instruction needed in PLT Entry<br>
};<br>
} // namespace<br>
<br>
AArch64BtiPac::AArch64BtiPac() {<br>
- BtiHeader = (Config->AndFeatures & GNU_PROPERTY_AARCH64_FEATURE_1_BTI);<br>
+ btiHeader = (config->andFeatures & GNU_PROPERTY_AARCH64_FEATURE_1_BTI);<br>
// A BTI (Branch Target Indicator) Plt Entry is only required if the<br>
// address of the PLT entry can be taken by the program, which permits an<br>
// indirect jump to the PLT entry. This can happen when the address<br>
@@ -490,16 +490,16 @@ AArch64BtiPac::AArch64BtiPac() {<br>
// the function in an executable being taken by a shared library.<br>
// FIXME: There is a potential optimization to omit the BTI if we detect<br>
// that the address of the PLT entry isn't taken.<br>
- BtiEntry = BtiHeader && !Config->Shared;<br>
- PacEntry = (Config->AndFeatures & GNU_PROPERTY_AARCH64_FEATURE_1_PAC);<br>
+ btiEntry = btiHeader && !config->shared;<br>
+ pacEntry = (config->andFeatures & GNU_PROPERTY_AARCH64_FEATURE_1_PAC);<br>
<br>
- if (BtiEntry || PacEntry)<br>
- PltEntrySize = 24;<br>
+ if (btiEntry || pacEntry)<br>
+ pltEntrySize = 24;<br>
}<br>
<br>
-void AArch64BtiPac::writePltHeader(uint8_t *Buf) const {<br>
- const uint8_t BtiData[] = { 0x5f, 0x24, 0x03, 0xd5 }; // bti c<br>
- const uint8_t PltData[] = {<br>
+void AArch64BtiPac::writePltHeader(uint8_t *buf) const {<br>
+ const uint8_t btiData[] = { 0x5f, 0x24, 0x03, 0xd5 }; // bti c<br>
+ const uint8_t pltData[] = {<br>
0xf0, 0x7b, 0xbf, 0xa9, // stp x16, x30, [sp,#-16]!<br>
0x10, 0x00, 0x00, 0x90, // adrp x16, Page(&(.plt.got[2]))<br>
0x11, 0x02, 0x40, 0xf9, // ldr x17, [x16, Offset(&(.plt.got[2]))]<br>
@@ -508,80 +508,80 @@ void AArch64BtiPac::writePltHeader(uint8<br>
0x1f, 0x20, 0x03, 0xd5, // nop<br>
0x1f, 0x20, 0x03, 0xd5 // nop<br>
};<br>
- const uint8_t NopData[] = { 0x1f, 0x20, 0x03, 0xd5 }; // nop<br>
+ const uint8_t nopData[] = { 0x1f, 0x20, 0x03, 0xd5 }; // nop<br>
<br>
- uint64_t Got = In.GotPlt->getVA();<br>
- uint64_t Plt = In.Plt->getVA();<br>
+ uint64_t got = in.gotPlt->getVA();<br>
+ uint64_t plt = in.plt->getVA();<br>
<br>
- if (BtiHeader) {<br>
+ if (btiHeader) {<br>
// PltHeader is called indirectly by Plt[N]. Prefix PltData with a BTI C<br>
// instruction.<br>
- memcpy(Buf, BtiData, sizeof(BtiData));<br>
- Buf += sizeof(BtiData);<br>
- Plt += sizeof(BtiData);<br>
- }<br>
- memcpy(Buf, PltData, sizeof(PltData));<br>
-<br>
- relocateOne(Buf + 4, R_AARCH64_ADR_PREL_PG_HI21,<br>
- getAArch64Page(Got + 16) - getAArch64Page(Plt + 8));<br>
- relocateOne(Buf + 8, R_AARCH64_LDST64_ABS_LO12_NC, Got + 16);<br>
- relocateOne(Buf + 12, R_AARCH64_ADD_ABS_LO12_NC, Got + 16);<br>
- if (!BtiHeader)<br>
+ memcpy(buf, btiData, sizeof(btiData));<br>
+ buf += sizeof(btiData);<br>
+ plt += sizeof(btiData);<br>
+ }<br>
+ memcpy(buf, pltData, sizeof(pltData));<br>
+<br>
+ relocateOne(buf + 4, R_AARCH64_ADR_PREL_PG_HI21,<br>
+ getAArch64Page(got + 16) - getAArch64Page(plt + 8));<br>
+ relocateOne(buf + 8, R_AARCH64_LDST64_ABS_LO12_NC, got + 16);<br>
+ relocateOne(buf + 12, R_AARCH64_ADD_ABS_LO12_NC, got + 16);<br>
+ if (!btiHeader)<br>
// We didn't add the BTI c instruction so round out size with NOP.<br>
- memcpy(Buf + sizeof(PltData), NopData, sizeof(NopData));<br>
+ memcpy(buf + sizeof(pltData), nopData, sizeof(nopData));<br>
}<br>
<br>
-void AArch64BtiPac::writePlt(uint8_t *Buf, uint64_t GotPltEntryAddr,<br>
- uint64_t PltEntryAddr, int32_t Index,<br>
- unsigned RelOff) const {<br>
+void AArch64BtiPac::writePlt(uint8_t *buf, uint64_t gotPltEntryAddr,<br>
+ uint64_t pltEntryAddr, int32_t index,<br>
+ unsigned relOff) const {<br>
// The PLT entry is of the form:<br>
// [BtiData] AddrInst (PacBr | StdBr) [NopData]<br>
- const uint8_t BtiData[] = { 0x5f, 0x24, 0x03, 0xd5 }; // bti c<br>
- const uint8_t AddrInst[] = {<br>
+ const uint8_t btiData[] = { 0x5f, 0x24, 0x03, 0xd5 }; // bti c<br>
+ const uint8_t addrInst[] = {<br>
0x10, 0x00, 0x00, 0x90, // adrp x16, Page(&(.plt.got[n]))<br>
0x11, 0x02, 0x40, 0xf9, // ldr x17, [x16, Offset(&(.plt.got[n]))]<br>
0x10, 0x02, 0x00, 0x91 // add x16, x16, Offset(&(.plt.got[n]))<br>
};<br>
- const uint8_t PacBr[] = {<br>
+ const uint8_t pacBr[] = {<br>
0x9f, 0x21, 0x03, 0xd5, // autia1716<br>
0x20, 0x02, 0x1f, 0xd6 // br x17<br>
};<br>
- const uint8_t StdBr[] = {<br>
+ const uint8_t stdBr[] = {<br>
0x20, 0x02, 0x1f, 0xd6, // br x17<br>
0x1f, 0x20, 0x03, 0xd5 // nop<br>
};<br>
- const uint8_t NopData[] = { 0x1f, 0x20, 0x03, 0xd5 }; // nop<br>
+ const uint8_t nopData[] = { 0x1f, 0x20, 0x03, 0xd5 }; // nop<br>
<br>
- if (BtiEntry) {<br>
- memcpy(Buf, BtiData, sizeof(BtiData));<br>
- Buf += sizeof(BtiData);<br>
- PltEntryAddr += sizeof(BtiData);<br>
- }<br>
-<br>
- memcpy(Buf, AddrInst, sizeof(AddrInst));<br>
- relocateOne(Buf, R_AARCH64_ADR_PREL_PG_HI21,<br>
- getAArch64Page(GotPltEntryAddr) -<br>
- getAArch64Page(PltEntryAddr));<br>
- relocateOne(Buf + 4, R_AARCH64_LDST64_ABS_LO12_NC, GotPltEntryAddr);<br>
- relocateOne(Buf + 8, R_AARCH64_ADD_ABS_LO12_NC, GotPltEntryAddr);<br>
+ if (btiEntry) {<br>
+ memcpy(buf, btiData, sizeof(btiData));<br>
+ buf += sizeof(btiData);<br>
+ pltEntryAddr += sizeof(btiData);<br>
+ }<br>
+<br>
+ memcpy(buf, addrInst, sizeof(addrInst));<br>
+ relocateOne(buf, R_AARCH64_ADR_PREL_PG_HI21,<br>
+ getAArch64Page(gotPltEntryAddr) -<br>
+ getAArch64Page(pltEntryAddr));<br>
+ relocateOne(buf + 4, R_AARCH64_LDST64_ABS_LO12_NC, gotPltEntryAddr);<br>
+ relocateOne(buf + 8, R_AARCH64_ADD_ABS_LO12_NC, gotPltEntryAddr);<br>
<br>
- if (PacEntry)<br>
- memcpy(Buf + sizeof(AddrInst), PacBr, sizeof(PacBr));<br>
+ if (pacEntry)<br>
+ memcpy(buf + sizeof(addrInst), pacBr, sizeof(pacBr));<br>
else<br>
- memcpy(Buf + sizeof(AddrInst), StdBr, sizeof(StdBr));<br>
- if (!BtiEntry)<br>
+ memcpy(buf + sizeof(addrInst), stdBr, sizeof(stdBr));<br>
+ if (!btiEntry)<br>
// We didn't add the BTI c instruction so round out size with NOP.<br>
- memcpy(Buf + sizeof(AddrInst) + sizeof(StdBr), NopData, sizeof(NopData));<br>
+ memcpy(buf + sizeof(addrInst) + sizeof(stdBr), nopData, sizeof(nopData));<br>
}<br>
<br>
static TargetInfo *getTargetInfo() {<br>
- if (Config->AndFeatures & (GNU_PROPERTY_AARCH64_FEATURE_1_BTI |<br>
+ if (config->andFeatures & (GNU_PROPERTY_AARCH64_FEATURE_1_BTI |<br>
GNU_PROPERTY_AARCH64_FEATURE_1_PAC)) {<br>
- static AArch64BtiPac T;<br>
- return &T;<br>
+ static AArch64BtiPac t;<br>
+ return &t;<br>
}<br>
- static AArch64 T;<br>
- return &T;<br>
+ static AArch64 t;<br>
+ return &t;<br>
}<br>
<br>
TargetInfo *elf::getAArch64TargetInfo() { return getTargetInfo(); }<br>
<br>
Modified: lld/trunk/ELF/Arch/AMDGPU.cpp<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_ELF_Arch_AMDGPU.cpp-3Frev-3D365595-26r1-3D365594-26r2-3D365595-26view-3Ddiff&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=0nrilnDnpb2HXTdixGYLQj29EnxWHn_gTUUPPNyjXjI&e=" rel="noreferrer" target="_blank">https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_ELF_Arch_AMDGPU.cpp-3Frev-3D365595-26r1-3D365594-26r2-3D365595-26view-3Ddiff&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=0nrilnDnpb2HXTdixGYLQj29EnxWHn_gTUUPPNyjXjI&e=</a> <br>
==============================================================================<br>
--- lld/trunk/ELF/Arch/AMDGPU.cpp (original)<br>
+++ lld/trunk/ELF/Arch/AMDGPU.cpp Tue Jul 9 22:00:37 2019<br>
@@ -25,63 +25,63 @@ class AMDGPU final : public TargetInfo {<br>
public:<br>
AMDGPU();<br>
uint32_t calcEFlags() const override;<br>
- void relocateOne(uint8_t *Loc, RelType Type, uint64_t Val) const override;<br>
- RelExpr getRelExpr(RelType Type, const Symbol &S,<br>
- const uint8_t *Loc) const override;<br>
- RelType getDynRel(RelType Type) const override;<br>
+ void relocateOne(uint8_t *loc, RelType type, uint64_t val) const override;<br>
+ RelExpr getRelExpr(RelType type, const Symbol &s,<br>
+ const uint8_t *loc) const override;<br>
+ RelType getDynRel(RelType type) const override;<br>
};<br>
} // namespace<br>
<br>
AMDGPU::AMDGPU() {<br>
- RelativeRel = R_AMDGPU_RELATIVE64;<br>
- GotRel = R_AMDGPU_ABS64;<br>
- NoneRel = R_AMDGPU_NONE;<br>
- SymbolicRel = R_AMDGPU_ABS64;<br>
+ relativeRel = R_AMDGPU_RELATIVE64;<br>
+ gotRel = R_AMDGPU_ABS64;<br>
+ noneRel = R_AMDGPU_NONE;<br>
+ symbolicRel = R_AMDGPU_ABS64;<br>
}<br>
<br>
-static uint32_t getEFlags(InputFile *File) {<br>
- return cast<ObjFile<ELF64LE>>(File)->getObj().getHeader()->e_flags;<br>
+static uint32_t getEFlags(InputFile *file) {<br>
+ return cast<ObjFile<ELF64LE>>(file)->getObj().getHeader()->e_flags;<br>
}<br>
<br>
uint32_t AMDGPU::calcEFlags() const {<br>
- assert(!ObjectFiles.empty());<br>
- uint32_t Ret = getEFlags(ObjectFiles[0]);<br>
+ assert(!objectFiles.empty());<br>
+ uint32_t ret = getEFlags(objectFiles[0]);<br>
<br>
// Verify that all input files have the same e_flags.<br>
- for (InputFile *F : makeArrayRef(ObjectFiles).slice(1)) {<br>
- if (Ret == getEFlags(F))<br>
+ for (InputFile *f : makeArrayRef(objectFiles).slice(1)) {<br>
+ if (ret == getEFlags(f))<br>
continue;<br>
- error("incompatible e_flags: " + toString(F));<br>
+ error("incompatible e_flags: " + toString(f));<br>
return 0;<br>
}<br>
- return Ret;<br>
+ return ret;<br>
}<br>
<br>
-void AMDGPU::relocateOne(uint8_t *Loc, RelType Type, uint64_t Val) const {<br>
- switch (Type) {<br>
+void AMDGPU::relocateOne(uint8_t *loc, RelType type, uint64_t val) const {<br>
+ switch (type) {<br>
case R_AMDGPU_ABS32:<br>
case R_AMDGPU_GOTPCREL:<br>
case R_AMDGPU_GOTPCREL32_LO:<br>
case R_AMDGPU_REL32:<br>
case R_AMDGPU_REL32_LO:<br>
- write32le(Loc, Val);<br>
+ write32le(loc, val);<br>
break;<br>
case R_AMDGPU_ABS64:<br>
case R_AMDGPU_REL64:<br>
- write64le(Loc, Val);<br>
+ write64le(loc, val);<br>
break;<br>
case R_AMDGPU_GOTPCREL32_HI:<br>
case R_AMDGPU_REL32_HI:<br>
- write32le(Loc, Val >> 32);<br>
+ write32le(loc, val >> 32);<br>
break;<br>
default:<br>
llvm_unreachable("unknown relocation");<br>
}<br>
}<br>
<br>
-RelExpr AMDGPU::getRelExpr(RelType Type, const Symbol &S,<br>
- const uint8_t *Loc) const {<br>
- switch (Type) {<br>
+RelExpr AMDGPU::getRelExpr(RelType type, const Symbol &s,<br>
+ const uint8_t *loc) const {<br>
+ switch (type) {<br>
case R_AMDGPU_ABS32:<br>
case R_AMDGPU_ABS64:<br>
return R_ABS;<br>
@@ -95,19 +95,19 @@ RelExpr AMDGPU::getRelExpr(RelType Type,<br>
case R_AMDGPU_GOTPCREL32_HI:<br>
return R_GOT_PC;<br>
default:<br>
- error(getErrorLocation(Loc) + "unknown relocation (" + Twine(Type) +<br>
- ") against symbol " + toString(S));<br>
+ error(getErrorLocation(loc) + "unknown relocation (" + Twine(type) +<br>
+ ") against symbol " + toString(s));<br>
return R_NONE;<br>
}<br>
}<br>
<br>
-RelType AMDGPU::getDynRel(RelType Type) const {<br>
- if (Type == R_AMDGPU_ABS64)<br>
- return Type;<br>
+RelType AMDGPU::getDynRel(RelType type) const {<br>
+ if (type == R_AMDGPU_ABS64)<br>
+ return type;<br>
return R_AMDGPU_NONE;<br>
}<br>
<br>
TargetInfo *elf::getAMDGPUTargetInfo() {<br>
- static AMDGPU Target;<br>
- return &Target;<br>
+ static AMDGPU target;<br>
+ return ⌖<br>
}<br>
<br>
Modified: lld/trunk/ELF/Arch/ARM.cpp<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_ELF_Arch_ARM.cpp-3Frev-3D365595-26r1-3D365594-26r2-3D365595-26view-3Ddiff&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=VBgAqeWff7sj2Gj00xkK5xSR24SKyuMR-sSBMHT7TiE&e=" rel="noreferrer" target="_blank">https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_ELF_Arch_ARM.cpp-3Frev-3D365595-26r1-3D365594-26r2-3D365595-26view-3Ddiff&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=VBgAqeWff7sj2Gj00xkK5xSR24SKyuMR-sSBMHT7TiE&e=</a> <br>
==============================================================================<br>
--- lld/trunk/ELF/Arch/ARM.cpp (original)<br>
+++ lld/trunk/ELF/Arch/ARM.cpp Tue Jul 9 22:00:37 2019<br>
@@ -26,62 +26,62 @@ class ARM final : public TargetInfo {<br>
public:<br>
ARM();<br>
uint32_t calcEFlags() const override;<br>
- RelExpr getRelExpr(RelType Type, const Symbol &S,<br>
- const uint8_t *Loc) const override;<br>
- RelType getDynRel(RelType Type) const override;<br>
- int64_t getImplicitAddend(const uint8_t *Buf, RelType Type) const override;<br>
- void writeGotPlt(uint8_t *Buf, const Symbol &S) const override;<br>
- void writeIgotPlt(uint8_t *Buf, const Symbol &S) const override;<br>
- void writePltHeader(uint8_t *Buf) const override;<br>
- void writePlt(uint8_t *Buf, uint64_t GotPltEntryAddr, uint64_t PltEntryAddr,<br>
- int32_t Index, unsigned RelOff) const override;<br>
- void addPltSymbols(InputSection &IS, uint64_t Off) const override;<br>
- void addPltHeaderSymbols(InputSection &ISD) const override;<br>
- bool needsThunk(RelExpr Expr, RelType Type, const InputFile *File,<br>
- uint64_t BranchAddr, const Symbol &S) const override;<br>
+ RelExpr getRelExpr(RelType type, const Symbol &s,<br>
+ const uint8_t *loc) const override;<br>
+ RelType getDynRel(RelType type) const override;<br>
+ int64_t getImplicitAddend(const uint8_t *buf, RelType type) const override;<br>
+ void writeGotPlt(uint8_t *buf, const Symbol &s) const override;<br>
+ void writeIgotPlt(uint8_t *buf, const Symbol &s) const override;<br>
+ void writePltHeader(uint8_t *buf) const override;<br>
+ void writePlt(uint8_t *buf, uint64_t gotPltEntryAddr, uint64_t pltEntryAddr,<br>
+ int32_t index, unsigned relOff) const override;<br>
+ void addPltSymbols(InputSection &isec, uint64_t off) const override;<br>
+ void addPltHeaderSymbols(InputSection &isd) const override;<br>
+ bool needsThunk(RelExpr expr, RelType type, const InputFile *file,<br>
+ uint64_t branchAddr, const Symbol &s) const override;<br>
uint32_t getThunkSectionSpacing() const override;<br>
- bool inBranchRange(RelType Type, uint64_t Src, uint64_t Dst) const override;<br>
- void relocateOne(uint8_t *Loc, RelType Type, uint64_t Val) const override;<br>
+ bool inBranchRange(RelType type, uint64_t src, uint64_t dst) const override;<br>
+ void relocateOne(uint8_t *loc, RelType type, uint64_t val) const override;<br>
};<br>
} // namespace<br>
<br>
ARM::ARM() {<br>
- CopyRel = R_ARM_COPY;<br>
- RelativeRel = R_ARM_RELATIVE;<br>
- IRelativeRel = R_ARM_IRELATIVE;<br>
- GotRel = R_ARM_GLOB_DAT;<br>
- NoneRel = R_ARM_NONE;<br>
- PltRel = R_ARM_JUMP_SLOT;<br>
- SymbolicRel = R_ARM_ABS32;<br>
- TlsGotRel = R_ARM_TLS_TPOFF32;<br>
- TlsModuleIndexRel = R_ARM_TLS_DTPMOD32;<br>
- TlsOffsetRel = R_ARM_TLS_DTPOFF32;<br>
- GotBaseSymInGotPlt = false;<br>
- PltEntrySize = 16;<br>
- PltHeaderSize = 32;<br>
- TrapInstr = {0xd4, 0xd4, 0xd4, 0xd4};<br>
- NeedsThunks = true;<br>
+ copyRel = R_ARM_COPY;<br>
+ relativeRel = R_ARM_RELATIVE;<br>
+ iRelativeRel = R_ARM_IRELATIVE;<br>
+ gotRel = R_ARM_GLOB_DAT;<br>
+ noneRel = R_ARM_NONE;<br>
+ pltRel = R_ARM_JUMP_SLOT;<br>
+ symbolicRel = R_ARM_ABS32;<br>
+ tlsGotRel = R_ARM_TLS_TPOFF32;<br>
+ tlsModuleIndexRel = R_ARM_TLS_DTPMOD32;<br>
+ tlsOffsetRel = R_ARM_TLS_DTPOFF32;<br>
+ gotBaseSymInGotPlt = false;<br>
+ pltEntrySize = 16;<br>
+ pltHeaderSize = 32;<br>
+ trapInstr = {0xd4, 0xd4, 0xd4, 0xd4};<br>
+ needsThunks = true;<br>
}<br>
<br>
uint32_t ARM::calcEFlags() const {<br>
// The ABIFloatType is used by loaders to detect the floating point calling<br>
// convention.<br>
- uint32_t ABIFloatType = 0;<br>
- if (Config->ARMVFPArgs == ARMVFPArgKind::Base ||<br>
- Config->ARMVFPArgs == ARMVFPArgKind::Default)<br>
- ABIFloatType = EF_ARM_ABI_FLOAT_SOFT;<br>
- else if (Config->ARMVFPArgs == ARMVFPArgKind::VFP)<br>
- ABIFloatType = EF_ARM_ABI_FLOAT_HARD;<br>
+ uint32_t abiFloatType = 0;<br>
+ if (config->armVFPArgs == ARMVFPArgKind::Base ||<br>
+ config->armVFPArgs == ARMVFPArgKind::Default)<br>
+ abiFloatType = EF_ARM_ABI_FLOAT_SOFT;<br>
+ else if (config->armVFPArgs == ARMVFPArgKind::VFP)<br>
+ abiFloatType = EF_ARM_ABI_FLOAT_HARD;<br>
<br>
// We don't currently use any features incompatible with EF_ARM_EABI_VER5,<br>
// but we don't have any firm guarantees of conformance. Linux AArch64<br>
// kernels (as of 2016) require an EABI version to be set.<br>
- return EF_ARM_EABI_VER5 | ABIFloatType;<br>
+ return EF_ARM_EABI_VER5 | abiFloatType;<br>
}<br>
<br>
-RelExpr ARM::getRelExpr(RelType Type, const Symbol &S,<br>
- const uint8_t *Loc) const {<br>
- switch (Type) {<br>
+RelExpr ARM::getRelExpr(RelType type, const Symbol &s,<br>
+ const uint8_t *loc) const {<br>
+ switch (type) {<br>
case R_ARM_THM_JUMP11:<br>
return R_PC;<br>
case R_ARM_CALL:<br>
@@ -106,11 +106,11 @@ RelExpr ARM::getRelExpr(RelType Type, co<br>
case R_ARM_SBREL32:<br>
return R_ARM_SBREL;<br>
case R_ARM_TARGET1:<br>
- return Config->Target1Rel ? R_PC : R_ABS;<br>
+ return config->target1Rel ? R_PC : R_ABS;<br>
case R_ARM_TARGET2:<br>
- if (Config->Target2 == Target2Policy::Rel)<br>
+ if (config->target2 == Target2Policy::Rel)<br>
return R_PC;<br>
- if (Config->Target2 == Target2Policy::Abs)<br>
+ if (config->target2 == Target2Policy::Abs)<br>
return R_ABS;<br>
return R_GOT_PC;<br>
case R_ARM_TLS_GD32:<br>
@@ -143,25 +143,25 @@ RelExpr ARM::getRelExpr(RelType Type, co<br>
}<br>
}<br>
<br>
-RelType ARM::getDynRel(RelType Type) const {<br>
- if ((Type == R_ARM_ABS32) || (Type == R_ARM_TARGET1 && !Config->Target1Rel))<br>
+RelType ARM::getDynRel(RelType type) const {<br>
+ if ((type == R_ARM_ABS32) || (type == R_ARM_TARGET1 && !config->target1Rel))<br>
return R_ARM_ABS32;<br>
return R_ARM_NONE;<br>
}<br>
<br>
-void ARM::writeGotPlt(uint8_t *Buf, const Symbol &) const {<br>
- write32le(Buf, In.Plt->getVA());<br>
+void ARM::writeGotPlt(uint8_t *buf, const Symbol &) const {<br>
+ write32le(buf, in.plt->getVA());<br>
}<br>
<br>
-void ARM::writeIgotPlt(uint8_t *Buf, const Symbol &S) const {<br>
+void ARM::writeIgotPlt(uint8_t *buf, const Symbol &s) const {<br>
// An ARM entry is the address of the ifunc resolver function.<br>
- write32le(Buf, S.getVA());<br>
+ write32le(buf, s.getVA());<br>
}<br>
<br>
// Long form PLT Header that does not have any restrictions on the displacement<br>
// of the .plt from the .plt.got.<br>
-static void writePltHeaderLong(uint8_t *Buf) {<br>
- const uint8_t PltData[] = {<br>
+static void writePltHeaderLong(uint8_t *buf) {<br>
+ const uint8_t pltData[] = {<br>
0x04, 0xe0, 0x2d, 0xe5, // str lr, [sp,#-4]!<br>
0x04, 0xe0, 0x9f, 0xe5, // ldr lr, L2<br>
0x0e, 0xe0, 0x8f, 0xe0, // L1: add lr, pc, lr<br>
@@ -170,128 +170,128 @@ static void writePltHeaderLong(uint8_t *<br>
0xd4, 0xd4, 0xd4, 0xd4, // Pad to 32-byte boundary<br>
0xd4, 0xd4, 0xd4, 0xd4, // Pad to 32-byte boundary<br>
0xd4, 0xd4, 0xd4, 0xd4};<br>
- memcpy(Buf, PltData, sizeof(PltData));<br>
- uint64_t GotPlt = In.GotPlt->getVA();<br>
- uint64_t L1 = In.Plt->getVA() + 8;<br>
- write32le(Buf + 16, GotPlt - L1 - 8);<br>
+ memcpy(buf, pltData, sizeof(pltData));<br>
+ uint64_t gotPlt = in.gotPlt->getVA();<br>
+ uint64_t l1 = in.plt->getVA() + 8;<br>
+ write32le(buf + 16, gotPlt - l1 - 8);<br>
}<br>
<br>
// The default PLT header requires the .plt.got to be within 128 Mb of the<br>
// .plt in the positive direction.<br>
-void ARM::writePltHeader(uint8_t *Buf) const {<br>
+void ARM::writePltHeader(uint8_t *buf) const {<br>
// Use a similar sequence to that in writePlt(), the difference is the calling<br>
// conventions mean we use lr instead of ip. The PLT entry is responsible for<br>
// saving lr on the stack, the dynamic loader is responsible for reloading<br>
// it.<br>
- const uint32_t PltData[] = {<br>
+ const uint32_t pltData[] = {<br>
0xe52de004, // L1: str lr, [sp,#-4]!<br>
0xe28fe600, // add lr, pc, #0x0NN00000 &(.got.plt - L1 - 4)<br>
0xe28eea00, // add lr, lr, #0x000NN000 &(.got.plt - L1 - 4)<br>
0xe5bef000, // ldr pc, [lr, #0x00000NNN] &(.got.plt -L1 - 4)<br>
};<br>
<br>
- uint64_t Offset = In.GotPlt->getVA() - In.Plt->getVA() - 4;<br>
- if (!llvm::isUInt<27>(Offset)) {<br>
+ uint64_t offset = in.gotPlt->getVA() - in.plt->getVA() - 4;<br>
+ if (!llvm::isUInt<27>(offset)) {<br>
// We cannot encode the Offset, use the long form.<br>
- writePltHeaderLong(Buf);<br>
+ writePltHeaderLong(buf);<br>
return;<br>
}<br>
- write32le(Buf + 0, PltData[0]);<br>
- write32le(Buf + 4, PltData[1] | ((Offset >> 20) & 0xff));<br>
- write32le(Buf + 8, PltData[2] | ((Offset >> 12) & 0xff));<br>
- write32le(Buf + 12, PltData[3] | (Offset & 0xfff));<br>
- memcpy(Buf + 16, TrapInstr.data(), 4); // Pad to 32-byte boundary<br>
- memcpy(Buf + 20, TrapInstr.data(), 4);<br>
- memcpy(Buf + 24, TrapInstr.data(), 4);<br>
- memcpy(Buf + 28, TrapInstr.data(), 4);<br>
+ write32le(buf + 0, pltData[0]);<br>
+ write32le(buf + 4, pltData[1] | ((offset >> 20) & 0xff));<br>
+ write32le(buf + 8, pltData[2] | ((offset >> 12) & 0xff));<br>
+ write32le(buf + 12, pltData[3] | (offset & 0xfff));<br>
+ memcpy(buf + 16, trapInstr.data(), 4); // Pad to 32-byte boundary<br>
+ memcpy(buf + 20, trapInstr.data(), 4);<br>
+ memcpy(buf + 24, trapInstr.data(), 4);<br>
+ memcpy(buf + 28, trapInstr.data(), 4);<br>
}<br>
<br>
-void ARM::addPltHeaderSymbols(InputSection &IS) const {<br>
- addSyntheticLocal("$a", STT_NOTYPE, 0, 0, IS);<br>
- addSyntheticLocal("$d", STT_NOTYPE, 16, 0, IS);<br>
+void ARM::addPltHeaderSymbols(InputSection &isec) const {<br>
+ addSyntheticLocal("$a", STT_NOTYPE, 0, 0, isec);<br>
+ addSyntheticLocal("$d", STT_NOTYPE, 16, 0, isec);<br>
}<br>
<br>
// Long form PLT entries that do not have any restrictions on the displacement<br>
// of the .plt from the .plt.got.<br>
-static void writePltLong(uint8_t *Buf, uint64_t GotPltEntryAddr,<br>
- uint64_t PltEntryAddr, int32_t Index,<br>
- unsigned RelOff) {<br>
- const uint8_t PltData[] = {<br>
+static void writePltLong(uint8_t *buf, uint64_t gotPltEntryAddr,<br>
+ uint64_t pltEntryAddr, int32_t index,<br>
+ unsigned relOff) {<br>
+ const uint8_t pltData[] = {<br>
0x04, 0xc0, 0x9f, 0xe5, // ldr ip, L2<br>
0x0f, 0xc0, 0x8c, 0xe0, // L1: add ip, ip, pc<br>
0x00, 0xf0, 0x9c, 0xe5, // ldr pc, [ip]<br>
0x00, 0x00, 0x00, 0x00, // L2: .word Offset(&(.plt.got) - L1 - 8<br>
};<br>
- memcpy(Buf, PltData, sizeof(PltData));<br>
- uint64_t L1 = PltEntryAddr + 4;<br>
- write32le(Buf + 12, GotPltEntryAddr - L1 - 8);<br>
+ memcpy(buf, pltData, sizeof(pltData));<br>
+ uint64_t l1 = pltEntryAddr + 4;<br>
+ write32le(buf + 12, gotPltEntryAddr - l1 - 8);<br>
}<br>
<br>
// The default PLT entries require the .plt.got to be within 128 Mb of the<br>
// .plt in the positive direction.<br>
-void ARM::writePlt(uint8_t *Buf, uint64_t GotPltEntryAddr,<br>
- uint64_t PltEntryAddr, int32_t Index,<br>
- unsigned RelOff) const {<br>
+void ARM::writePlt(uint8_t *buf, uint64_t gotPltEntryAddr,<br>
+ uint64_t pltEntryAddr, int32_t index,<br>
+ unsigned relOff) const {<br>
// The PLT entry is similar to the example given in Appendix A of ELF for<br>
// the Arm Architecture. Instead of using the Group Relocations to find the<br>
// optimal rotation for the 8-bit immediate used in the add instructions we<br>
// hard code the most compact rotations for simplicity. This saves a load<br>
// instruction over the long plt sequences.<br>
- const uint32_t PltData[] = {<br>
+ const uint32_t pltData[] = {<br>
0xe28fc600, // L1: add ip, pc, #0x0NN00000 Offset(&(.plt.got) - L1 - 8<br>
0xe28cca00, // add ip, ip, #0x000NN000 Offset(&(.plt.got) - L1 - 8<br>
0xe5bcf000, // ldr pc, [ip, #0x00000NNN] Offset(&(.plt.got) - L1 - 8<br>
};<br>
<br>
- uint64_t Offset = GotPltEntryAddr - PltEntryAddr - 8;<br>
- if (!llvm::isUInt<27>(Offset)) {<br>
+ uint64_t offset = gotPltEntryAddr - pltEntryAddr - 8;<br>
+ if (!llvm::isUInt<27>(offset)) {<br>
// We cannot encode the Offset, use the long form.<br>
- writePltLong(Buf, GotPltEntryAddr, PltEntryAddr, Index, RelOff);<br>
+ writePltLong(buf, gotPltEntryAddr, pltEntryAddr, index, relOff);<br>
return;<br>
}<br>
- write32le(Buf + 0, PltData[0] | ((Offset >> 20) & 0xff));<br>
- write32le(Buf + 4, PltData[1] | ((Offset >> 12) & 0xff));<br>
- write32le(Buf + 8, PltData[2] | (Offset & 0xfff));<br>
- memcpy(Buf + 12, TrapInstr.data(), 4); // Pad to 16-byte boundary<br>
+ write32le(buf + 0, pltData[0] | ((offset >> 20) & 0xff));<br>
+ write32le(buf + 4, pltData[1] | ((offset >> 12) & 0xff));<br>
+ write32le(buf + 8, pltData[2] | (offset & 0xfff));<br>
+ memcpy(buf + 12, trapInstr.data(), 4); // Pad to 16-byte boundary<br>
}<br>
<br>
-void ARM::addPltSymbols(InputSection &IS, uint64_t Off) const {<br>
- addSyntheticLocal("$a", STT_NOTYPE, Off, 0, IS);<br>
- addSyntheticLocal("$d", STT_NOTYPE, Off + 12, 0, IS);<br>
+void ARM::addPltSymbols(InputSection &isec, uint64_t off) const {<br>
+ addSyntheticLocal("$a", STT_NOTYPE, off, 0, isec);<br>
+ addSyntheticLocal("$d", STT_NOTYPE, off + 12, 0, isec);<br>
}<br>
<br>
-bool ARM::needsThunk(RelExpr Expr, RelType Type, const InputFile *File,<br>
- uint64_t BranchAddr, const Symbol &S) const {<br>
+bool ARM::needsThunk(RelExpr expr, RelType type, const InputFile *file,<br>
+ uint64_t branchAddr, const Symbol &s) const {<br>
// If S is an undefined weak symbol and does not have a PLT entry then it<br>
// will be resolved as a branch to the next instruction.<br>
- if (S.isUndefWeak() && !S.isInPlt())<br>
+ if (s.isUndefWeak() && !s.isInPlt())<br>
return false;<br>
// A state change from ARM to Thumb and vice versa must go through an<br>
// interworking thunk if the relocation type is not R_ARM_CALL or<br>
// R_ARM_THM_CALL.<br>
- switch (Type) {<br>
+ switch (type) {<br>
case R_ARM_PC24:<br>
case R_ARM_PLT32:<br>
case R_ARM_JUMP24:<br>
// Source is ARM, all PLT entries are ARM so no interworking required.<br>
// Otherwise we need to interwork if Symbol has bit 0 set (Thumb).<br>
- if (Expr == R_PC && ((S.getVA() & 1) == 1))<br>
+ if (expr == R_PC && ((s.getVA() & 1) == 1))<br>
return true;<br>
LLVM_FALLTHROUGH;<br>
case R_ARM_CALL: {<br>
- uint64_t Dst = (Expr == R_PLT_PC) ? S.getPltVA() : S.getVA();<br>
- return !inBranchRange(Type, BranchAddr, Dst);<br>
+ uint64_t dst = (expr == R_PLT_PC) ? s.getPltVA() : s.getVA();<br>
+ return !inBranchRange(type, branchAddr, dst);<br>
}<br>
case R_ARM_THM_JUMP19:<br>
case R_ARM_THM_JUMP24:<br>
// Source is Thumb, all PLT entries are ARM so interworking is required.<br>
// Otherwise we need to interwork if Symbol has bit 0 clear (ARM).<br>
- if (Expr == R_PLT_PC || ((S.getVA() & 1) == 0))<br>
+ if (expr == R_PLT_PC || ((s.getVA() & 1) == 0))<br>
return true;<br>
LLVM_FALLTHROUGH;<br>
case R_ARM_THM_CALL: {<br>
- uint64_t Dst = (Expr == R_PLT_PC) ? S.getPltVA() : S.getVA();<br>
- return !inBranchRange(Type, BranchAddr, Dst);<br>
+ uint64_t dst = (expr == R_PLT_PC) ? s.getPltVA() : s.getVA();<br>
+ return !inBranchRange(type, branchAddr, dst);<br>
}<br>
}<br>
return false;<br>
@@ -327,55 +327,55 @@ uint32_t ARM::getThunkSectionSpacing() c<br>
// range. On earlier Architectures such as ARMv4, ARMv5 and ARMv6 (except<br>
// ARMv6T2) the range is +/- 4MiB.<br>
<br>
- return (Config->ARMJ1J2BranchEncoding) ? 0x1000000 - 0x30000<br>
+ return (config->armJ1J2BranchEncoding) ? 0x1000000 - 0x30000<br>
: 0x400000 - 0x7500;<br>
}<br>
<br>
-bool ARM::inBranchRange(RelType Type, uint64_t Src, uint64_t Dst) const {<br>
- uint64_t Range;<br>
- uint64_t InstrSize;<br>
+bool ARM::inBranchRange(RelType type, uint64_t src, uint64_t dst) const {<br>
+ uint64_t range;<br>
+ uint64_t instrSize;<br>
<br>
- switch (Type) {<br>
+ switch (type) {<br>
case R_ARM_PC24:<br>
case R_ARM_PLT32:<br>
case R_ARM_JUMP24:<br>
case R_ARM_CALL:<br>
- Range = 0x2000000;<br>
- InstrSize = 4;<br>
+ range = 0x2000000;<br>
+ instrSize = 4;<br>
break;<br>
case R_ARM_THM_JUMP19:<br>
- Range = 0x100000;<br>
- InstrSize = 2;<br>
+ range = 0x100000;<br>
+ instrSize = 2;<br>
break;<br>
case R_ARM_THM_JUMP24:<br>
case R_ARM_THM_CALL:<br>
- Range = Config->ARMJ1J2BranchEncoding ? 0x1000000 : 0x400000;<br>
- InstrSize = 2;<br>
+ range = config->armJ1J2BranchEncoding ? 0x1000000 : 0x400000;<br>
+ instrSize = 2;<br>
break;<br>
default:<br>
return true;<br>
}<br>
// PC at Src is 2 instructions ahead, immediate of branch is signed<br>
- if (Src > Dst)<br>
- Range -= 2 * InstrSize;<br>
+ if (src > dst)<br>
+ range -= 2 * instrSize;<br>
else<br>
- Range += InstrSize;<br>
+ range += instrSize;<br>
<br>
- if ((Dst & 0x1) == 0)<br>
+ if ((dst & 0x1) == 0)<br>
// Destination is ARM, if ARM caller then Src is already 4-byte aligned.<br>
// If Thumb Caller (BLX) the Src address has bottom 2 bits cleared to ensure<br>
// destination will be 4 byte aligned.<br>
- Src &= ~0x3;<br>
+ src &= ~0x3;<br>
else<br>
// Bit 0 == 1 denotes Thumb state, it is not part of the range<br>
- Dst &= ~0x1;<br>
+ dst &= ~0x1;<br>
<br>
- uint64_t Distance = (Src > Dst) ? Src - Dst : Dst - Src;<br>
- return Distance <= Range;<br>
+ uint64_t distance = (src > dst) ? src - dst : dst - src;<br>
+ return distance <= range;<br>
}<br>
<br>
-void ARM::relocateOne(uint8_t *Loc, RelType Type, uint64_t Val) const {<br>
- switch (Type) {<br>
+void ARM::relocateOne(uint8_t *loc, RelType type, uint64_t val) const {<br>
+ switch (type) {<br>
case R_ARM_ABS32:<br>
case R_ARM_BASE_PREL:<br>
case R_ARM_GOTOFF32:<br>
@@ -393,132 +393,132 @@ void ARM::relocateOne(uint8_t *Loc, RelT<br>
case R_ARM_TLS_LE32:<br>
case R_ARM_TLS_TPOFF32:<br>
case R_ARM_TLS_DTPOFF32:<br>
- write32le(Loc, Val);<br>
+ write32le(loc, val);<br>
break;<br>
case R_ARM_PREL31:<br>
- checkInt(Loc, Val, 31, Type);<br>
- write32le(Loc, (read32le(Loc) & 0x80000000) | (Val & ~0x80000000));<br>
+ checkInt(loc, val, 31, type);<br>
+ write32le(loc, (read32le(loc) & 0x80000000) | (val & ~0x80000000));<br>
break;<br>
case R_ARM_CALL:<br>
// R_ARM_CALL is used for BL and BLX instructions, depending on the<br>
// value of bit 0 of Val, we must select a BL or BLX instruction<br>
- if (Val & 1) {<br>
+ if (val & 1) {<br>
// If bit 0 of Val is 1 the target is Thumb, we must select a BLX.<br>
// The BLX encoding is 0xfa:H:imm24 where Val = imm24:H:'1'<br>
- checkInt(Loc, Val, 26, Type);<br>
- write32le(Loc, 0xfa000000 | // opcode<br>
- ((Val & 2) << 23) | // H<br>
- ((Val >> 2) & 0x00ffffff)); // imm24<br>
+ checkInt(loc, val, 26, type);<br>
+ write32le(loc, 0xfa000000 | // opcode<br>
+ ((val & 2) << 23) | // H<br>
+ ((val >> 2) & 0x00ffffff)); // imm24<br>
break;<br>
}<br>
- if ((read32le(Loc) & 0xfe000000) == 0xfa000000)<br>
+ if ((read32le(loc) & 0xfe000000) == 0xfa000000)<br>
// BLX (always unconditional) instruction to an ARM Target, select an<br>
// unconditional BL.<br>
- write32le(Loc, 0xeb000000 | (read32le(Loc) & 0x00ffffff));<br>
+ write32le(loc, 0xeb000000 | (read32le(loc) & 0x00ffffff));<br>
// fall through as BL encoding is shared with B<br>
LLVM_FALLTHROUGH;<br>
case R_ARM_JUMP24:<br>
case R_ARM_PC24:<br>
case R_ARM_PLT32:<br>
- checkInt(Loc, Val, 26, Type);<br>
- write32le(Loc, (read32le(Loc) & ~0x00ffffff) | ((Val >> 2) & 0x00ffffff));<br>
+ checkInt(loc, val, 26, type);<br>
+ write32le(loc, (read32le(loc) & ~0x00ffffff) | ((val >> 2) & 0x00ffffff));<br>
break;<br>
case R_ARM_THM_JUMP11:<br>
- checkInt(Loc, Val, 12, Type);<br>
- write16le(Loc, (read32le(Loc) & 0xf800) | ((Val >> 1) & 0x07ff));<br>
+ checkInt(loc, val, 12, type);<br>
+ write16le(loc, (read32le(loc) & 0xf800) | ((val >> 1) & 0x07ff));<br>
break;<br>
case R_ARM_THM_JUMP19:<br>
// Encoding T3: Val = S:J2:J1:imm6:imm11:0<br>
- checkInt(Loc, Val, 21, Type);<br>
- write16le(Loc,<br>
- (read16le(Loc) & 0xfbc0) | // opcode cond<br>
- ((Val >> 10) & 0x0400) | // S<br>
- ((Val >> 12) & 0x003f)); // imm6<br>
- write16le(Loc + 2,<br>
+ checkInt(loc, val, 21, type);<br>
+ write16le(loc,<br>
+ (read16le(loc) & 0xfbc0) | // opcode cond<br>
+ ((val >> 10) & 0x0400) | // S<br>
+ ((val >> 12) & 0x003f)); // imm6<br>
+ write16le(loc + 2,<br>
0x8000 | // opcode<br>
- ((Val >> 8) & 0x0800) | // J2<br>
- ((Val >> 5) & 0x2000) | // J1<br>
- ((Val >> 1) & 0x07ff)); // imm11<br>
+ ((val >> 8) & 0x0800) | // J2<br>
+ ((val >> 5) & 0x2000) | // J1<br>
+ ((val >> 1) & 0x07ff)); // imm11<br>
break;<br>
case R_ARM_THM_CALL:<br>
// R_ARM_THM_CALL is used for BL and BLX instructions, depending on the<br>
// value of bit 0 of Val, we must select a BL or BLX instruction<br>
- if ((Val & 1) == 0) {<br>
+ if ((val & 1) == 0) {<br>
// Ensure BLX destination is 4-byte aligned. As BLX instruction may<br>
// only be two byte aligned. This must be done before overflow check<br>
- Val = alignTo(Val, 4);<br>
+ val = alignTo(val, 4);<br>
}<br>
// Bit 12 is 0 for BLX, 1 for BL<br>
- write16le(Loc + 2, (read16le(Loc + 2) & ~0x1000) | (Val & 1) << 12);<br>
- if (!Config->ARMJ1J2BranchEncoding) {<br>
+ write16le(loc + 2, (read16le(loc + 2) & ~0x1000) | (val & 1) << 12);<br>
+ if (!config->armJ1J2BranchEncoding) {<br>
// Older Arm architectures do not support R_ARM_THM_JUMP24 and have<br>
// different encoding rules and range due to J1 and J2 always being 1.<br>
- checkInt(Loc, Val, 23, Type);<br>
- write16le(Loc,<br>
+ checkInt(loc, val, 23, type);<br>
+ write16le(loc,<br>
0xf000 | // opcode<br>
- ((Val >> 12) & 0x07ff)); // imm11<br>
- write16le(Loc + 2,<br>
- (read16le(Loc + 2) & 0xd000) | // opcode<br>
+ ((val >> 12) & 0x07ff)); // imm11<br>
+ write16le(loc + 2,<br>
+ (read16le(loc + 2) & 0xd000) | // opcode<br>
0x2800 | // J1 == J2 == 1<br>
- ((Val >> 1) & 0x07ff)); // imm11<br>
+ ((val >> 1) & 0x07ff)); // imm11<br>
break;<br>
}<br>
// Fall through as rest of encoding is the same as B.W<br>
LLVM_FALLTHROUGH;<br>
case R_ARM_THM_JUMP24:<br>
// Encoding B T4, BL T1, BLX T2: Val = S:I1:I2:imm10:imm11:0<br>
- checkInt(Loc, Val, 25, Type);<br>
- write16le(Loc,<br>
+ checkInt(loc, val, 25, type);<br>
+ write16le(loc,<br>
0xf000 | // opcode<br>
- ((Val >> 14) & 0x0400) | // S<br>
- ((Val >> 12) & 0x03ff)); // imm10<br>
- write16le(Loc + 2,<br>
- (read16le(Loc + 2) & 0xd000) | // opcode<br>
- (((~(Val >> 10)) ^ (Val >> 11)) & 0x2000) | // J1<br>
- (((~(Val >> 11)) ^ (Val >> 13)) & 0x0800) | // J2<br>
- ((Val >> 1) & 0x07ff)); // imm11<br>
+ ((val >> 14) & 0x0400) | // S<br>
+ ((val >> 12) & 0x03ff)); // imm10<br>
+ write16le(loc + 2,<br>
+ (read16le(loc + 2) & 0xd000) | // opcode<br>
+ (((~(val >> 10)) ^ (val >> 11)) & 0x2000) | // J1<br>
+ (((~(val >> 11)) ^ (val >> 13)) & 0x0800) | // J2<br>
+ ((val >> 1) & 0x07ff)); // imm11<br>
break;<br>
case R_ARM_MOVW_ABS_NC:<br>
case R_ARM_MOVW_PREL_NC:<br>
- write32le(Loc, (read32le(Loc) & ~0x000f0fff) | ((Val & 0xf000) << 4) |<br>
- (Val & 0x0fff));<br>
+ write32le(loc, (read32le(loc) & ~0x000f0fff) | ((val & 0xf000) << 4) |<br>
+ (val & 0x0fff));<br>
break;<br>
case R_ARM_MOVT_ABS:<br>
case R_ARM_MOVT_PREL:<br>
- write32le(Loc, (read32le(Loc) & ~0x000f0fff) |<br>
- (((Val >> 16) & 0xf000) << 4) | ((Val >> 16) & 0xfff));<br>
+ write32le(loc, (read32le(loc) & ~0x000f0fff) |<br>
+ (((val >> 16) & 0xf000) << 4) | ((val >> 16) & 0xfff));<br>
break;<br>
case R_ARM_THM_MOVT_ABS:<br>
case R_ARM_THM_MOVT_PREL:<br>
// Encoding T1: A = imm4:i:imm3:imm8<br>
- write16le(Loc,<br>
+ write16le(loc,<br>
0xf2c0 | // opcode<br>
- ((Val >> 17) & 0x0400) | // i<br>
- ((Val >> 28) & 0x000f)); // imm4<br>
- write16le(Loc + 2,<br>
- (read16le(Loc + 2) & 0x8f00) | // opcode<br>
- ((Val >> 12) & 0x7000) | // imm3<br>
- ((Val >> 16) & 0x00ff)); // imm8<br>
+ ((val >> 17) & 0x0400) | // i<br>
+ ((val >> 28) & 0x000f)); // imm4<br>
+ write16le(loc + 2,<br>
+ (read16le(loc + 2) & 0x8f00) | // opcode<br>
+ ((val >> 12) & 0x7000) | // imm3<br>
+ ((val >> 16) & 0x00ff)); // imm8<br>
break;<br>
case R_ARM_THM_MOVW_ABS_NC:<br>
case R_ARM_THM_MOVW_PREL_NC:<br>
// Encoding T3: A = imm4:i:imm3:imm8<br>
- write16le(Loc,<br>
+ write16le(loc,<br>
0xf240 | // opcode<br>
- ((Val >> 1) & 0x0400) | // i<br>
- ((Val >> 12) & 0x000f)); // imm4<br>
- write16le(Loc + 2,<br>
- (read16le(Loc + 2) & 0x8f00) | // opcode<br>
- ((Val << 4) & 0x7000) | // imm3<br>
- (Val & 0x00ff)); // imm8<br>
+ ((val >> 1) & 0x0400) | // i<br>
+ ((val >> 12) & 0x000f)); // imm4<br>
+ write16le(loc + 2,<br>
+ (read16le(loc + 2) & 0x8f00) | // opcode<br>
+ ((val << 4) & 0x7000) | // imm3<br>
+ (val & 0x00ff)); // imm8<br>
break;<br>
default:<br>
- error(getErrorLocation(Loc) + "unrecognized relocation " + toString(Type));<br>
+ error(getErrorLocation(loc) + "unrecognized relocation " + toString(type));<br>
}<br>
}<br>
<br>
-int64_t ARM::getImplicitAddend(const uint8_t *Buf, RelType Type) const {<br>
- switch (Type) {<br>
+int64_t ARM::getImplicitAddend(const uint8_t *buf, RelType type) const {<br>
+ switch (type) {<br>
default:<br>
return 0;<br>
case R_ARM_ABS32:<br>
@@ -534,47 +534,47 @@ int64_t ARM::getImplicitAddend(const uin<br>
case R_ARM_TLS_LDO32:<br>
case R_ARM_TLS_IE32:<br>
case R_ARM_TLS_LE32:<br>
- return SignExtend64<32>(read32le(Buf));<br>
+ return SignExtend64<32>(read32le(buf));<br>
case R_ARM_PREL31:<br>
- return SignExtend64<31>(read32le(Buf));<br>
+ return SignExtend64<31>(read32le(buf));<br>
case R_ARM_CALL:<br>
case R_ARM_JUMP24:<br>
case R_ARM_PC24:<br>
case R_ARM_PLT32:<br>
- return SignExtend64<26>(read32le(Buf) << 2);<br>
+ return SignExtend64<26>(read32le(buf) << 2);<br>
case R_ARM_THM_JUMP11:<br>
- return SignExtend64<12>(read16le(Buf) << 1);<br>
+ return SignExtend64<12>(read16le(buf) << 1);<br>
case R_ARM_THM_JUMP19: {<br>
// Encoding T3: A = S:J2:J1:imm10:imm6:0<br>
- uint16_t Hi = read16le(Buf);<br>
- uint16_t Lo = read16le(Buf + 2);<br>
- return SignExtend64<20>(((Hi & 0x0400) << 10) | // S<br>
- ((Lo & 0x0800) << 8) | // J2<br>
- ((Lo & 0x2000) << 5) | // J1<br>
- ((Hi & 0x003f) << 12) | // imm6<br>
- ((Lo & 0x07ff) << 1)); // imm11:0<br>
+ uint16_t hi = read16le(buf);<br>
+ uint16_t lo = read16le(buf + 2);<br>
+ return SignExtend64<20>(((hi & 0x0400) << 10) | // S<br>
+ ((lo & 0x0800) << 8) | // J2<br>
+ ((lo & 0x2000) << 5) | // J1<br>
+ ((hi & 0x003f) << 12) | // imm6<br>
+ ((lo & 0x07ff) << 1)); // imm11:0<br>
}<br>
case R_ARM_THM_CALL:<br>
- if (!Config->ARMJ1J2BranchEncoding) {<br>
+ if (!config->armJ1J2BranchEncoding) {<br>
// Older Arm architectures do not support R_ARM_THM_JUMP24 and have<br>
// different encoding rules and range due to J1 and J2 always being 1.<br>
- uint16_t Hi = read16le(Buf);<br>
- uint16_t Lo = read16le(Buf + 2);<br>
- return SignExtend64<22>(((Hi & 0x7ff) << 12) | // imm11<br>
- ((Lo & 0x7ff) << 1)); // imm11:0<br>
+ uint16_t hi = read16le(buf);<br>
+ uint16_t lo = read16le(buf + 2);<br>
+ return SignExtend64<22>(((hi & 0x7ff) << 12) | // imm11<br>
+ ((lo & 0x7ff) << 1)); // imm11:0<br>
break;<br>
}<br>
LLVM_FALLTHROUGH;<br>
case R_ARM_THM_JUMP24: {<br>
// Encoding B T4, BL T1, BLX T2: A = S:I1:I2:imm10:imm11:0<br>
// I1 = NOT(J1 EOR S), I2 = NOT(J2 EOR S)<br>
- uint16_t Hi = read16le(Buf);<br>
- uint16_t Lo = read16le(Buf + 2);<br>
- return SignExtend64<24>(((Hi & 0x0400) << 14) | // S<br>
- (~((Lo ^ (Hi << 3)) << 10) & 0x00800000) | // I1<br>
- (~((Lo ^ (Hi << 1)) << 11) & 0x00400000) | // I2<br>
- ((Hi & 0x003ff) << 12) | // imm0<br>
- ((Lo & 0x007ff) << 1)); // imm11:0<br>
+ uint16_t hi = read16le(buf);<br>
+ uint16_t lo = read16le(buf + 2);<br>
+ return SignExtend64<24>(((hi & 0x0400) << 14) | // S<br>
+ (~((lo ^ (hi << 3)) << 10) & 0x00800000) | // I1<br>
+ (~((lo ^ (hi << 1)) << 11) & 0x00400000) | // I2<br>
+ ((hi & 0x003ff) << 12) | // imm0<br>
+ ((lo & 0x007ff) << 1)); // imm11:0<br>
}<br>
// ELF for the ARM Architecture 4.6.1.1 the implicit addend for MOVW and<br>
// MOVT is in the range -32768 <= A < 32768<br>
@@ -582,25 +582,25 @@ int64_t ARM::getImplicitAddend(const uin<br>
case R_ARM_MOVT_ABS:<br>
case R_ARM_MOVW_PREL_NC:<br>
case R_ARM_MOVT_PREL: {<br>
- uint64_t Val = read32le(Buf) & 0x000f0fff;<br>
- return SignExtend64<16>(((Val & 0x000f0000) >> 4) | (Val & 0x00fff));<br>
+ uint64_t val = read32le(buf) & 0x000f0fff;<br>
+ return SignExtend64<16>(((val & 0x000f0000) >> 4) | (val & 0x00fff));<br>
}<br>
case R_ARM_THM_MOVW_ABS_NC:<br>
case R_ARM_THM_MOVT_ABS:<br>
case R_ARM_THM_MOVW_PREL_NC:<br>
case R_ARM_THM_MOVT_PREL: {<br>
// Encoding T3: A = imm4:i:imm3:imm8<br>
- uint16_t Hi = read16le(Buf);<br>
- uint16_t Lo = read16le(Buf + 2);<br>
- return SignExtend64<16>(((Hi & 0x000f) << 12) | // imm4<br>
- ((Hi & 0x0400) << 1) | // i<br>
- ((Lo & 0x7000) >> 4) | // imm3<br>
- (Lo & 0x00ff)); // imm8<br>
+ uint16_t hi = read16le(buf);<br>
+ uint16_t lo = read16le(buf + 2);<br>
+ return SignExtend64<16>(((hi & 0x000f) << 12) | // imm4<br>
+ ((hi & 0x0400) << 1) | // i<br>
+ ((lo & 0x7000) >> 4) | // imm3<br>
+ (lo & 0x00ff)); // imm8<br>
}<br>
}<br>
}<br>
<br>
TargetInfo *elf::getARMTargetInfo() {<br>
- static ARM Target;<br>
- return &Target;<br>
+ static ARM target;<br>
+ return ⌖<br>
}<br>
<br>
Modified: lld/trunk/ELF/Arch/AVR.cpp<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_ELF_Arch_AVR.cpp-3Frev-3D365595-26r1-3D365594-26r2-3D365595-26view-3Ddiff&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=ou7_BuDBHsM0Ylesun0AV0Qw0AeVW_QxwKwA8758guc&e=" rel="noreferrer" target="_blank">https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_ELF_Arch_AVR.cpp-3Frev-3D365595-26r1-3D365594-26r2-3D365595-26view-3Ddiff&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=ou7_BuDBHsM0Ylesun0AV0Qw0AeVW_QxwKwA8758guc&e=</a> <br>
==============================================================================<br>
--- lld/trunk/ELF/Arch/AVR.cpp (original)<br>
+++ lld/trunk/ELF/Arch/AVR.cpp Tue Jul 9 22:00:37 2019<br>
@@ -43,34 +43,34 @@ namespace {<br>
class AVR final : public TargetInfo {<br>
public:<br>
AVR();<br>
- RelExpr getRelExpr(RelType Type, const Symbol &S,<br>
- const uint8_t *Loc) const override;<br>
- void relocateOne(uint8_t *Loc, RelType Type, uint64_t Val) const override;<br>
+ RelExpr getRelExpr(RelType type, const Symbol &s,<br>
+ const uint8_t *loc) const override;<br>
+ void relocateOne(uint8_t *loc, RelType type, uint64_t val) const override;<br>
};<br>
} // namespace<br>
<br>
-AVR::AVR() { NoneRel = R_AVR_NONE; }<br>
+AVR::AVR() { noneRel = R_AVR_NONE; }<br>
<br>
-RelExpr AVR::getRelExpr(RelType Type, const Symbol &S,<br>
- const uint8_t *Loc) const {<br>
+RelExpr AVR::getRelExpr(RelType type, const Symbol &s,<br>
+ const uint8_t *loc) const {<br>
return R_ABS;<br>
}<br>
<br>
-void AVR::relocateOne(uint8_t *Loc, RelType Type, uint64_t Val) const {<br>
- switch (Type) {<br>
+void AVR::relocateOne(uint8_t *loc, RelType type, uint64_t val) const {<br>
+ switch (type) {<br>
case R_AVR_CALL: {<br>
- uint16_t Hi = Val >> 17;<br>
- uint16_t Lo = Val >> 1;<br>
- write16le(Loc, read16le(Loc) | ((Hi >> 1) << 4) | (Hi & 1));<br>
- write16le(Loc + 2, Lo);<br>
+ uint16_t hi = val >> 17;<br>
+ uint16_t lo = val >> 1;<br>
+ write16le(loc, read16le(loc) | ((hi >> 1) << 4) | (hi & 1));<br>
+ write16le(loc + 2, lo);<br>
break;<br>
}<br>
default:<br>
- error(getErrorLocation(Loc) + "unrecognized relocation " + toString(Type));<br>
+ error(getErrorLocation(loc) + "unrecognized relocation " + toString(type));<br>
}<br>
}<br>
<br>
TargetInfo *elf::getAVRTargetInfo() {<br>
- static AVR Target;<br>
- return &Target;<br>
+ static AVR target;<br>
+ return ⌖<br>
}<br>
<br>
Modified: lld/trunk/ELF/Arch/Hexagon.cpp<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_ELF_Arch_Hexagon.cpp-3Frev-3D365595-26r1-3D365594-26r2-3D365595-26view-3Ddiff&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=8TI1OYMfEvb6Qt0wbtn3TN0wxSlLGjsTaHFtGmh-3bE&e=" rel="noreferrer" target="_blank">https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_ELF_Arch_Hexagon.cpp-3Frev-3D365595-26r1-3D365594-26r2-3D365595-26view-3Ddiff&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=8TI1OYMfEvb6Qt0wbtn3TN0wxSlLGjsTaHFtGmh-3bE&e=</a> <br>
==============================================================================<br>
--- lld/trunk/ELF/Arch/Hexagon.cpp (original)<br>
+++ lld/trunk/ELF/Arch/Hexagon.cpp Tue Jul 9 22:00:37 2019<br>
@@ -27,65 +27,65 @@ class Hexagon final : public TargetInfo<br>
public:<br>
Hexagon();<br>
uint32_t calcEFlags() const override;<br>
- RelExpr getRelExpr(RelType Type, const Symbol &S,<br>
- const uint8_t *Loc) const override;<br>
- void relocateOne(uint8_t *Loc, RelType Type, uint64_t Val) const override;<br>
- void writePltHeader(uint8_t *Buf) const override;<br>
- void writePlt(uint8_t *Buf, uint64_t GotPltEntryAddr, uint64_t PltEntryAddr,<br>
- int32_t Index, unsigned RelOff) const override;<br>
+ RelExpr getRelExpr(RelType type, const Symbol &s,<br>
+ const uint8_t *loc) const override;<br>
+ void relocateOne(uint8_t *loc, RelType type, uint64_t val) const override;<br>
+ void writePltHeader(uint8_t *buf) const override;<br>
+ void writePlt(uint8_t *buf, uint64_t gotPltEntryAddr, uint64_t pltEntryAddr,<br>
+ int32_t index, unsigned relOff) const override;<br>
};<br>
} // namespace<br>
<br>
Hexagon::Hexagon() {<br>
- PltRel = R_HEX_JMP_SLOT;<br>
- RelativeRel = R_HEX_RELATIVE;<br>
- GotRel = R_HEX_GLOB_DAT;<br>
- SymbolicRel = R_HEX_32;<br>
+ pltRel = R_HEX_JMP_SLOT;<br>
+ relativeRel = R_HEX_RELATIVE;<br>
+ gotRel = R_HEX_GLOB_DAT;<br>
+ symbolicRel = R_HEX_32;<br>
<br>
// The zero'th GOT entry is reserved for the address of _DYNAMIC. The<br>
// next 3 are reserved for the dynamic loader.<br>
- GotPltHeaderEntriesNum = 4;<br>
+ gotPltHeaderEntriesNum = 4;<br>
<br>
- PltEntrySize = 16;<br>
- PltHeaderSize = 32;<br>
+ pltEntrySize = 16;<br>
+ pltHeaderSize = 32;<br>
<br>
// Hexagon Linux uses 64K pages by default.<br>
- DefaultMaxPageSize = 0x10000;<br>
- NoneRel = R_HEX_NONE;<br>
+ defaultMaxPageSize = 0x10000;<br>
+ noneRel = R_HEX_NONE;<br>
}<br>
<br>
uint32_t Hexagon::calcEFlags() const {<br>
- assert(!ObjectFiles.empty());<br>
+ assert(!objectFiles.empty());<br>
<br>
// The architecture revision must always be equal to or greater than<br>
// greatest revision in the list of inputs.<br>
- uint32_t Ret = 0;<br>
- for (InputFile *F : ObjectFiles) {<br>
- uint32_t EFlags = cast<ObjFile<ELF32LE>>(F)->getObj().getHeader()->e_flags;<br>
- if (EFlags > Ret)<br>
- Ret = EFlags;<br>
+ uint32_t ret = 0;<br>
+ for (InputFile *f : objectFiles) {<br>
+ uint32_t eflags = cast<ObjFile<ELF32LE>>(f)->getObj().getHeader()->e_flags;<br>
+ if (eflags > ret)<br>
+ ret = eflags;<br>
}<br>
- return Ret;<br>
+ return ret;<br>
}<br>
<br>
-static uint32_t applyMask(uint32_t Mask, uint32_t Data) {<br>
- uint32_t Result = 0;<br>
- size_t Off = 0;<br>
-<br>
- for (size_t Bit = 0; Bit != 32; ++Bit) {<br>
- uint32_t ValBit = (Data >> Off) & 1;<br>
- uint32_t MaskBit = (Mask >> Bit) & 1;<br>
- if (MaskBit) {<br>
- Result |= (ValBit << Bit);<br>
- ++Off;<br>
+static uint32_t applyMask(uint32_t mask, uint32_t data) {<br>
+ uint32_t result = 0;<br>
+ size_t off = 0;<br>
+<br>
+ for (size_t bit = 0; bit != 32; ++bit) {<br>
+ uint32_t valBit = (data >> off) & 1;<br>
+ uint32_t maskBit = (mask >> bit) & 1;<br>
+ if (maskBit) {<br>
+ result |= (valBit << bit);<br>
+ ++off;<br>
}<br>
}<br>
- return Result;<br>
+ return result;<br>
}<br>
<br>
-RelExpr Hexagon::getRelExpr(RelType Type, const Symbol &S,<br>
- const uint8_t *Loc) const {<br>
- switch (Type) {<br>
+RelExpr Hexagon::getRelExpr(RelType type, const Symbol &s,<br>
+ const uint8_t *loc) const {<br>
+ switch (type) {<br>
case R_HEX_B9_PCREL:<br>
case R_HEX_B9_PCREL_X:<br>
case R_HEX_B13_PCREL:<br>
@@ -108,16 +108,16 @@ RelExpr Hexagon::getRelExpr(RelType Type<br>
}<br>
}<br>
<br>
-static uint32_t findMaskR6(uint32_t Insn) {<br>
+static uint32_t findMaskR6(uint32_t insn) {<br>
// There are (arguably too) many relocation masks for the DSP's<br>
// R_HEX_6_X type. The table below is used to select the correct mask<br>
// for the given instruction.<br>
struct InstructionMask {<br>
- uint32_t CmpMask;<br>
- uint32_t RelocMask;<br>
+ uint32_t cmpMask;<br>
+ uint32_t relocMask;<br>
};<br>
<br>
- static const InstructionMask R6[] = {<br>
+ static const InstructionMask r6[] = {<br>
{0x38000000, 0x0000201f}, {0x39000000, 0x0000201f},<br>
{0x3e000000, 0x00001f80}, {0x3f000000, 0x00001f80},<br>
{0x40000000, 0x000020f8}, {0x41000000, 0x000007e0},<br>
@@ -135,124 +135,124 @@ static uint32_t findMaskR6(uint32_t Insn<br>
// Duplex forms have a fixed mask and parse bits 15:14 are always<br>
// zero. Non-duplex insns will always have at least one bit set in the<br>
// parse field.<br>
- if ((0xC000 & Insn) == 0x0)<br>
+ if ((0xC000 & insn) == 0x0)<br>
return 0x03f00000;<br>
<br>
- for (InstructionMask I : R6)<br>
- if ((0xff000000 & Insn) == I.CmpMask)<br>
- return I.RelocMask;<br>
+ for (InstructionMask i : r6)<br>
+ if ((0xff000000 & insn) == i.cmpMask)<br>
+ return i.relocMask;<br>
<br>
error("unrecognized instruction for R_HEX_6 relocation: 0x" +<br>
- utohexstr(Insn));<br>
+ utohexstr(insn));<br>
return 0;<br>
}<br>
<br>
-static uint32_t findMaskR8(uint32_t Insn) {<br>
- if ((0xff000000 & Insn) == 0xde000000)<br>
+static uint32_t findMaskR8(uint32_t insn) {<br>
+ if ((0xff000000 & insn) == 0xde000000)<br>
return 0x00e020e8;<br>
- if ((0xff000000 & Insn) == 0x3c000000)<br>
+ if ((0xff000000 & insn) == 0x3c000000)<br>
return 0x0000207f;<br>
return 0x00001fe0;<br>
}<br>
<br>
-static uint32_t findMaskR11(uint32_t Insn) {<br>
- if ((0xff000000 & Insn) == 0xa1000000)<br>
+static uint32_t findMaskR11(uint32_t insn) {<br>
+ if ((0xff000000 & insn) == 0xa1000000)<br>
return 0x060020ff;<br>
return 0x06003fe0;<br>
}<br>
<br>
-static uint32_t findMaskR16(uint32_t Insn) {<br>
- if ((0xff000000 & Insn) == 0x48000000)<br>
+static uint32_t findMaskR16(uint32_t insn) {<br>
+ if ((0xff000000 & insn) == 0x48000000)<br>
return 0x061f20ff;<br>
- if ((0xff000000 & Insn) == 0x49000000)<br>
+ if ((0xff000000 & insn) == 0x49000000)<br>
return 0x061f3fe0;<br>
- if ((0xff000000 & Insn) == 0x78000000)<br>
+ if ((0xff000000 & insn) == 0x78000000)<br>
return 0x00df3fe0;<br>
- if ((0xff000000 & Insn) == 0xb0000000)<br>
+ if ((0xff000000 & insn) == 0xb0000000)<br>
return 0x0fe03fe0;<br>
<br>
error("unrecognized instruction for R_HEX_16_X relocation: 0x" +<br>
- utohexstr(Insn));<br>
+ utohexstr(insn));<br>
return 0;<br>
}<br>
<br>
-static void or32le(uint8_t *P, int32_t V) { write32le(P, read32le(P) | V); }<br>
+static void or32le(uint8_t *p, int32_t v) { write32le(p, read32le(p) | v); }<br>
<br>
-void Hexagon::relocateOne(uint8_t *Loc, RelType Type, uint64_t Val) const {<br>
- switch (Type) {<br>
+void Hexagon::relocateOne(uint8_t *loc, RelType type, uint64_t val) const {<br>
+ switch (type) {<br>
case R_HEX_NONE:<br>
break;<br>
case R_HEX_6_PCREL_X:<br>
case R_HEX_6_X:<br>
- or32le(Loc, applyMask(findMaskR6(read32le(Loc)), Val));<br>
+ or32le(loc, applyMask(findMaskR6(read32le(loc)), val));<br>
break;<br>
case R_HEX_8_X:<br>
- or32le(Loc, applyMask(findMaskR8(read32le(Loc)), Val));<br>
+ or32le(loc, applyMask(findMaskR8(read32le(loc)), val));<br>
break;<br>
case R_HEX_9_X:<br>
- or32le(Loc, applyMask(0x00003fe0, Val & 0x3f));<br>
+ or32le(loc, applyMask(0x00003fe0, val & 0x3f));<br>
break;<br>
case R_HEX_10_X:<br>
- or32le(Loc, applyMask(0x00203fe0, Val & 0x3f));<br>
+ or32le(loc, applyMask(0x00203fe0, val & 0x3f));<br>
break;<br>
case R_HEX_11_X:<br>
case R_HEX_GOT_11_X:<br>
- or32le(Loc, applyMask(findMaskR11(read32le(Loc)), Val & 0x3f));<br>
+ or32le(loc, applyMask(findMaskR11(read32le(loc)), val & 0x3f));<br>
break;<br>
case R_HEX_12_X:<br>
- or32le(Loc, applyMask(0x000007e0, Val));<br>
+ or32le(loc, applyMask(0x000007e0, val));<br>
break;<br>
case R_HEX_16_X: // These relocs only have 6 effective bits.<br>
case R_HEX_GOT_16_X:<br>
- or32le(Loc, applyMask(findMaskR16(read32le(Loc)), Val & 0x3f));<br>
+ or32le(loc, applyMask(findMaskR16(read32le(loc)), val & 0x3f));<br>
break;<br>
case R_HEX_32:<br>
case R_HEX_32_PCREL:<br>
- or32le(Loc, Val);<br>
+ or32le(loc, val);<br>
break;<br>
case R_HEX_32_6_X:<br>
case R_HEX_GOT_32_6_X:<br>
- or32le(Loc, applyMask(0x0fff3fff, Val >> 6));<br>
+ or32le(loc, applyMask(0x0fff3fff, val >> 6));<br>
break;<br>
case R_HEX_B9_PCREL:<br>
- or32le(Loc, applyMask(0x003000fe, Val >> 2));<br>
+ or32le(loc, applyMask(0x003000fe, val >> 2));<br>
break;<br>
case R_HEX_B9_PCREL_X:<br>
- or32le(Loc, applyMask(0x003000fe, Val & 0x3f));<br>
+ or32le(loc, applyMask(0x003000fe, val & 0x3f));<br>
break;<br>
case R_HEX_B13_PCREL:<br>
- or32le(Loc, applyMask(0x00202ffe, Val >> 2));<br>
+ or32le(loc, applyMask(0x00202ffe, val >> 2));<br>
break;<br>
case R_HEX_B15_PCREL:<br>
- or32le(Loc, applyMask(0x00df20fe, Val >> 2));<br>
+ or32le(loc, applyMask(0x00df20fe, val >> 2));<br>
break;<br>
case R_HEX_B15_PCREL_X:<br>
- or32le(Loc, applyMask(0x00df20fe, Val & 0x3f));<br>
+ or32le(loc, applyMask(0x00df20fe, val & 0x3f));<br>
break;<br>
case R_HEX_B22_PCREL:<br>
case R_HEX_PLT_B22_PCREL:<br>
- or32le(Loc, applyMask(0x1ff3ffe, Val >> 2));<br>
+ or32le(loc, applyMask(0x1ff3ffe, val >> 2));<br>
break;<br>
case R_HEX_B22_PCREL_X:<br>
- or32le(Loc, applyMask(0x1ff3ffe, Val & 0x3f));<br>
+ or32le(loc, applyMask(0x1ff3ffe, val & 0x3f));<br>
break;<br>
case R_HEX_B32_PCREL_X:<br>
- or32le(Loc, applyMask(0x0fff3fff, Val >> 6));<br>
+ or32le(loc, applyMask(0x0fff3fff, val >> 6));<br>
break;<br>
case R_HEX_HI16:<br>
- or32le(Loc, applyMask(0x00c03fff, Val >> 16));<br>
+ or32le(loc, applyMask(0x00c03fff, val >> 16));<br>
break;<br>
case R_HEX_LO16:<br>
- or32le(Loc, applyMask(0x00c03fff, Val));<br>
+ or32le(loc, applyMask(0x00c03fff, val));<br>
break;<br>
default:<br>
- error(getErrorLocation(Loc) + "unrecognized relocation " + toString(Type));<br>
+ error(getErrorLocation(loc) + "unrecognized relocation " + toString(type));<br>
break;<br>
}<br>
}<br>
<br>
-void Hexagon::writePltHeader(uint8_t *Buf) const {<br>
- const uint8_t PltData[] = {<br>
+void Hexagon::writePltHeader(uint8_t *buf) const {<br>
+ const uint8_t pltData[] = {<br>
0x00, 0x40, 0x00, 0x00, // { immext (#0)<br>
0x1c, 0xc0, 0x49, 0x6a, // r28 = add (pc, ##GOT0@PCREL) } # @GOT0<br>
0x0e, 0x42, 0x9c, 0xe2, // { r14 -= add (r28, #16) # offset of GOTn<br>
@@ -262,30 +262,30 @@ void Hexagon::writePltHeader(uint8_t *Bu<br>
0x00, 0xc0, 0x9c, 0x52, // jumpr r28 } # call dynamic linker<br>
0x0c, 0xdb, 0x00, 0x54, // trap0(#0xdb) # bring plt0 into 16byte alignment<br>
};<br>
- memcpy(Buf, PltData, sizeof(PltData));<br>
+ memcpy(buf, pltData, sizeof(pltData));<br>
<br>
// Offset from PLT0 to the GOT.<br>
- uint64_t Off = In.GotPlt->getVA() - In.Plt->getVA();<br>
- relocateOne(Buf, R_HEX_B32_PCREL_X, Off);<br>
- relocateOne(Buf + 4, R_HEX_6_PCREL_X, Off);<br>
+ uint64_t off = in.gotPlt->getVA() - in.plt->getVA();<br>
+ relocateOne(buf, R_HEX_B32_PCREL_X, off);<br>
+ relocateOne(buf + 4, R_HEX_6_PCREL_X, off);<br>
}<br>
<br>
-void Hexagon::writePlt(uint8_t *Buf, uint64_t GotPltEntryAddr,<br>
- uint64_t PltEntryAddr, int32_t Index,<br>
- unsigned RelOff) const {<br>
- const uint8_t Inst[] = {<br>
+void Hexagon::writePlt(uint8_t *buf, uint64_t gotPltEntryAddr,<br>
+ uint64_t pltEntryAddr, int32_t index,<br>
+ unsigned relOff) const {<br>
+ const uint8_t inst[] = {<br>
0x00, 0x40, 0x00, 0x00, // { immext (#0)<br>
0x0e, 0xc0, 0x49, 0x6a, // r14 = add (pc, ##GOTn@PCREL) }<br>
0x1c, 0xc0, 0x8e, 0x91, // r28 = memw (r14)<br>
0x00, 0xc0, 0x9c, 0x52, // jumpr r28<br>
};<br>
- memcpy(Buf, Inst, sizeof(Inst));<br>
+ memcpy(buf, inst, sizeof(inst));<br>
<br>
- relocateOne(Buf, R_HEX_B32_PCREL_X, GotPltEntryAddr - PltEntryAddr);<br>
- relocateOne(Buf + 4, R_HEX_6_PCREL_X, GotPltEntryAddr - PltEntryAddr);<br>
+ relocateOne(buf, R_HEX_B32_PCREL_X, gotPltEntryAddr - pltEntryAddr);<br>
+ relocateOne(buf + 4, R_HEX_6_PCREL_X, gotPltEntryAddr - pltEntryAddr);<br>
}<br>
<br>
TargetInfo *elf::getHexagonTargetInfo() {<br>
- static Hexagon Target;<br>
- return &Target;<br>
+ static Hexagon target;<br>
+ return ⌖<br>
}<br>
<br>
Modified: lld/trunk/ELF/Arch/MSP430.cpp<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_ELF_Arch_MSP430.cpp-3Frev-3D365595-26r1-3D365594-26r2-3D365595-26view-3Ddiff&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=gO20EqD2GAZ9hLj_k1r3fHjyHbKLKKznX9VIeyi8wPI&e=" rel="noreferrer" target="_blank">https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_ELF_Arch_MSP430.cpp-3Frev-3D365595-26r1-3D365594-26r2-3D365595-26view-3Ddiff&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=gO20EqD2GAZ9hLj_k1r3fHjyHbKLKKznX9VIeyi8wPI&e=</a> <br>
==============================================================================<br>
--- lld/trunk/ELF/Arch/MSP430.cpp (original)<br>
+++ lld/trunk/ELF/Arch/MSP430.cpp Tue Jul 9 22:00:37 2019<br>
@@ -33,20 +33,20 @@ namespace {<br>
class MSP430 final : public TargetInfo {<br>
public:<br>
MSP430();<br>
- RelExpr getRelExpr(RelType Type, const Symbol &S,<br>
- const uint8_t *Loc) const override;<br>
- void relocateOne(uint8_t *Loc, RelType Type, uint64_t Val) const override;<br>
+ RelExpr getRelExpr(RelType type, const Symbol &s,<br>
+ const uint8_t *loc) const override;<br>
+ void relocateOne(uint8_t *loc, RelType type, uint64_t val) const override;<br>
};<br>
} // namespace<br>
<br>
MSP430::MSP430() {<br>
// mov.b #0, r3<br>
- TrapInstr = {0x43, 0x43, 0x43, 0x43};<br>
+ trapInstr = {0x43, 0x43, 0x43, 0x43};<br>
}<br>
<br>
-RelExpr MSP430::getRelExpr(RelType Type, const Symbol &S,<br>
- const uint8_t *Loc) const {<br>
- switch (Type) {<br>
+RelExpr MSP430::getRelExpr(RelType type, const Symbol &s,<br>
+ const uint8_t *loc) const {<br>
+ switch (type) {<br>
case R_MSP430_10_PCREL:<br>
case R_MSP430_16_PCREL:<br>
case R_MSP430_16_PCREL_BYTE:<br>
@@ -59,35 +59,35 @@ RelExpr MSP430::getRelExpr(RelType Type,<br>
}<br>
}<br>
<br>
-void MSP430::relocateOne(uint8_t *Loc, RelType Type, uint64_t Val) const {<br>
- switch (Type) {<br>
+void MSP430::relocateOne(uint8_t *loc, RelType type, uint64_t val) const {<br>
+ switch (type) {<br>
case R_MSP430_8:<br>
- checkIntUInt(Loc, Val, 8, Type);<br>
- *Loc = Val;<br>
+ checkIntUInt(loc, val, 8, type);<br>
+ *loc = val;<br>
break;<br>
case R_MSP430_16:<br>
case R_MSP430_16_PCREL:<br>
case R_MSP430_16_BYTE:<br>
case R_MSP430_16_PCREL_BYTE:<br>
- checkIntUInt(Loc, Val, 16, Type);<br>
- write16le(Loc, Val);<br>
+ checkIntUInt(loc, val, 16, type);<br>
+ write16le(loc, val);<br>
break;<br>
case R_MSP430_32:<br>
- checkIntUInt(Loc, Val, 32, Type);<br>
- write32le(Loc, Val);<br>
+ checkIntUInt(loc, val, 32, type);<br>
+ write32le(loc, val);<br>
break;<br>
case R_MSP430_10_PCREL: {<br>
- int16_t Offset = ((int16_t)Val >> 1) - 1;<br>
- checkInt(Loc, Offset, 10, Type);<br>
- write16le(Loc, (read16le(Loc) & 0xFC00) | (Offset & 0x3FF));<br>
+ int16_t offset = ((int16_t)val >> 1) - 1;<br>
+ checkInt(loc, offset, 10, type);<br>
+ write16le(loc, (read16le(loc) & 0xFC00) | (offset & 0x3FF));<br>
break;<br>
}<br>
default:<br>
- error(getErrorLocation(Loc) + "unrecognized relocation " + toString(Type));<br>
+ error(getErrorLocation(loc) + "unrecognized relocation " + toString(type));<br>
}<br>
}<br>
<br>
TargetInfo *elf::getMSP430TargetInfo() {<br>
- static MSP430 Target;<br>
- return &Target;<br>
+ static MSP430 target;<br>
+ return ⌖<br>
}<br>
<br>
Modified: lld/trunk/ELF/Arch/Mips.cpp<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_ELF_Arch_Mips.cpp-3Frev-3D365595-26r1-3D365594-26r2-3D365595-26view-3Ddiff&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=5twCzKi6O5GBmjBudR6q-tKAK0KcPichjaHnZQKiK1g&e=" rel="noreferrer" target="_blank">https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_ELF_Arch_Mips.cpp-3Frev-3D365595-26r1-3D365594-26r2-3D365595-26view-3Ddiff&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=5twCzKi6O5GBmjBudR6q-tKAK0KcPichjaHnZQKiK1g&e=</a> <br>
==============================================================================<br>
--- lld/trunk/ELF/Arch/Mips.cpp (original)<br>
+++ lld/trunk/ELF/Arch/Mips.cpp Tue Jul 9 22:00:37 2019<br>
@@ -28,47 +28,47 @@ template <class ELFT> class MIPS final :<br>
public:<br>
MIPS();<br>
uint32_t calcEFlags() const override;<br>
- RelExpr getRelExpr(RelType Type, const Symbol &S,<br>
- const uint8_t *Loc) const override;<br>
- int64_t getImplicitAddend(const uint8_t *Buf, RelType Type) const override;<br>
- RelType getDynRel(RelType Type) const override;<br>
- void writeGotPlt(uint8_t *Buf, const Symbol &S) const override;<br>
- void writePltHeader(uint8_t *Buf) const override;<br>
- void writePlt(uint8_t *Buf, uint64_t GotPltEntryAddr, uint64_t PltEntryAddr,<br>
- int32_t Index, unsigned RelOff) const override;<br>
- bool needsThunk(RelExpr Expr, RelType Type, const InputFile *File,<br>
- uint64_t BranchAddr, const Symbol &S) const override;<br>
- void relocateOne(uint8_t *Loc, RelType Type, uint64_t Val) const override;<br>
- bool usesOnlyLowPageBits(RelType Type) const override;<br>
+ RelExpr getRelExpr(RelType type, const Symbol &s,<br>
+ const uint8_t *loc) const override;<br>
+ int64_t getImplicitAddend(const uint8_t *buf, RelType type) const override;<br>
+ RelType getDynRel(RelType type) const override;<br>
+ void writeGotPlt(uint8_t *buf, const Symbol &s) const override;<br>
+ void writePltHeader(uint8_t *buf) const override;<br>
+ void writePlt(uint8_t *buf, uint64_t gotPltEntryAddr, uint64_t pltEntryAddr,<br>
+ int32_t index, unsigned relOff) const override;<br>
+ bool needsThunk(RelExpr expr, RelType type, const InputFile *file,<br>
+ uint64_t branchAddr, const Symbol &s) const override;<br>
+ void relocateOne(uint8_t *loc, RelType type, uint64_t val) const override;<br>
+ bool usesOnlyLowPageBits(RelType type) const override;<br>
};<br>
} // namespace<br>
<br>
template <class ELFT> MIPS<ELFT>::MIPS() {<br>
- GotPltHeaderEntriesNum = 2;<br>
- DefaultMaxPageSize = 65536;<br>
- GotBaseSymInGotPlt = false;<br>
- PltEntrySize = 16;<br>
- PltHeaderSize = 32;<br>
- CopyRel = R_MIPS_COPY;<br>
- NoneRel = R_MIPS_NONE;<br>
- PltRel = R_MIPS_JUMP_SLOT;<br>
- NeedsThunks = true;<br>
+ gotPltHeaderEntriesNum = 2;<br>
+ defaultMaxPageSize = 65536;<br>
+ gotBaseSymInGotPlt = false;<br>
+ pltEntrySize = 16;<br>
+ pltHeaderSize = 32;<br>
+ copyRel = R_MIPS_COPY;<br>
+ noneRel = R_MIPS_NONE;<br>
+ pltRel = R_MIPS_JUMP_SLOT;<br>
+ needsThunks = true;<br>
<br>
// Set `sigrie 1` as a trap instruction.<br>
- write32(TrapInstr.data(), 0x04170001);<br>
+ write32(trapInstr.data(), 0x04170001);<br>
<br>
if (ELFT::Is64Bits) {<br>
- RelativeRel = (R_MIPS_64 << 8) | R_MIPS_REL32;<br>
- SymbolicRel = R_MIPS_64;<br>
- TlsGotRel = R_MIPS_TLS_TPREL64;<br>
- TlsModuleIndexRel = R_MIPS_TLS_DTPMOD64;<br>
- TlsOffsetRel = R_MIPS_TLS_DTPREL64;<br>
+ relativeRel = (R_MIPS_64 << 8) | R_MIPS_REL32;<br>
+ symbolicRel = R_MIPS_64;<br>
+ tlsGotRel = R_MIPS_TLS_TPREL64;<br>
+ tlsModuleIndexRel = R_MIPS_TLS_DTPMOD64;<br>
+ tlsOffsetRel = R_MIPS_TLS_DTPREL64;<br>
} else {<br>
- RelativeRel = R_MIPS_REL32;<br>
- SymbolicRel = R_MIPS_32;<br>
- TlsGotRel = R_MIPS_TLS_TPREL32;<br>
- TlsModuleIndexRel = R_MIPS_TLS_DTPMOD32;<br>
- TlsOffsetRel = R_MIPS_TLS_DTPREL32;<br>
+ relativeRel = R_MIPS_REL32;<br>
+ symbolicRel = R_MIPS_32;<br>
+ tlsGotRel = R_MIPS_TLS_TPREL32;<br>
+ tlsModuleIndexRel = R_MIPS_TLS_DTPMOD32;<br>
+ tlsOffsetRel = R_MIPS_TLS_DTPREL32;<br>
}<br>
}<br>
<br>
@@ -77,13 +77,13 @@ template <class ELFT> uint32_t MIPS<ELFT<br>
}<br>
<br>
template <class ELFT><br>
-RelExpr MIPS<ELFT>::getRelExpr(RelType Type, const Symbol &S,<br>
- const uint8_t *Loc) const {<br>
+RelExpr MIPS<ELFT>::getRelExpr(RelType type, const Symbol &s,<br>
+ const uint8_t *loc) const {<br>
// See comment in the calculateMipsRelChain.<br>
- if (ELFT::Is64Bits || Config->MipsN32Abi)<br>
- Type &= 0xff;<br>
+ if (ELFT::Is64Bits || config->mipsN32Abi)<br>
+ type &= 0xff;<br>
<br>
- switch (Type) {<br>
+ switch (type) {<br>
case R_MIPS_JALR:<br>
case R_MICROMIPS_JALR:<br>
return R_HINT;<br>
@@ -107,9 +107,9 @@ RelExpr MIPS<ELFT>::getRelExpr(RelType T<br>
// offset between start of function and 'gp' value which by default<br>
// equal to the start of .got section. In that case we consider these<br>
// relocations as relative.<br>
- if (&S == ElfSym::MipsGpDisp)<br>
+ if (&s == ElfSym::mipsGpDisp)<br>
return R_MIPS_GOT_GP_PC;<br>
- if (&S == ElfSym::MipsLocalGp)<br>
+ if (&s == ElfSym::mipsLocalGp)<br>
return R_MIPS_GOT_GP;<br>
LLVM_FALLTHROUGH;<br>
case R_MIPS_32:<br>
@@ -146,7 +146,7 @@ RelExpr MIPS<ELFT>::getRelExpr(RelType T<br>
return R_PC;<br>
case R_MIPS_GOT16:<br>
case R_MICROMIPS_GOT16:<br>
- if (S.isLocal())<br>
+ if (s.isLocal())<br>
return R_MIPS_GOT_LOCAL_PAGE;<br>
LLVM_FALLTHROUGH;<br>
case R_MIPS_CALL16:<br>
@@ -175,213 +175,213 @@ RelExpr MIPS<ELFT>::getRelExpr(RelType T<br>
case R_MIPS_NONE:<br>
return R_NONE;<br>
default:<br>
- error(getErrorLocation(Loc) + "unknown relocation (" + Twine(Type) +<br>
- ") against symbol " + toString(S));<br>
+ error(getErrorLocation(loc) + "unknown relocation (" + Twine(type) +<br>
+ ") against symbol " + toString(s));<br>
return R_NONE;<br>
}<br>
}<br>
<br>
-template <class ELFT> RelType MIPS<ELFT>::getDynRel(RelType Type) const {<br>
- if (Type == SymbolicRel)<br>
- return Type;<br>
+template <class ELFT> RelType MIPS<ELFT>::getDynRel(RelType type) const {<br>
+ if (type == symbolicRel)<br>
+ return type;<br>
return R_MIPS_NONE;<br>
}<br>
<br>
template <class ELFT><br>
-void MIPS<ELFT>::writeGotPlt(uint8_t *Buf, const Symbol &) const {<br>
- uint64_t VA = In.Plt->getVA();<br>
+void MIPS<ELFT>::writeGotPlt(uint8_t *buf, const Symbol &) const {<br>
+ uint64_t va = in.plt->getVA();<br>
if (isMicroMips())<br>
- VA |= 1;<br>
- write32<ELFT::TargetEndianness>(Buf, VA);<br>
+ va |= 1;<br>
+ write32<ELFT::TargetEndianness>(buf, va);<br>
}<br>
<br>
-template <endianness E> static uint32_t readShuffle(const uint8_t *Loc) {<br>
+template <endianness E> static uint32_t readShuffle(const uint8_t *loc) {<br>
// The major opcode of a microMIPS instruction needs to appear<br>
// in the first 16-bit word (lowest address) for efficient hardware<br>
// decode so that it knows if the instruction is 16-bit or 32-bit<br>
// as early as possible. To do so, little-endian binaries keep 16-bit<br>
// words in a big-endian order. That is why we have to swap these<br>
// words to get a correct value.<br>
- uint32_t V = read32<E>(Loc);<br>
+ uint32_t v = read32<E>(loc);<br>
if (E == support::little)<br>
- return (V << 16) | (V >> 16);<br>
- return V;<br>
+ return (v << 16) | (v >> 16);<br>
+ return v;<br>
}<br>
<br>
template <endianness E><br>
-static void writeValue(uint8_t *Loc, uint64_t V, uint8_t BitsSize,<br>
- uint8_t Shift) {<br>
- uint32_t Instr = read32<E>(Loc);<br>
- uint32_t Mask = 0xffffffff >> (32 - BitsSize);<br>
- uint32_t Data = (Instr & ~Mask) | ((V >> Shift) & Mask);<br>
- write32<E>(Loc, Data);<br>
+static void writeValue(uint8_t *loc, uint64_t v, uint8_t bitsSize,<br>
+ uint8_t shift) {<br>
+ uint32_t instr = read32<E>(loc);<br>
+ uint32_t mask = 0xffffffff >> (32 - bitsSize);<br>
+ uint32_t data = (instr & ~mask) | ((v >> shift) & mask);<br>
+ write32<E>(loc, data);<br>
}<br>
<br>
template <endianness E><br>
-static void writeShuffleValue(uint8_t *Loc, uint64_t V, uint8_t BitsSize,<br>
- uint8_t Shift) {<br>
+static void writeShuffleValue(uint8_t *loc, uint64_t v, uint8_t bitsSize,<br>
+ uint8_t shift) {<br>
// See comments in readShuffle for purpose of this code.<br>
- uint16_t *Words = (uint16_t *)Loc;<br>
+ uint16_t *words = (uint16_t *)loc;<br>
if (E == support::little)<br>
- std::swap(Words[0], Words[1]);<br>
+ std::swap(words[0], words[1]);<br>
<br>
- writeValue<E>(Loc, V, BitsSize, Shift);<br>
+ writeValue<E>(loc, v, bitsSize, shift);<br>
<br>
if (E == support::little)<br>
- std::swap(Words[0], Words[1]);<br>
+ std::swap(words[0], words[1]);<br>
}<br>
<br>
template <endianness E><br>
-static void writeMicroRelocation16(uint8_t *Loc, uint64_t V, uint8_t BitsSize,<br>
- uint8_t Shift) {<br>
- uint16_t Instr = read16<E>(Loc);<br>
- uint16_t Mask = 0xffff >> (16 - BitsSize);<br>
- uint16_t Data = (Instr & ~Mask) | ((V >> Shift) & Mask);<br>
- write16<E>(Loc, Data);<br>
+static void writeMicroRelocation16(uint8_t *loc, uint64_t v, uint8_t bitsSize,<br>
+ uint8_t shift) {<br>
+ uint16_t instr = read16<E>(loc);<br>
+ uint16_t mask = 0xffff >> (16 - bitsSize);<br>
+ uint16_t data = (instr & ~mask) | ((v >> shift) & mask);<br>
+ write16<E>(loc, data);<br>
}<br>
<br>
-template <class ELFT> void MIPS<ELFT>::writePltHeader(uint8_t *Buf) const {<br>
- const endianness E = ELFT::TargetEndianness;<br>
+template <class ELFT> void MIPS<ELFT>::writePltHeader(uint8_t *buf) const {<br>
+ const endianness e = ELFT::TargetEndianness;<br>
if (isMicroMips()) {<br>
- uint64_t GotPlt = In.GotPlt->getVA();<br>
- uint64_t Plt = In.Plt->getVA();<br>
+ uint64_t gotPlt = in.gotPlt->getVA();<br>
+ uint64_t plt = in.plt->getVA();<br>
// Overwrite trap instructions written by Writer::writeTrapInstr.<br>
- memset(Buf, 0, PltHeaderSize);<br>
+ memset(buf, 0, pltHeaderSize);<br>
<br>
- write16<E>(Buf, isMipsR6() ? 0x7860 : 0x7980); // addiupc v1, (GOTPLT) - .<br>
- write16<E>(Buf + 4, 0xff23); // lw $25, 0($3)<br>
- write16<E>(Buf + 8, 0x0535); // subu16 $2, $2, $3<br>
- write16<E>(Buf + 10, 0x2525); // srl16 $2, $2, 2<br>
- write16<E>(Buf + 12, 0x3302); // addiu $24, $2, -2<br>
- write16<E>(Buf + 14, 0xfffe);<br>
- write16<E>(Buf + 16, 0x0dff); // move $15, $31<br>
+ write16<e>(buf, isMipsR6() ? 0x7860 : 0x7980); // addiupc v1, (GOTPLT) - .<br>
+ write16<e>(buf + 4, 0xff23); // lw $25, 0($3)<br>
+ write16<e>(buf + 8, 0x0535); // subu16 $2, $2, $3<br>
+ write16<e>(buf + 10, 0x2525); // srl16 $2, $2, 2<br>
+ write16<e>(buf + 12, 0x3302); // addiu $24, $2, -2<br>
+ write16<e>(buf + 14, 0xfffe);<br>
+ write16<e>(buf + 16, 0x0dff); // move $15, $31<br>
if (isMipsR6()) {<br>
- write16<E>(Buf + 18, 0x0f83); // move $28, $3<br>
- write16<E>(Buf + 20, 0x472b); // jalrc $25<br>
- write16<E>(Buf + 22, 0x0c00); // nop<br>
- relocateOne(Buf, R_MICROMIPS_PC19_S2, GotPlt - Plt);<br>
+ write16<e>(buf + 18, 0x0f83); // move $28, $3<br>
+ write16<e>(buf + 20, 0x472b); // jalrc $25<br>
+ write16<e>(buf + 22, 0x0c00); // nop<br>
+ relocateOne(buf, R_MICROMIPS_PC19_S2, gotPlt - plt);<br>
} else {<br>
- write16<E>(Buf + 18, 0x45f9); // jalrc $25<br>
- write16<E>(Buf + 20, 0x0f83); // move $28, $3<br>
- write16<E>(Buf + 22, 0x0c00); // nop<br>
- relocateOne(Buf, R_MICROMIPS_PC23_S2, GotPlt - Plt);<br>
+ write16<e>(buf + 18, 0x45f9); // jalrc $25<br>
+ write16<e>(buf + 20, 0x0f83); // move $28, $3<br>
+ write16<e>(buf + 22, 0x0c00); // nop<br>
+ relocateOne(buf, R_MICROMIPS_PC23_S2, gotPlt - plt);<br>
}<br>
return;<br>
}<br>
<br>
- if (Config->MipsN32Abi) {<br>
- write32<E>(Buf, 0x3c0e0000); // lui $14, %hi(&GOTPLT[0])<br>
- write32<E>(Buf + 4, 0x8dd90000); // lw $25, %lo(&GOTPLT[0])($14)<br>
- write32<E>(Buf + 8, 0x25ce0000); // addiu $14, $14, %lo(&GOTPLT[0])<br>
- write32<E>(Buf + 12, 0x030ec023); // subu $24, $24, $14<br>
- write32<E>(Buf + 16, 0x03e07825); // move $15, $31<br>
- write32<E>(Buf + 20, 0x0018c082); // srl $24, $24, 2<br>
+ if (config->mipsN32Abi) {<br>
+ write32<e>(buf, 0x3c0e0000); // lui $14, %hi(&GOTPLT[0])<br>
+ write32<e>(buf + 4, 0x8dd90000); // lw $25, %lo(&GOTPLT[0])($14)<br>
+ write32<e>(buf + 8, 0x25ce0000); // addiu $14, $14, %lo(&GOTPLT[0])<br>
+ write32<e>(buf + 12, 0x030ec023); // subu $24, $24, $14<br>
+ write32<e>(buf + 16, 0x03e07825); // move $15, $31<br>
+ write32<e>(buf + 20, 0x0018c082); // srl $24, $24, 2<br>
} else if (ELFT::Is64Bits) {<br>
- write32<E>(Buf, 0x3c0e0000); // lui $14, %hi(&GOTPLT[0])<br>
- write32<E>(Buf + 4, 0xddd90000); // ld $25, %lo(&GOTPLT[0])($14)<br>
- write32<E>(Buf + 8, 0x25ce0000); // addiu $14, $14, %lo(&GOTPLT[0])<br>
- write32<E>(Buf + 12, 0x030ec023); // subu $24, $24, $14<br>
- write32<E>(Buf + 16, 0x03e07825); // move $15, $31<br>
- write32<E>(Buf + 20, 0x0018c0c2); // srl $24, $24, 3<br>
+ write32<e>(buf, 0x3c0e0000); // lui $14, %hi(&GOTPLT[0])<br>
+ write32<e>(buf + 4, 0xddd90000); // ld $25, %lo(&GOTPLT[0])($14)<br>
+ write32<e>(buf + 8, 0x25ce0000); // addiu $14, $14, %lo(&GOTPLT[0])<br>
+ write32<e>(buf + 12, 0x030ec023); // subu $24, $24, $14<br>
+ write32<e>(buf + 16, 0x03e07825); // move $15, $31<br>
+ write32<e>(buf + 20, 0x0018c0c2); // srl $24, $24, 3<br>
} else {<br>
- write32<E>(Buf, 0x3c1c0000); // lui $28, %hi(&GOTPLT[0])<br>
- write32<E>(Buf + 4, 0x8f990000); // lw $25, %lo(&GOTPLT[0])($28)<br>
- write32<E>(Buf + 8, 0x279c0000); // addiu $28, $28, %lo(&GOTPLT[0])<br>
- write32<E>(Buf + 12, 0x031cc023); // subu $24, $24, $28<br>
- write32<E>(Buf + 16, 0x03e07825); // move $15, $31<br>
- write32<E>(Buf + 20, 0x0018c082); // srl $24, $24, 2<br>
- }<br>
-<br>
- uint32_t JalrInst = Config->ZHazardplt ? 0x0320fc09 : 0x0320f809;<br>
- write32<E>(Buf + 24, JalrInst); // jalr.hb $25 or jalr $25<br>
- write32<E>(Buf + 28, 0x2718fffe); // subu $24, $24, 2<br>
-<br>
- uint64_t GotPlt = In.GotPlt->getVA();<br>
- writeValue<E>(Buf, GotPlt + 0x8000, 16, 16);<br>
- writeValue<E>(Buf + 4, GotPlt, 16, 0);<br>
- writeValue<E>(Buf + 8, GotPlt, 16, 0);<br>
+ write32<e>(buf, 0x3c1c0000); // lui $28, %hi(&GOTPLT[0])<br>
+ write32<e>(buf + 4, 0x8f990000); // lw $25, %lo(&GOTPLT[0])($28)<br>
+ write32<e>(buf + 8, 0x279c0000); // addiu $28, $28, %lo(&GOTPLT[0])<br>
+ write32<e>(buf + 12, 0x031cc023); // subu $24, $24, $28<br>
+ write32<e>(buf + 16, 0x03e07825); // move $15, $31<br>
+ write32<e>(buf + 20, 0x0018c082); // srl $24, $24, 2<br>
+ }<br>
+<br>
+ uint32_t jalrInst = config->zHazardplt ? 0x0320fc09 : 0x0320f809;<br>
+ write32<e>(buf + 24, jalrInst); // jalr.hb $25 or jalr $25<br>
+ write32<e>(buf + 28, 0x2718fffe); // subu $24, $24, 2<br>
+<br>
+ uint64_t gotPlt = in.gotPlt->getVA();<br>
+ writeValue<e>(buf, gotPlt + 0x8000, 16, 16);<br>
+ writeValue<e>(buf + 4, gotPlt, 16, 0);<br>
+ writeValue<e>(buf + 8, gotPlt, 16, 0);<br>
}<br>
<br>
template <class ELFT><br>
-void MIPS<ELFT>::writePlt(uint8_t *Buf, uint64_t GotPltEntryAddr,<br>
- uint64_t PltEntryAddr, int32_t Index,<br>
- unsigned RelOff) const {<br>
- const endianness E = ELFT::TargetEndianness;<br>
+void MIPS<ELFT>::writePlt(uint8_t *buf, uint64_t gotPltEntryAddr,<br>
+ uint64_t pltEntryAddr, int32_t index,<br>
+ unsigned relOff) const {<br>
+ const endianness e = ELFT::TargetEndianness;<br>
if (isMicroMips()) {<br>
// Overwrite trap instructions written by Writer::writeTrapInstr.<br>
- memset(Buf, 0, PltEntrySize);<br>
+ memset(buf, 0, pltEntrySize);<br>
<br>
if (isMipsR6()) {<br>
- write16<E>(Buf, 0x7840); // addiupc $2, (GOTPLT) - .<br>
- write16<E>(Buf + 4, 0xff22); // lw $25, 0($2)<br>
- write16<E>(Buf + 8, 0x0f02); // move $24, $2<br>
- write16<E>(Buf + 10, 0x4723); // jrc $25 / jr16 $25<br>
- relocateOne(Buf, R_MICROMIPS_PC19_S2, GotPltEntryAddr - PltEntryAddr);<br>
+ write16<e>(buf, 0x7840); // addiupc $2, (GOTPLT) - .<br>
+ write16<e>(buf + 4, 0xff22); // lw $25, 0($2)<br>
+ write16<e>(buf + 8, 0x0f02); // move $24, $2<br>
+ write16<e>(buf + 10, 0x4723); // jrc $25 / jr16 $25<br>
+ relocateOne(buf, R_MICROMIPS_PC19_S2, gotPltEntryAddr - pltEntryAddr);<br>
} else {<br>
- write16<E>(Buf, 0x7900); // addiupc $2, (GOTPLT) - .<br>
- write16<E>(Buf + 4, 0xff22); // lw $25, 0($2)<br>
- write16<E>(Buf + 8, 0x4599); // jrc $25 / jr16 $25<br>
- write16<E>(Buf + 10, 0x0f02); // move $24, $2<br>
- relocateOne(Buf, R_MICROMIPS_PC23_S2, GotPltEntryAddr - PltEntryAddr);<br>
+ write16<e>(buf, 0x7900); // addiupc $2, (GOTPLT) - .<br>
+ write16<e>(buf + 4, 0xff22); // lw $25, 0($2)<br>
+ write16<e>(buf + 8, 0x4599); // jrc $25 / jr16 $25<br>
+ write16<e>(buf + 10, 0x0f02); // move $24, $2<br>
+ relocateOne(buf, R_MICROMIPS_PC23_S2, gotPltEntryAddr - pltEntryAddr);<br>
}<br>
return;<br>
}<br>
<br>
- uint32_t LoadInst = ELFT::Is64Bits ? 0xddf90000 : 0x8df90000;<br>
- uint32_t JrInst = isMipsR6() ? (Config->ZHazardplt ? 0x03200409 : 0x03200009)<br>
- : (Config->ZHazardplt ? 0x03200408 : 0x03200008);<br>
- uint32_t AddInst = ELFT::Is64Bits ? 0x65f80000 : 0x25f80000;<br>
-<br>
- write32<E>(Buf, 0x3c0f0000); // lui $15, %hi(.got.plt entry)<br>
- write32<E>(Buf + 4, LoadInst); // l[wd] $25, %lo(.got.plt entry)($15)<br>
- write32<E>(Buf + 8, JrInst); // jr $25 / jr.hb $25<br>
- write32<E>(Buf + 12, AddInst); // [d]addiu $24, $15, %lo(.got.plt entry)<br>
- writeValue<E>(Buf, GotPltEntryAddr + 0x8000, 16, 16);<br>
- writeValue<E>(Buf + 4, GotPltEntryAddr, 16, 0);<br>
- writeValue<E>(Buf + 12, GotPltEntryAddr, 16, 0);<br>
+ uint32_t loadInst = ELFT::Is64Bits ? 0xddf90000 : 0x8df90000;<br>
+ uint32_t jrInst = isMipsR6() ? (config->zHazardplt ? 0x03200409 : 0x03200009)<br>
+ : (config->zHazardplt ? 0x03200408 : 0x03200008);<br>
+ uint32_t addInst = ELFT::Is64Bits ? 0x65f80000 : 0x25f80000;<br>
+<br>
+ write32<e>(buf, 0x3c0f0000); // lui $15, %hi(.got.plt entry)<br>
+ write32<e>(buf + 4, loadInst); // l[wd] $25, %lo(.got.plt entry)($15)<br>
+ write32<e>(buf + 8, jrInst); // jr $25 / jr.hb $25<br>
+ write32<e>(buf + 12, addInst); // [d]addiu $24, $15, %lo(.got.plt entry)<br>
+ writeValue<e>(buf, gotPltEntryAddr + 0x8000, 16, 16);<br>
+ writeValue<e>(buf + 4, gotPltEntryAddr, 16, 0);<br>
+ writeValue<e>(buf + 12, gotPltEntryAddr, 16, 0);<br>
}<br>
<br>
template <class ELFT><br>
-bool MIPS<ELFT>::needsThunk(RelExpr Expr, RelType Type, const InputFile *File,<br>
- uint64_t BranchAddr, const Symbol &S) const {<br>
+bool MIPS<ELFT>::needsThunk(RelExpr expr, RelType type, const InputFile *file,<br>
+ uint64_t branchAddr, const Symbol &s) const {<br>
// Any MIPS PIC code function is invoked with its address in register $t9.<br>
// So if we have a branch instruction from non-PIC code to the PIC one<br>
// we cannot make the jump directly and need to create a small stubs<br>
// to save the target function address.<br>
// See page 3-38 <a href="https://urldefense.proofpoint.com/v2/url?u=ftp-3A__www.linux-2Dmips.org_pub_linux_mips_doc_ABI_mipsabi.pdf&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=RAkf3Vl5MWzirfmkwopuyQjQ-5uEE95ctSfXOidHyHs&e=" rel="noreferrer" target="_blank">https://urldefense.proofpoint.com/v2/url?u=ftp-3A__www.linux-2Dmips.org_pub_linux_mips_doc_ABI_mipsabi.pdf&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=RAkf3Vl5MWzirfmkwopuyQjQ-5uEE95ctSfXOidHyHs&e=</a> <br>
- if (Type != R_MIPS_26 && Type != R_MIPS_PC26_S2 &&<br>
- Type != R_MICROMIPS_26_S1 && Type != R_MICROMIPS_PC26_S1)<br>
+ if (type != R_MIPS_26 && type != R_MIPS_PC26_S2 &&<br>
+ type != R_MICROMIPS_26_S1 && type != R_MICROMIPS_PC26_S1)<br>
return false;<br>
- auto *F = dyn_cast_or_null<ObjFile<ELFT>>(File);<br>
- if (!F)<br>
+ auto *f = dyn_cast_or_null<ObjFile<ELFT>>(file);<br>
+ if (!f)<br>
return false;<br>
// If current file has PIC code, LA25 stub is not required.<br>
- if (F->getObj().getHeader()->e_flags & EF_MIPS_PIC)<br>
+ if (f->getObj().getHeader()->e_flags & EF_MIPS_PIC)<br>
return false;<br>
- auto *D = dyn_cast<Defined>(&S);<br>
+ auto *d = dyn_cast<Defined>(&s);<br>
// LA25 is required if target file has PIC code<br>
// or target symbol is a PIC symbol.<br>
- return D && isMipsPIC<ELFT>(D);<br>
+ return d && isMipsPIC<ELFT>(d);<br>
}<br>
<br>
template <class ELFT><br>
-int64_t MIPS<ELFT>::getImplicitAddend(const uint8_t *Buf, RelType Type) const {<br>
- const endianness E = ELFT::TargetEndianness;<br>
- switch (Type) {<br>
+int64_t MIPS<ELFT>::getImplicitAddend(const uint8_t *buf, RelType type) const {<br>
+ const endianness e = ELFT::TargetEndianness;<br>
+ switch (type) {<br>
case R_MIPS_32:<br>
case R_MIPS_GPREL32:<br>
case R_MIPS_TLS_DTPREL32:<br>
case R_MIPS_TLS_TPREL32:<br>
- return SignExtend64<32>(read32<E>(Buf));<br>
+ return SignExtend64<32>(read32<e>(buf));<br>
case R_MIPS_26:<br>
// FIXME (simon): If the relocation target symbol is not a PLT entry<br>
// we should use another expression for calculation:<br>
// ((A << 2) | (P & 0xf0000000)) >> 2<br>
- return SignExtend64<28>(read32<E>(Buf) << 2);<br>
+ return SignExtend64<28>(read32<e>(buf) << 2);<br>
case R_MIPS_GOT16:<br>
case R_MIPS_HI16:<br>
case R_MIPS_PCHI16:<br>
- return SignExtend64<16>(read32<E>(Buf)) << 16;<br>
+ return SignExtend64<16>(read32<e>(buf)) << 16;<br>
case R_MIPS_GPREL16:<br>
case R_MIPS_LO16:<br>
case R_MIPS_PCLO16:<br>
@@ -389,54 +389,54 @@ int64_t MIPS<ELFT>::getImplicitAddend(co<br>
case R_MIPS_TLS_DTPREL_LO16:<br>
case R_MIPS_TLS_TPREL_HI16:<br>
case R_MIPS_TLS_TPREL_LO16:<br>
- return SignExtend64<16>(read32<E>(Buf));<br>
+ return SignExtend64<16>(read32<e>(buf));<br>
case R_MICROMIPS_GOT16:<br>
case R_MICROMIPS_HI16:<br>
- return SignExtend64<16>(readShuffle<E>(Buf)) << 16;<br>
+ return SignExtend64<16>(readShuffle<e>(buf)) << 16;<br>
case R_MICROMIPS_GPREL16:<br>
case R_MICROMIPS_LO16:<br>
case R_MICROMIPS_TLS_DTPREL_HI16:<br>
case R_MICROMIPS_TLS_DTPREL_LO16:<br>
case R_MICROMIPS_TLS_TPREL_HI16:<br>
case R_MICROMIPS_TLS_TPREL_LO16:<br>
- return SignExtend64<16>(readShuffle<E>(Buf));<br>
+ return SignExtend64<16>(readShuffle<e>(buf));<br>
case R_MICROMIPS_GPREL7_S2:<br>
- return SignExtend64<9>(readShuffle<E>(Buf) << 2);<br>
+ return SignExtend64<9>(readShuffle<e>(buf) << 2);<br>
case R_MIPS_PC16:<br>
- return SignExtend64<18>(read32<E>(Buf) << 2);<br>
+ return SignExtend64<18>(read32<e>(buf) << 2);<br>
case R_MIPS_PC19_S2:<br>
- return SignExtend64<21>(read32<E>(Buf) << 2);<br>
+ return SignExtend64<21>(read32<e>(buf) << 2);<br>
case R_MIPS_PC21_S2:<br>
- return SignExtend64<23>(read32<E>(Buf) << 2);<br>
+ return SignExtend64<23>(read32<e>(buf) << 2);<br>
case R_MIPS_PC26_S2:<br>
- return SignExtend64<28>(read32<E>(Buf) << 2);<br>
+ return SignExtend64<28>(read32<e>(buf) << 2);<br>
case R_MIPS_PC32:<br>
- return SignExtend64<32>(read32<E>(Buf));<br>
+ return SignExtend64<32>(read32<e>(buf));<br>
case R_MICROMIPS_26_S1:<br>
- return SignExtend64<27>(readShuffle<E>(Buf) << 1);<br>
+ return SignExtend64<27>(readShuffle<e>(buf) << 1);<br>
case R_MICROMIPS_PC7_S1:<br>
- return SignExtend64<8>(read16<E>(Buf) << 1);<br>
+ return SignExtend64<8>(read16<e>(buf) << 1);<br>
case R_MICROMIPS_PC10_S1:<br>
- return SignExtend64<11>(read16<E>(Buf) << 1);<br>
+ return SignExtend64<11>(read16<e>(buf) << 1);<br>
case R_MICROMIPS_PC16_S1:<br>
- return SignExtend64<17>(readShuffle<E>(Buf) << 1);<br>
+ return SignExtend64<17>(readShuffle<e>(buf) << 1);<br>
case R_MICROMIPS_PC18_S3:<br>
- return SignExtend64<21>(readShuffle<E>(Buf) << 3);<br>
+ return SignExtend64<21>(readShuffle<e>(buf) << 3);<br>
case R_MICROMIPS_PC19_S2:<br>
- return SignExtend64<21>(readShuffle<E>(Buf) << 2);<br>
+ return SignExtend64<21>(readShuffle<e>(buf) << 2);<br>
case R_MICROMIPS_PC21_S1:<br>
- return SignExtend64<22>(readShuffle<E>(Buf) << 1);<br>
+ return SignExtend64<22>(readShuffle<e>(buf) << 1);<br>
case R_MICROMIPS_PC23_S2:<br>
- return SignExtend64<25>(readShuffle<E>(Buf) << 2);<br>
+ return SignExtend64<25>(readShuffle<e>(buf) << 2);<br>
case R_MICROMIPS_PC26_S1:<br>
- return SignExtend64<27>(readShuffle<E>(Buf) << 1);<br>
+ return SignExtend64<27>(readShuffle<e>(buf) << 1);<br>
default:<br>
return 0;<br>
}<br>
}<br>
<br>
static std::pair<uint32_t, uint64_t><br>
-calculateMipsRelChain(uint8_t *Loc, RelType Type, uint64_t Val) {<br>
+calculateMipsRelChain(uint8_t *loc, RelType type, uint64_t val) {<br>
// MIPS N64 ABI packs multiple relocations into the single relocation<br>
// record. In general, all up to three relocations can have arbitrary<br>
// types. In fact, Clang and GCC uses only a few combinations. For now,<br>
@@ -449,57 +449,57 @@ calculateMipsRelChain(uint8_t *Loc, RelT<br>
// relocations used to modify result of the first one: extend it to<br>
// 64-bit, extract high or low part etc. For details, see part 2.9 Relocation<br>
// at the <a href="https://urldefense.proofpoint.com/v2/url?u=https-3A__dmz-2Dportal.mips.com_mw_images_8_82_007-2D4658-2D001.pdf&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=KBo2M0csGBb5gCRdvtStD-6yYUQcOt93n0BDlwIXJVc&e=" rel="noreferrer" target="_blank">https://urldefense.proofpoint.com/v2/url?u=https-3A__dmz-2Dportal.mips.com_mw_images_8_82_007-2D4658-2D001.pdf&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=KBo2M0csGBb5gCRdvtStD-6yYUQcOt93n0BDlwIXJVc&e=</a> <br>
- RelType Type2 = (Type >> 8) & 0xff;<br>
- RelType Type3 = (Type >> 16) & 0xff;<br>
- if (Type2 == R_MIPS_NONE && Type3 == R_MIPS_NONE)<br>
- return std::make_pair(Type, Val);<br>
- if (Type2 == R_MIPS_64 && Type3 == R_MIPS_NONE)<br>
- return std::make_pair(Type2, Val);<br>
- if (Type2 == R_MIPS_SUB && (Type3 == R_MIPS_HI16 || Type3 == R_MIPS_LO16))<br>
- return std::make_pair(Type3, -Val);<br>
- error(getErrorLocation(Loc) + "unsupported relocations combination " +<br>
- Twine(Type));<br>
- return std::make_pair(Type & 0xff, Val);<br>
-}<br>
-<br>
-static bool isBranchReloc(RelType Type) {<br>
- return Type == R_MIPS_26 || Type == R_MIPS_PC26_S2 ||<br>
- Type == R_MIPS_PC21_S2 || Type == R_MIPS_PC16;<br>
-}<br>
-<br>
-static bool isMicroBranchReloc(RelType Type) {<br>
- return Type == R_MICROMIPS_26_S1 || Type == R_MICROMIPS_PC16_S1 ||<br>
- Type == R_MICROMIPS_PC10_S1 || Type == R_MICROMIPS_PC7_S1;<br>
+ RelType type2 = (type >> 8) & 0xff;<br>
+ RelType type3 = (type >> 16) & 0xff;<br>
+ if (type2 == R_MIPS_NONE && type3 == R_MIPS_NONE)<br>
+ return std::make_pair(type, val);<br>
+ if (type2 == R_MIPS_64 && type3 == R_MIPS_NONE)<br>
+ return std::make_pair(type2, val);<br>
+ if (type2 == R_MIPS_SUB && (type3 == R_MIPS_HI16 || type3 == R_MIPS_LO16))<br>
+ return std::make_pair(type3, -val);<br>
+ error(getErrorLocation(loc) + "unsupported relocations combination " +<br>
+ Twine(type));<br>
+ return std::make_pair(type & 0xff, val);<br>
+}<br>
+<br>
+static bool isBranchReloc(RelType type) {<br>
+ return type == R_MIPS_26 || type == R_MIPS_PC26_S2 ||<br>
+ type == R_MIPS_PC21_S2 || type == R_MIPS_PC16;<br>
+}<br>
+<br>
+static bool isMicroBranchReloc(RelType type) {<br>
+ return type == R_MICROMIPS_26_S1 || type == R_MICROMIPS_PC16_S1 ||<br>
+ type == R_MICROMIPS_PC10_S1 || type == R_MICROMIPS_PC7_S1;<br>
}<br>
<br>
template <class ELFT><br>
-static uint64_t fixupCrossModeJump(uint8_t *Loc, RelType Type, uint64_t Val) {<br>
+static uint64_t fixupCrossModeJump(uint8_t *loc, RelType type, uint64_t val) {<br>
// Here we need to detect jump/branch from regular MIPS code<br>
// to a microMIPS target and vice versa. In that cases jump<br>
// instructions need to be replaced by their "cross-mode"<br>
// equivalents.<br>
- const endianness E = ELFT::TargetEndianness;<br>
- bool IsMicroTgt = Val & 0x1;<br>
- bool IsCrossJump = (IsMicroTgt && isBranchReloc(Type)) ||<br>
- (!IsMicroTgt && isMicroBranchReloc(Type));<br>
- if (!IsCrossJump)<br>
- return Val;<br>
+ const endianness e = ELFT::TargetEndianness;<br>
+ bool isMicroTgt = val & 0x1;<br>
+ bool isCrossJump = (isMicroTgt && isBranchReloc(type)) ||<br>
+ (!isMicroTgt && isMicroBranchReloc(type));<br>
+ if (!isCrossJump)<br>
+ return val;<br>
<br>
- switch (Type) {<br>
+ switch (type) {<br>
case R_MIPS_26: {<br>
- uint32_t Inst = read32<E>(Loc) >> 26;<br>
- if (Inst == 0x3 || Inst == 0x1d) { // JAL or JALX<br>
- writeValue<E>(Loc, 0x1d << 26, 32, 0);<br>
- return Val;<br>
+ uint32_t inst = read32<e>(loc) >> 26;<br>
+ if (inst == 0x3 || inst == 0x1d) { // JAL or JALX<br>
+ writeValue<e>(loc, 0x1d << 26, 32, 0);<br>
+ return val;<br>
}<br>
break;<br>
}<br>
case R_MICROMIPS_26_S1: {<br>
- uint32_t Inst = readShuffle<E>(Loc) >> 26;<br>
- if (Inst == 0x3d || Inst == 0x3c) { // JAL32 or JALX32<br>
- Val >>= 1;<br>
- writeShuffleValue<E>(Loc, 0x3c << 26, 32, 0);<br>
- return Val;<br>
+ uint32_t inst = readShuffle<e>(loc) >> 26;<br>
+ if (inst == 0x3d || inst == 0x3c) { // JAL32 or JALX32<br>
+ val >>= 1;<br>
+ writeShuffleValue<e>(loc, 0x3c << 26, 32, 0);<br>
+ return val;<br>
}<br>
break;<br>
}<br>
@@ -515,68 +515,68 @@ static uint64_t fixupCrossModeJump(uint8<br>
llvm_unreachable("unexpected jump/branch relocation");<br>
}<br>
<br>
- error(getErrorLocation(Loc) +<br>
+ error(getErrorLocation(loc) +<br>
"unsupported jump/branch instruction between ISA modes referenced by " +<br>
- toString(Type) + " relocation");<br>
- return Val;<br>
+ toString(type) + " relocation");<br>
+ return val;<br>
}<br>
<br>
template <class ELFT><br>
-void MIPS<ELFT>::relocateOne(uint8_t *Loc, RelType Type, uint64_t Val) const {<br>
- const endianness E = ELFT::TargetEndianness;<br>
+void MIPS<ELFT>::relocateOne(uint8_t *loc, RelType type, uint64_t val) const {<br>
+ const endianness e = ELFT::TargetEndianness;<br>
<br>
- if (ELFT::Is64Bits || Config->MipsN32Abi)<br>
- std::tie(Type, Val) = calculateMipsRelChain(Loc, Type, Val);<br>
+ if (ELFT::Is64Bits || config->mipsN32Abi)<br>
+ std::tie(type, val) = calculateMipsRelChain(loc, type, val);<br>
<br>
// Detect cross-mode jump/branch and fix instruction.<br>
- Val = fixupCrossModeJump<ELFT>(Loc, Type, Val);<br>
+ val = fixupCrossModeJump<ELFT>(loc, type, val);<br>
<br>
// Thread pointer and DRP offsets from the start of TLS data area.<br>
// <a href="https://urldefense.proofpoint.com/v2/url?u=https-3A__www.linux-2Dmips.org_wiki_NPTL&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=RakKH8VixPi8JXre-dl0635Qb4o3oNmeHdGuOUvYAvQ&e=" rel="noreferrer" target="_blank">https://urldefense.proofpoint.com/v2/url?u=https-3A__www.linux-2Dmips.org_wiki_NPTL&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=RakKH8VixPi8JXre-dl0635Qb4o3oNmeHdGuOUvYAvQ&e=</a> <br>
- if (Type == R_MIPS_TLS_DTPREL_HI16 || Type == R_MIPS_TLS_DTPREL_LO16 ||<br>
- Type == R_MIPS_TLS_DTPREL32 || Type == R_MIPS_TLS_DTPREL64 ||<br>
- Type == R_MICROMIPS_TLS_DTPREL_HI16 ||<br>
- Type == R_MICROMIPS_TLS_DTPREL_LO16) {<br>
- Val -= 0x8000;<br>
- } else if (Type == R_MIPS_TLS_TPREL_HI16 || Type == R_MIPS_TLS_TPREL_LO16 ||<br>
- Type == R_MIPS_TLS_TPREL32 || Type == R_MIPS_TLS_TPREL64 ||<br>
- Type == R_MICROMIPS_TLS_TPREL_HI16 ||<br>
- Type == R_MICROMIPS_TLS_TPREL_LO16) {<br>
- Val -= 0x7000;<br>
+ if (type == R_MIPS_TLS_DTPREL_HI16 || type == R_MIPS_TLS_DTPREL_LO16 ||<br>
+ type == R_MIPS_TLS_DTPREL32 || type == R_MIPS_TLS_DTPREL64 ||<br>
+ type == R_MICROMIPS_TLS_DTPREL_HI16 ||<br>
+ type == R_MICROMIPS_TLS_DTPREL_LO16) {<br>
+ val -= 0x8000;<br>
+ } else if (type == R_MIPS_TLS_TPREL_HI16 || type == R_MIPS_TLS_TPREL_LO16 ||<br>
+ type == R_MIPS_TLS_TPREL32 || type == R_MIPS_TLS_TPREL64 ||<br>
+ type == R_MICROMIPS_TLS_TPREL_HI16 ||<br>
+ type == R_MICROMIPS_TLS_TPREL_LO16) {<br>
+ val -= 0x7000;<br>
}<br>
<br>
- switch (Type) {<br>
+ switch (type) {<br>
case R_MIPS_32:<br>
case R_MIPS_GPREL32:<br>
case R_MIPS_TLS_DTPREL32:<br>
case R_MIPS_TLS_TPREL32:<br>
- write32<E>(Loc, Val);<br>
+ write32<e>(loc, val);<br>
break;<br>
case R_MIPS_64:<br>
case R_MIPS_TLS_DTPREL64:<br>
case R_MIPS_TLS_TPREL64:<br>
- write64<E>(Loc, Val);<br>
+ write64<e>(loc, val);<br>
break;<br>
case R_MIPS_26:<br>
- writeValue<E>(Loc, Val, 26, 2);<br>
+ writeValue<e>(loc, val, 26, 2);<br>
break;<br>
case R_MIPS_GOT16:<br>
// The R_MIPS_GOT16 relocation's value in "relocatable" linking mode<br>
// is updated addend (not a GOT index). In that case write high 16 bits<br>
// to store a correct addend value.<br>
- if (Config->Relocatable) {<br>
- writeValue<E>(Loc, Val + 0x8000, 16, 16);<br>
+ if (config->relocatable) {<br>
+ writeValue<e>(loc, val + 0x8000, 16, 16);<br>
} else {<br>
- checkInt(Loc, Val, 16, Type);<br>
- writeValue<E>(Loc, Val, 16, 0);<br>
+ checkInt(loc, val, 16, type);<br>
+ writeValue<e>(loc, val, 16, 0);<br>
}<br>
break;<br>
case R_MICROMIPS_GOT16:<br>
- if (Config->Relocatable) {<br>
- writeShuffleValue<E>(Loc, Val + 0x8000, 16, 16);<br>
+ if (config->relocatable) {<br>
+ writeShuffleValue<e>(loc, val + 0x8000, 16, 16);<br>
} else {<br>
- checkInt(Loc, Val, 16, Type);<br>
- writeShuffleValue<E>(Loc, Val, 16, 0);<br>
+ checkInt(loc, val, 16, type);<br>
+ writeShuffleValue<e>(loc, val, 16, 0);<br>
}<br>
break;<br>
case R_MIPS_CALL16:<br>
@@ -586,7 +586,7 @@ void MIPS<ELFT>::relocateOne(uint8_t *Lo<br>
case R_MIPS_TLS_GD:<br>
case R_MIPS_TLS_GOTTPREL:<br>
case R_MIPS_TLS_LDM:<br>
- checkInt(Loc, Val, 16, Type);<br>
+ checkInt(loc, val, 16, type);<br>
LLVM_FALLTHROUGH;<br>
case R_MIPS_CALL_LO16:<br>
case R_MIPS_GOT_LO16:<br>
@@ -595,13 +595,13 @@ void MIPS<ELFT>::relocateOne(uint8_t *Lo<br>
case R_MIPS_PCLO16:<br>
case R_MIPS_TLS_DTPREL_LO16:<br>
case R_MIPS_TLS_TPREL_LO16:<br>
- writeValue<E>(Loc, Val, 16, 0);<br>
+ writeValue<e>(loc, val, 16, 0);<br>
break;<br>
case R_MICROMIPS_GPREL16:<br>
case R_MICROMIPS_TLS_GD:<br>
case R_MICROMIPS_TLS_LDM:<br>
- checkInt(Loc, Val, 16, Type);<br>
- writeShuffleValue<E>(Loc, Val, 16, 0);<br>
+ checkInt(loc, val, 16, type);<br>
+ writeShuffleValue<e>(loc, val, 16, 0);<br>
break;<br>
case R_MICROMIPS_CALL16:<br>
case R_MICROMIPS_CALL_LO16:<br>
@@ -609,11 +609,11 @@ void MIPS<ELFT>::relocateOne(uint8_t *Lo<br>
case R_MICROMIPS_TLS_DTPREL_LO16:<br>
case R_MICROMIPS_TLS_GOTTPREL:<br>
case R_MICROMIPS_TLS_TPREL_LO16:<br>
- writeShuffleValue<E>(Loc, Val, 16, 0);<br>
+ writeShuffleValue<e>(loc, val, 16, 0);<br>
break;<br>
case R_MICROMIPS_GPREL7_S2:<br>
- checkInt(Loc, Val, 7, Type);<br>
- writeShuffleValue<E>(Loc, Val, 7, 2);<br>
+ checkInt(loc, val, 7, type);<br>
+ writeShuffleValue<e>(loc, val, 7, 2);<br>
break;<br>
case R_MIPS_CALL_HI16:<br>
case R_MIPS_GOT_HI16:<br>
@@ -621,113 +621,113 @@ void MIPS<ELFT>::relocateOne(uint8_t *Lo<br>
case R_MIPS_PCHI16:<br>
case R_MIPS_TLS_DTPREL_HI16:<br>
case R_MIPS_TLS_TPREL_HI16:<br>
- writeValue<E>(Loc, Val + 0x8000, 16, 16);<br>
+ writeValue<e>(loc, val + 0x8000, 16, 16);<br>
break;<br>
case R_MICROMIPS_CALL_HI16:<br>
case R_MICROMIPS_GOT_HI16:<br>
case R_MICROMIPS_HI16:<br>
case R_MICROMIPS_TLS_DTPREL_HI16:<br>
case R_MICROMIPS_TLS_TPREL_HI16:<br>
- writeShuffleValue<E>(Loc, Val + 0x8000, 16, 16);<br>
+ writeShuffleValue<e>(loc, val + 0x8000, 16, 16);<br>
break;<br>
case R_MIPS_HIGHER:<br>
- writeValue<E>(Loc, Val + 0x80008000, 16, 32);<br>
+ writeValue<e>(loc, val + 0x80008000, 16, 32);<br>
break;<br>
case R_MIPS_HIGHEST:<br>
- writeValue<E>(Loc, Val + 0x800080008000, 16, 48);<br>
+ writeValue<e>(loc, val + 0x800080008000, 16, 48);<br>
break;<br>
case R_MIPS_JALR:<br>
case R_MICROMIPS_JALR:<br>
// Ignore this optimization relocation for now<br>
break;<br>
case R_MIPS_PC16:<br>
- checkAlignment(Loc, Val, 4, Type);<br>
- checkInt(Loc, Val, 18, Type);<br>
- writeValue<E>(Loc, Val, 16, 2);<br>
+ checkAlignment(loc, val, 4, type);<br>
+ checkInt(loc, val, 18, type);<br>
+ writeValue<e>(loc, val, 16, 2);<br>
break;<br>
case R_MIPS_PC19_S2:<br>
- checkAlignment(Loc, Val, 4, Type);<br>
- checkInt(Loc, Val, 21, Type);<br>
- writeValue<E>(Loc, Val, 19, 2);<br>
+ checkAlignment(loc, val, 4, type);<br>
+ checkInt(loc, val, 21, type);<br>
+ writeValue<e>(loc, val, 19, 2);<br>
break;<br>
case R_MIPS_PC21_S2:<br>
- checkAlignment(Loc, Val, 4, Type);<br>
- checkInt(Loc, Val, 23, Type);<br>
- writeValue<E>(Loc, Val, 21, 2);<br>
+ checkAlignment(loc, val, 4, type);<br>
+ checkInt(loc, val, 23, type);<br>
+ writeValue<e>(loc, val, 21, 2);<br>
break;<br>
case R_MIPS_PC26_S2:<br>
- checkAlignment(Loc, Val, 4, Type);<br>
- checkInt(Loc, Val, 28, Type);<br>
- writeValue<E>(Loc, Val, 26, 2);<br>
+ checkAlignment(loc, val, 4, type);<br>
+ checkInt(loc, val, 28, type);<br>
+ writeValue<e>(loc, val, 26, 2);<br>
break;<br>
case R_MIPS_PC32:<br>
- writeValue<E>(Loc, Val, 32, 0);<br>
+ writeValue<e>(loc, val, 32, 0);<br>
break;<br>
case R_MICROMIPS_26_S1:<br>
case R_MICROMIPS_PC26_S1:<br>
- checkInt(Loc, Val, 27, Type);<br>
- writeShuffleValue<E>(Loc, Val, 26, 1);<br>
+ checkInt(loc, val, 27, type);<br>
+ writeShuffleValue<e>(loc, val, 26, 1);<br>
break;<br>
case R_MICROMIPS_PC7_S1:<br>
- checkInt(Loc, Val, 8, Type);<br>
- writeMicroRelocation16<E>(Loc, Val, 7, 1);<br>
+ checkInt(loc, val, 8, type);<br>
+ writeMicroRelocation16<e>(loc, val, 7, 1);<br>
break;<br>
case R_MICROMIPS_PC10_S1:<br>
- checkInt(Loc, Val, 11, Type);<br>
- writeMicroRelocation16<E>(Loc, Val, 10, 1);<br>
+ checkInt(loc, val, 11, type);<br>
+ writeMicroRelocation16<e>(loc, val, 10, 1);<br>
break;<br>
case R_MICROMIPS_PC16_S1:<br>
- checkInt(Loc, Val, 17, Type);<br>
- writeShuffleValue<E>(Loc, Val, 16, 1);<br>
+ checkInt(loc, val, 17, type);<br>
+ writeShuffleValue<e>(loc, val, 16, 1);<br>
break;<br>
case R_MICROMIPS_PC18_S3:<br>
- checkInt(Loc, Val, 21, Type);<br>
- writeShuffleValue<E>(Loc, Val, 18, 3);<br>
+ checkInt(loc, val, 21, type);<br>
+ writeShuffleValue<e>(loc, val, 18, 3);<br>
break;<br>
case R_MICROMIPS_PC19_S2:<br>
- checkInt(Loc, Val, 21, Type);<br>
- writeShuffleValue<E>(Loc, Val, 19, 2);<br>
+ checkInt(loc, val, 21, type);<br>
+ writeShuffleValue<e>(loc, val, 19, 2);<br>
break;<br>
case R_MICROMIPS_PC21_S1:<br>
- checkInt(Loc, Val, 22, Type);<br>
- writeShuffleValue<E>(Loc, Val, 21, 1);<br>
+ checkInt(loc, val, 22, type);<br>
+ writeShuffleValue<e>(loc, val, 21, 1);<br>
break;<br>
case R_MICROMIPS_PC23_S2:<br>
- checkInt(Loc, Val, 25, Type);<br>
- writeShuffleValue<E>(Loc, Val, 23, 2);<br>
+ checkInt(loc, val, 25, type);<br>
+ writeShuffleValue<e>(loc, val, 23, 2);<br>
break;<br>
default:<br>
llvm_unreachable("unknown relocation");<br>
}<br>
}<br>
<br>
-template <class ELFT> bool MIPS<ELFT>::usesOnlyLowPageBits(RelType Type) const {<br>
- return Type == R_MIPS_LO16 || Type == R_MIPS_GOT_OFST ||<br>
- Type == R_MICROMIPS_LO16;<br>
+template <class ELFT> bool MIPS<ELFT>::usesOnlyLowPageBits(RelType type) const {<br>
+ return type == R_MIPS_LO16 || type == R_MIPS_GOT_OFST ||<br>
+ type == R_MICROMIPS_LO16;<br>
}<br>
<br>
// Return true if the symbol is a PIC function.<br>
-template <class ELFT> bool elf::isMipsPIC(const Defined *Sym) {<br>
- if (!Sym->isFunc())<br>
+template <class ELFT> bool elf::isMipsPIC(const Defined *sym) {<br>
+ if (!sym->isFunc())<br>
return false;<br>
<br>
- if (Sym->StOther & STO_MIPS_PIC)<br>
+ if (sym->stOther & STO_MIPS_PIC)<br>
return true;<br>
<br>
- if (!Sym->Section)<br>
+ if (!sym->section)<br>
return false;<br>
<br>
- ObjFile<ELFT> *File =<br>
- cast<InputSectionBase>(Sym->Section)->template getFile<ELFT>();<br>
- if (!File)<br>
+ ObjFile<ELFT> *file =<br>
+ cast<InputSectionBase>(sym->section)->template getFile<ELFT>();<br>
+ if (!file)<br>
return false;<br>
<br>
- return File->getObj().getHeader()->e_flags & EF_MIPS_PIC;<br>
+ return file->getObj().getHeader()->e_flags & EF_MIPS_PIC;<br>
}<br>
<br>
template <class ELFT> TargetInfo *elf::getMipsTargetInfo() {<br>
- static MIPS<ELFT> Target;<br>
- return &Target;<br>
+ static MIPS<ELFT> target;<br>
+ return ⌖<br>
}<br>
<br>
template TargetInfo *elf::getMipsTargetInfo<ELF32LE>();<br>
<br>
Modified: lld/trunk/ELF/Arch/MipsArchTree.cpp<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_ELF_Arch_MipsArchTree.cpp-3Frev-3D365595-26r1-3D365594-26r2-3D365595-26view-3Ddiff&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=Tl66Mtod-vaCxh1JMVaVHA93eIAgiquVNODVRRzeyzY&e=" rel="noreferrer" target="_blank">https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_ELF_Arch_MipsArchTree.cpp-3Frev-3D365595-26r1-3D365594-26r2-3D365595-26view-3Ddiff&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=Tl66Mtod-vaCxh1JMVaVHA93eIAgiquVNODVRRzeyzY&e=</a> <br>
==============================================================================<br>
--- lld/trunk/ELF/Arch/MipsArchTree.cpp (original)<br>
+++ lld/trunk/ELF/Arch/MipsArchTree.cpp Tue Jul 9 22:00:37 2019<br>
@@ -28,18 +28,18 @@ using namespace lld::elf;<br>
<br>
namespace {<br>
struct ArchTreeEdge {<br>
- uint32_t Child;<br>
- uint32_t Parent;<br>
+ uint32_t child;<br>
+ uint32_t parent;<br>
};<br>
<br>
struct FileFlags {<br>
- InputFile *File;<br>
- uint32_t Flags;<br>
+ InputFile *file;<br>
+ uint32_t flags;<br>
};<br>
} // namespace<br>
<br>
-static StringRef getAbiName(uint32_t Flags) {<br>
- switch (Flags) {<br>
+static StringRef getAbiName(uint32_t flags) {<br>
+ switch (flags) {<br>
case 0:<br>
return "n64";<br>
case EF_MIPS_ABI2:<br>
@@ -57,76 +57,76 @@ static StringRef getAbiName(uint32_t Fla<br>
}<br>
}<br>
<br>
-static StringRef getNanName(bool IsNan2008) {<br>
- return IsNan2008 ? "2008" : "legacy";<br>
+static StringRef getNanName(bool isNan2008) {<br>
+ return isNan2008 ? "2008" : "legacy";<br>
}<br>
<br>
-static StringRef getFpName(bool IsFp64) { return IsFp64 ? "64" : "32"; }<br>
+static StringRef getFpName(bool isFp64) { return isFp64 ? "64" : "32"; }<br>
<br>
-static void checkFlags(ArrayRef<FileFlags> Files) {<br>
- assert(!Files.empty() && "expected non-empty file list");<br>
+static void checkFlags(ArrayRef<FileFlags> files) {<br>
+ assert(!files.empty() && "expected non-empty file list");<br>
<br>
- uint32_t ABI = Files[0].Flags & (EF_MIPS_ABI | EF_MIPS_ABI2);<br>
- bool Nan = Files[0].Flags & EF_MIPS_NAN2008;<br>
- bool Fp = Files[0].Flags & EF_MIPS_FP64;<br>
+ uint32_t abi = files[0].flags & (EF_MIPS_ABI | EF_MIPS_ABI2);<br>
+ bool nan = files[0].flags & EF_MIPS_NAN2008;<br>
+ bool fp = files[0].flags & EF_MIPS_FP64;<br>
<br>
- for (const FileFlags &F : Files) {<br>
- if (Config->Is64 && F.Flags & EF_MIPS_MICROMIPS)<br>
- error(toString(F.File) + ": microMIPS 64-bit is not supported");<br>
+ for (const FileFlags &f : files) {<br>
+ if (config->is64 && f.flags & EF_MIPS_MICROMIPS)<br>
+ error(toString(f.file) + ": microMIPS 64-bit is not supported");<br>
<br>
- uint32_t ABI2 = F.Flags & (EF_MIPS_ABI | EF_MIPS_ABI2);<br>
- if (ABI != ABI2)<br>
- error(toString(F.File) + ": ABI '" + getAbiName(ABI2) +<br>
- "' is incompatible with target ABI '" + getAbiName(ABI) + "'");<br>
+ uint32_t abi2 = f.flags & (EF_MIPS_ABI | EF_MIPS_ABI2);<br>
+ if (abi != abi2)<br>
+ error(toString(f.file) + ": ABI '" + getAbiName(abi2) +<br>
+ "' is incompatible with target ABI '" + getAbiName(abi) + "'");<br>
<br>
- bool Nan2 = F.Flags & EF_MIPS_NAN2008;<br>
- if (Nan != Nan2)<br>
- error(toString(F.File) + ": -mnan=" + getNanName(Nan2) +<br>
- " is incompatible with target -mnan=" + getNanName(Nan));<br>
+ bool nan2 = f.flags & EF_MIPS_NAN2008;<br>
+ if (nan != nan2)<br>
+ error(toString(f.file) + ": -mnan=" + getNanName(nan2) +<br>
+ " is incompatible with target -mnan=" + getNanName(nan));<br>
<br>
- bool Fp2 = F.Flags & EF_MIPS_FP64;<br>
- if (Fp != Fp2)<br>
- error(toString(F.File) + ": -mfp" + getFpName(Fp2) +<br>
- " is incompatible with target -mfp" + getFpName(Fp));<br>
+ bool fp2 = f.flags & EF_MIPS_FP64;<br>
+ if (fp != fp2)<br>
+ error(toString(f.file) + ": -mfp" + getFpName(fp2) +<br>
+ " is incompatible with target -mfp" + getFpName(fp));<br>
}<br>
}<br>
<br>
-static uint32_t getMiscFlags(ArrayRef<FileFlags> Files) {<br>
- uint32_t Ret = 0;<br>
- for (const FileFlags &F : Files)<br>
- Ret |= F.Flags &<br>
+static uint32_t getMiscFlags(ArrayRef<FileFlags> files) {<br>
+ uint32_t ret = 0;<br>
+ for (const FileFlags &f : files)<br>
+ ret |= f.flags &<br>
(EF_MIPS_ABI | EF_MIPS_ABI2 | EF_MIPS_ARCH_ASE | EF_MIPS_NOREORDER |<br>
EF_MIPS_MICROMIPS | EF_MIPS_NAN2008 | EF_MIPS_32BITMODE);<br>
- return Ret;<br>
+ return ret;<br>
}<br>
<br>
-static uint32_t getPicFlags(ArrayRef<FileFlags> Files) {<br>
+static uint32_t getPicFlags(ArrayRef<FileFlags> files) {<br>
// Check PIC/non-PIC compatibility.<br>
- bool IsPic = Files[0].Flags & (EF_MIPS_PIC | EF_MIPS_CPIC);<br>
- for (const FileFlags &F : Files.slice(1)) {<br>
- bool IsPic2 = F.Flags & (EF_MIPS_PIC | EF_MIPS_CPIC);<br>
- if (IsPic && !IsPic2)<br>
- warn(toString(F.File) +<br>
+ bool isPic = files[0].flags & (EF_MIPS_PIC | EF_MIPS_CPIC);<br>
+ for (const FileFlags &f : files.slice(1)) {<br>
+ bool isPic2 = f.flags & (EF_MIPS_PIC | EF_MIPS_CPIC);<br>
+ if (isPic && !isPic2)<br>
+ warn(toString(f.file) +<br>
": linking non-abicalls code with abicalls code " +<br>
- toString(Files[0].File));<br>
- if (!IsPic && IsPic2)<br>
- warn(toString(F.File) +<br>
+ toString(files[0].file));<br>
+ if (!isPic && isPic2)<br>
+ warn(toString(f.file) +<br>
": linking abicalls code with non-abicalls code " +<br>
- toString(Files[0].File));<br>
+ toString(files[0].file));<br>
}<br>
<br>
// Compute the result PIC/non-PIC flag.<br>
- uint32_t Ret = Files[0].Flags & (EF_MIPS_PIC | EF_MIPS_CPIC);<br>
- for (const FileFlags &F : Files.slice(1))<br>
- Ret &= F.Flags & (EF_MIPS_PIC | EF_MIPS_CPIC);<br>
+ uint32_t ret = files[0].flags & (EF_MIPS_PIC | EF_MIPS_CPIC);<br>
+ for (const FileFlags &f : files.slice(1))<br>
+ ret &= f.flags & (EF_MIPS_PIC | EF_MIPS_CPIC);<br>
<br>
// PIC code is inherently CPIC and may not set CPIC flag explicitly.<br>
- if (Ret & EF_MIPS_PIC)<br>
- Ret |= EF_MIPS_CPIC;<br>
- return Ret;<br>
+ if (ret & EF_MIPS_PIC)<br>
+ ret |= EF_MIPS_CPIC;<br>
+ return ret;<br>
}<br>
<br>
-static ArchTreeEdge ArchTree[] = {<br>
+static ArchTreeEdge archTree[] = {<br>
// MIPS32R6 and MIPS64R6 are not compatible with other extensions<br>
// MIPS64R2 extensions.<br>
{EF_MIPS_ARCH_64R2 | EF_MIPS_MACH_OCTEON3, EF_MIPS_ARCH_64R2},<br>
@@ -166,25 +166,25 @@ static ArchTreeEdge ArchTree[] = {<br>
{EF_MIPS_ARCH_2, EF_MIPS_ARCH_1},<br>
};<br>
<br>
-static bool isArchMatched(uint32_t New, uint32_t Res) {<br>
- if (New == Res)<br>
+static bool isArchMatched(uint32_t New, uint32_t res) {<br>
+ if (New == res)<br>
return true;<br>
- if (New == EF_MIPS_ARCH_32 && isArchMatched(EF_MIPS_ARCH_64, Res))<br>
+ if (New == EF_MIPS_ARCH_32 && isArchMatched(EF_MIPS_ARCH_64, res))<br>
return true;<br>
- if (New == EF_MIPS_ARCH_32R2 && isArchMatched(EF_MIPS_ARCH_64R2, Res))<br>
+ if (New == EF_MIPS_ARCH_32R2 && isArchMatched(EF_MIPS_ARCH_64R2, res))<br>
return true;<br>
- for (const auto &Edge : ArchTree) {<br>
- if (Res == Edge.Child) {<br>
- Res = Edge.Parent;<br>
- if (Res == New)<br>
+ for (const auto &edge : archTree) {<br>
+ if (res == edge.child) {<br>
+ res = edge.parent;<br>
+ if (res == New)<br>
return true;<br>
}<br>
}<br>
return false;<br>
}<br>
<br>
-static StringRef getMachName(uint32_t Flags) {<br>
- switch (Flags & EF_MIPS_MACH) {<br>
+static StringRef getMachName(uint32_t flags) {<br>
+ switch (flags & EF_MIPS_MACH) {<br>
case EF_MIPS_MACH_NONE:<br>
return "";<br>
case EF_MIPS_MACH_3900:<br>
@@ -228,8 +228,8 @@ static StringRef getMachName(uint32_t Fl<br>
}<br>
}<br>
<br>
-static StringRef getArchName(uint32_t Flags) {<br>
- switch (Flags & EF_MIPS_ARCH) {<br>
+static StringRef getArchName(uint32_t flags) {<br>
+ switch (flags & EF_MIPS_ARCH) {<br>
case EF_MIPS_ARCH_1:<br>
return "mips1";<br>
case EF_MIPS_ARCH_2:<br>
@@ -257,12 +257,12 @@ static StringRef getArchName(uint32_t Fl<br>
}<br>
}<br>
<br>
-static std::string getFullArchName(uint32_t Flags) {<br>
- StringRef Arch = getArchName(Flags);<br>
- StringRef Mach = getMachName(Flags);<br>
- if (Mach.empty())<br>
- return Arch.str();<br>
- return (Arch + " (" + Mach + ")").str();<br>
+static std::string getFullArchName(uint32_t flags) {<br>
+ StringRef arch = getArchName(flags);<br>
+ StringRef mach = getMachName(flags);<br>
+ if (mach.empty())<br>
+ return arch.str();<br>
+ return (arch + " (" + mach + ")").str();<br>
}<br>
<br>
// There are (arguably too) many MIPS ISAs out there. Their relationships<br>
@@ -274,55 +274,55 @@ static std::string getFullArchName(uint3<br>
// Output file gets EF_MIPS_ARCH_2 flag. From the other side mips3 and mips32<br>
// are incompatible because nor mips3 is a parent for misp32, nor mips32<br>
// is a parent for mips3.<br>
-static uint32_t getArchFlags(ArrayRef<FileFlags> Files) {<br>
- uint32_t Ret = Files[0].Flags & (EF_MIPS_ARCH | EF_MIPS_MACH);<br>
+static uint32_t getArchFlags(ArrayRef<FileFlags> files) {<br>
+ uint32_t ret = files[0].flags & (EF_MIPS_ARCH | EF_MIPS_MACH);<br>
<br>
- for (const FileFlags &F : Files.slice(1)) {<br>
- uint32_t New = F.Flags & (EF_MIPS_ARCH | EF_MIPS_MACH);<br>
+ for (const FileFlags &f : files.slice(1)) {<br>
+ uint32_t New = f.flags & (EF_MIPS_ARCH | EF_MIPS_MACH);<br>
<br>
// Check ISA compatibility.<br>
- if (isArchMatched(New, Ret))<br>
+ if (isArchMatched(New, ret))<br>
continue;<br>
- if (!isArchMatched(Ret, New)) {<br>
- error("incompatible target ISA:\n>>> " + toString(Files[0].File) + ": " +<br>
- getFullArchName(Ret) + "\n>>> " + toString(F.File) + ": " +<br>
+ if (!isArchMatched(ret, New)) {<br>
+ error("incompatible target ISA:\n>>> " + toString(files[0].file) + ": " +<br>
+ getFullArchName(ret) + "\n>>> " + toString(f.file) + ": " +<br>
getFullArchName(New));<br>
return 0;<br>
}<br>
- Ret = New;<br>
+ ret = New;<br>
}<br>
- return Ret;<br>
+ return ret;<br>
}<br>
<br>
template <class ELFT> uint32_t elf::calcMipsEFlags() {<br>
- std::vector<FileFlags> V;<br>
- for (InputFile *F : ObjectFiles)<br>
- V.push_back({F, cast<ObjFile<ELFT>>(F)->getObj().getHeader()->e_flags});<br>
- if (V.empty())<br>
+ std::vector<FileFlags> v;<br>
+ for (InputFile *f : objectFiles)<br>
+ v.push_back({f, cast<ObjFile<ELFT>>(f)->getObj().getHeader()->e_flags});<br>
+ if (v.empty())<br>
return 0;<br>
- checkFlags(V);<br>
- return getMiscFlags(V) | getPicFlags(V) | getArchFlags(V);<br>
+ checkFlags(v);<br>
+ return getMiscFlags(v) | getPicFlags(v) | getArchFlags(v);<br>
}<br>
<br>
-static int compareMipsFpAbi(uint8_t FpA, uint8_t FpB) {<br>
- if (FpA == FpB)<br>
+static int compareMipsFpAbi(uint8_t fpA, uint8_t fpB) {<br>
+ if (fpA == fpB)<br>
return 0;<br>
- if (FpB == Mips::Val_GNU_MIPS_ABI_FP_ANY)<br>
+ if (fpB == Mips::Val_GNU_MIPS_ABI_FP_ANY)<br>
return 1;<br>
- if (FpB == Mips::Val_GNU_MIPS_ABI_FP_64A &&<br>
- FpA == Mips::Val_GNU_MIPS_ABI_FP_64)<br>
+ if (fpB == Mips::Val_GNU_MIPS_ABI_FP_64A &&<br>
+ fpA == Mips::Val_GNU_MIPS_ABI_FP_64)<br>
return 1;<br>
- if (FpB != Mips::Val_GNU_MIPS_ABI_FP_XX)<br>
+ if (fpB != Mips::Val_GNU_MIPS_ABI_FP_XX)<br>
return -1;<br>
- if (FpA == Mips::Val_GNU_MIPS_ABI_FP_DOUBLE ||<br>
- FpA == Mips::Val_GNU_MIPS_ABI_FP_64 ||<br>
- FpA == Mips::Val_GNU_MIPS_ABI_FP_64A)<br>
+ if (fpA == Mips::Val_GNU_MIPS_ABI_FP_DOUBLE ||<br>
+ fpA == Mips::Val_GNU_MIPS_ABI_FP_64 ||<br>
+ fpA == Mips::Val_GNU_MIPS_ABI_FP_64A)<br>
return 1;<br>
return -1;<br>
}<br>
<br>
-static StringRef getMipsFpAbiName(uint8_t FpAbi) {<br>
- switch (FpAbi) {<br>
+static StringRef getMipsFpAbiName(uint8_t fpAbi) {<br>
+ switch (fpAbi) {<br>
case Mips::Val_GNU_MIPS_ABI_FP_ANY:<br>
return "any";<br>
case Mips::Val_GNU_MIPS_ABI_FP_DOUBLE:<br>
@@ -344,43 +344,43 @@ static StringRef getMipsFpAbiName(uint8_<br>
}<br>
}<br>
<br>
-uint8_t elf::getMipsFpAbiFlag(uint8_t OldFlag, uint8_t NewFlag,<br>
- StringRef FileName) {<br>
- if (compareMipsFpAbi(NewFlag, OldFlag) >= 0)<br>
- return NewFlag;<br>
- if (compareMipsFpAbi(OldFlag, NewFlag) < 0)<br>
- error(FileName + ": floating point ABI '" + getMipsFpAbiName(NewFlag) +<br>
+uint8_t elf::getMipsFpAbiFlag(uint8_t oldFlag, uint8_t newFlag,<br>
+ StringRef fileName) {<br>
+ if (compareMipsFpAbi(newFlag, oldFlag) >= 0)<br>
+ return newFlag;<br>
+ if (compareMipsFpAbi(oldFlag, newFlag) < 0)<br>
+ error(fileName + ": floating point ABI '" + getMipsFpAbiName(newFlag) +<br>
"' is incompatible with target floating point ABI '" +<br>
- getMipsFpAbiName(OldFlag) + "'");<br>
- return OldFlag;<br>
+ getMipsFpAbiName(oldFlag) + "'");<br>
+ return oldFlag;<br>
}<br>
<br>
-template <class ELFT> static bool isN32Abi(const InputFile *F) {<br>
- if (auto *EF = dyn_cast<ELFFileBase>(F))<br>
- return EF->template getObj<ELFT>().getHeader()->e_flags & EF_MIPS_ABI2;<br>
+template <class ELFT> static bool isN32Abi(const InputFile *f) {<br>
+ if (auto *ef = dyn_cast<ELFFileBase>(f))<br>
+ return ef->template getObj<ELFT>().getHeader()->e_flags & EF_MIPS_ABI2;<br>
return false;<br>
}<br>
<br>
-bool elf::isMipsN32Abi(const InputFile *F) {<br>
- switch (Config->EKind) {<br>
+bool elf::isMipsN32Abi(const InputFile *f) {<br>
+ switch (config->ekind) {<br>
case ELF32LEKind:<br>
- return isN32Abi<ELF32LE>(F);<br>
+ return isN32Abi<ELF32LE>(f);<br>
case ELF32BEKind:<br>
- return isN32Abi<ELF32BE>(F);<br>
+ return isN32Abi<ELF32BE>(f);<br>
case ELF64LEKind:<br>
- return isN32Abi<ELF64LE>(F);<br>
+ return isN32Abi<ELF64LE>(f);<br>
case ELF64BEKind:<br>
- return isN32Abi<ELF64BE>(F);<br>
+ return isN32Abi<ELF64BE>(f);<br>
default:<br>
llvm_unreachable("unknown Config->EKind");<br>
}<br>
}<br>
<br>
-bool elf::isMicroMips() { return Config->EFlags & EF_MIPS_MICROMIPS; }<br>
+bool elf::isMicroMips() { return config->eflags & EF_MIPS_MICROMIPS; }<br>
<br>
bool elf::isMipsR6() {<br>
- uint32_t Arch = Config->EFlags & EF_MIPS_ARCH;<br>
- return Arch == EF_MIPS_ARCH_32R6 || Arch == EF_MIPS_ARCH_64R6;<br>
+ uint32_t arch = config->eflags & EF_MIPS_ARCH;<br>
+ return arch == EF_MIPS_ARCH_32R6 || arch == EF_MIPS_ARCH_64R6;<br>
}<br>
<br>
template uint32_t elf::calcMipsEFlags<ELF32LE>();<br>
<br>
Modified: lld/trunk/ELF/Arch/PPC.cpp<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_ELF_Arch_PPC.cpp-3Frev-3D365595-26r1-3D365594-26r2-3D365595-26view-3Ddiff&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=IWqzOe31N6VoM_s4Ylt8_bMBd6TmS7RY8fsmuAHgFd4&e=" rel="noreferrer" target="_blank">https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_ELF_Arch_PPC.cpp-3Frev-3D365595-26r1-3D365594-26r2-3D365595-26view-3Ddiff&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=IWqzOe31N6VoM_s4Ylt8_bMBd6TmS7RY8fsmuAHgFd4&e=</a> <br>
==============================================================================<br>
--- lld/trunk/ELF/Arch/PPC.cpp (original)<br>
+++ lld/trunk/ELF/Arch/PPC.cpp Tue Jul 9 22:00:37 2019<br>
@@ -23,45 +23,45 @@ namespace {<br>
class PPC final : public TargetInfo {<br>
public:<br>
PPC();<br>
- RelExpr getRelExpr(RelType Type, const Symbol &S,<br>
- const uint8_t *Loc) const override;<br>
- RelType getDynRel(RelType Type) const override;<br>
- void writeGotHeader(uint8_t *Buf) const override;<br>
- void writePltHeader(uint8_t *Buf) const override {<br>
+ RelExpr getRelExpr(RelType type, const Symbol &s,<br>
+ const uint8_t *loc) const override;<br>
+ RelType getDynRel(RelType type) const override;<br>
+ void writeGotHeader(uint8_t *buf) const override;<br>
+ void writePltHeader(uint8_t *buf) const override {<br>
llvm_unreachable("should call writePPC32GlinkSection() instead");<br>
}<br>
- void writePlt(uint8_t *Buf, uint64_t GotPltEntryAddr, uint64_t PltEntryAddr,<br>
- int32_t Index, unsigned RelOff) const override {<br>
+ void writePlt(uint8_t *buf, uint64_t gotPltEntryAddr, uint64_t pltEntryAddr,<br>
+ int32_t index, unsigned relOff) const override {<br>
llvm_unreachable("should call writePPC32GlinkSection() instead");<br>
}<br>
- void writeGotPlt(uint8_t *Buf, const Symbol &S) const override;<br>
- bool needsThunk(RelExpr Expr, RelType RelocType, const InputFile *File,<br>
- uint64_t BranchAddr, const Symbol &S) const override;<br>
+ void writeGotPlt(uint8_t *buf, const Symbol &s) const override;<br>
+ bool needsThunk(RelExpr expr, RelType relocType, const InputFile *file,<br>
+ uint64_t branchAddr, const Symbol &s) const override;<br>
uint32_t getThunkSectionSpacing() const override;<br>
- bool inBranchRange(RelType Type, uint64_t Src, uint64_t Dst) const override;<br>
- void relocateOne(uint8_t *Loc, RelType Type, uint64_t Val) const override;<br>
- RelExpr adjustRelaxExpr(RelType Type, const uint8_t *Data,<br>
- RelExpr Expr) const override;<br>
- int getTlsGdRelaxSkip(RelType Type) const override;<br>
- void relaxTlsGdToIe(uint8_t *Loc, RelType Type, uint64_t Val) const override;<br>
- void relaxTlsGdToLe(uint8_t *Loc, RelType Type, uint64_t Val) const override;<br>
- void relaxTlsLdToLe(uint8_t *Loc, RelType Type, uint64_t Val) const override;<br>
- void relaxTlsIeToLe(uint8_t *Loc, RelType Type, uint64_t Val) const override;<br>
+ bool inBranchRange(RelType type, uint64_t src, uint64_t dst) const override;<br>
+ void relocateOne(uint8_t *loc, RelType type, uint64_t val) const override;<br>
+ RelExpr adjustRelaxExpr(RelType type, const uint8_t *data,<br>
+ RelExpr expr) const override;<br>
+ int getTlsGdRelaxSkip(RelType type) const override;<br>
+ void relaxTlsGdToIe(uint8_t *loc, RelType type, uint64_t val) const override;<br>
+ void relaxTlsGdToLe(uint8_t *loc, RelType type, uint64_t val) const override;<br>
+ void relaxTlsLdToLe(uint8_t *loc, RelType type, uint64_t val) const override;<br>
+ void relaxTlsIeToLe(uint8_t *loc, RelType type, uint64_t val) const override;<br>
};<br>
} // namespace<br>
<br>
-static uint16_t lo(uint32_t V) { return V; }<br>
-static uint16_t ha(uint32_t V) { return (V + 0x8000) >> 16; }<br>
+static uint16_t lo(uint32_t v) { return v; }<br>
+static uint16_t ha(uint32_t v) { return (v + 0x8000) >> 16; }<br>
<br>
-static uint32_t readFromHalf16(const uint8_t *Loc) {<br>
- return read32(Config->IsLE ? Loc : Loc - 2);<br>
+static uint32_t readFromHalf16(const uint8_t *loc) {<br>
+ return read32(config->isLE ? loc : loc - 2);<br>
}<br>
<br>
-static void writeFromHalf16(uint8_t *Loc, uint32_t Insn) {<br>
- write32(Config->IsLE ? Loc : Loc - 2, Insn);<br>
+static void writeFromHalf16(uint8_t *loc, uint32_t insn) {<br>
+ write32(config->isLE ? loc : loc - 2, insn);<br>
}<br>
<br>
-void elf::writePPC32GlinkSection(uint8_t *Buf, size_t NumEntries) {<br>
+void elf::writePPC32GlinkSection(uint8_t *buf, size_t numEntries) {<br>
// On PPC Secure PLT ABI, bl foo@plt jumps to a call stub, which loads an<br>
// absolute address from a specific .plt slot (usually called .got.plt on<br>
// other targets) and jumps there.<br>
@@ -72,124 +72,124 @@ void elf::writePPC32GlinkSection(uint8_t<br>
// instruction in .glink, filled in by PPC::writeGotPlt().<br>
<br>
// Write N `b PLTresolve` first.<br>
- for (size_t I = 0; I != NumEntries; ++I)<br>
- write32(Buf + 4 * I, 0x48000000 | 4 * (NumEntries - I));<br>
- Buf += 4 * NumEntries;<br>
+ for (size_t i = 0; i != numEntries; ++i)<br>
+ write32(buf + 4 * i, 0x48000000 | 4 * (numEntries - i));<br>
+ buf += 4 * numEntries;<br>
<br>
// Then write PLTresolve(), which has two forms: PIC and non-PIC. PLTresolve()<br>
// computes the PLT index (by computing the distance from the landing b to<br>
// itself) and calls _dl_runtime_resolve() (in glibc).<br>
- uint32_t GOT = In.Got->getVA();<br>
- uint32_t Glink = In.Plt->getVA(); // VA of .glink<br>
- const uint8_t *End = Buf + 64;<br>
- if (Config->Pic) {<br>
- uint32_t AfterBcl = In.Plt->getSize() - Target->PltHeaderSize + 12;<br>
- uint32_t GotBcl = GOT + 4 - (Glink + AfterBcl);<br>
- write32(Buf + 0, 0x3d6b0000 | ha(AfterBcl)); // addis r11,r11,1f-glink@ha<br>
- write32(Buf + 4, 0x7c0802a6); // mflr r0<br>
- write32(Buf + 8, 0x429f0005); // bcl 20,30,.+4<br>
- write32(Buf + 12, 0x396b0000 | lo(AfterBcl)); // 1: addi r11,r11,1b-.glink@l<br>
- write32(Buf + 16, 0x7d8802a6); // mflr r12<br>
- write32(Buf + 20, 0x7c0803a6); // mtlr r0<br>
- write32(Buf + 24, 0x7d6c5850); // sub r11,r11,r12<br>
- write32(Buf + 28, 0x3d8c0000 | ha(GotBcl)); // addis 12,12,GOT+4-1b@ha<br>
- if (ha(GotBcl) == ha(GotBcl + 4)) {<br>
- write32(Buf + 32, 0x800c0000 | lo(GotBcl)); // lwz r0,r12,GOT+4-1b@l(r12)<br>
- write32(Buf + 36,<br>
- 0x818c0000 | lo(GotBcl + 4)); // lwz r12,r12,GOT+8-1b@l(r12)<br>
+ uint32_t got = in.got->getVA();<br>
+ uint32_t glink = in.plt->getVA(); // VA of .glink<br>
+ const uint8_t *end = buf + 64;<br>
+ if (config->isPic) {<br>
+ uint32_t afterBcl = in.plt->getSize() - target->pltHeaderSize + 12;<br>
+ uint32_t gotBcl = got + 4 - (glink + afterBcl);<br>
+ write32(buf + 0, 0x3d6b0000 | ha(afterBcl)); // addis r11,r11,1f-glink@ha<br>
+ write32(buf + 4, 0x7c0802a6); // mflr r0<br>
+ write32(buf + 8, 0x429f0005); // bcl 20,30,.+4<br>
+ write32(buf + 12, 0x396b0000 | lo(afterBcl)); // 1: addi r11,r11,1b-.glink@l<br>
+ write32(buf + 16, 0x7d8802a6); // mflr r12<br>
+ write32(buf + 20, 0x7c0803a6); // mtlr r0<br>
+ write32(buf + 24, 0x7d6c5850); // sub r11,r11,r12<br>
+ write32(buf + 28, 0x3d8c0000 | ha(gotBcl)); // addis 12,12,GOT+4-1b@ha<br>
+ if (ha(gotBcl) == ha(gotBcl + 4)) {<br>
+ write32(buf + 32, 0x800c0000 | lo(gotBcl)); // lwz r0,r12,GOT+4-1b@l(r12)<br>
+ write32(buf + 36,<br>
+ 0x818c0000 | lo(gotBcl + 4)); // lwz r12,r12,GOT+8-1b@l(r12)<br>
} else {<br>
- write32(Buf + 32, 0x840c0000 | lo(GotBcl)); // lwzu r0,r12,GOT+4-1b@l(r12)<br>
- write32(Buf + 36, 0x818c0000 | 4); // lwz r12,r12,4(r12)<br>
+ write32(buf + 32, 0x840c0000 | lo(gotBcl)); // lwzu r0,r12,GOT+4-1b@l(r12)<br>
+ write32(buf + 36, 0x818c0000 | 4); // lwz r12,r12,4(r12)<br>
}<br>
- write32(Buf + 40, 0x7c0903a6); // mtctr 0<br>
- write32(Buf + 44, 0x7c0b5a14); // add r0,11,11<br>
- write32(Buf + 48, 0x7d605a14); // add r11,0,11<br>
- write32(Buf + 52, 0x4e800420); // bctr<br>
- Buf += 56;<br>
+ write32(buf + 40, 0x7c0903a6); // mtctr 0<br>
+ write32(buf + 44, 0x7c0b5a14); // add r0,11,11<br>
+ write32(buf + 48, 0x7d605a14); // add r11,0,11<br>
+ write32(buf + 52, 0x4e800420); // bctr<br>
+ buf += 56;<br>
} else {<br>
- write32(Buf + 0, 0x3d800000 | ha(GOT + 4)); // lis r12,GOT+4@ha<br>
- write32(Buf + 4, 0x3d6b0000 | ha(-Glink)); // addis r11,r11,-Glink@ha<br>
- if (ha(GOT + 4) == ha(GOT + 8))<br>
- write32(Buf + 8, 0x800c0000 | lo(GOT + 4)); // lwz r0,GOT+4@l(r12)<br>
+ write32(buf + 0, 0x3d800000 | ha(got + 4)); // lis r12,GOT+4@ha<br>
+ write32(buf + 4, 0x3d6b0000 | ha(-glink)); // addis r11,r11,-Glink@ha<br>
+ if (ha(got + 4) == ha(got + 8))<br>
+ write32(buf + 8, 0x800c0000 | lo(got + 4)); // lwz r0,GOT+4@l(r12)<br>
else<br>
- write32(Buf + 8, 0x840c0000 | lo(GOT + 4)); // lwzu r0,GOT+4@l(r12)<br>
- write32(Buf + 12, 0x396b0000 | lo(-Glink)); // addi r11,r11,-Glink@l<br>
- write32(Buf + 16, 0x7c0903a6); // mtctr r0<br>
- write32(Buf + 20, 0x7c0b5a14); // add r0,r11,r11<br>
- if (ha(GOT + 4) == ha(GOT + 8))<br>
- write32(Buf + 24, 0x818c0000 | lo(GOT + 8)); // lwz r12,GOT+8@ha(r12)<br>
+ write32(buf + 8, 0x840c0000 | lo(got + 4)); // lwzu r0,GOT+4@l(r12)<br>
+ write32(buf + 12, 0x396b0000 | lo(-glink)); // addi r11,r11,-Glink@l<br>
+ write32(buf + 16, 0x7c0903a6); // mtctr r0<br>
+ write32(buf + 20, 0x7c0b5a14); // add r0,r11,r11<br>
+ if (ha(got + 4) == ha(got + 8))<br>
+ write32(buf + 24, 0x818c0000 | lo(got + 8)); // lwz r12,GOT+8@ha(r12)<br>
else<br>
- write32(Buf + 24, 0x818c0000 | 4); // lwz r12,4(r12)<br>
- write32(Buf + 28, 0x7d605a14); // add r11,r0,r11<br>
- write32(Buf + 32, 0x4e800420); // bctr<br>
- Buf += 36;<br>
+ write32(buf + 24, 0x818c0000 | 4); // lwz r12,4(r12)<br>
+ write32(buf + 28, 0x7d605a14); // add r11,r0,r11<br>
+ write32(buf + 32, 0x4e800420); // bctr<br>
+ buf += 36;<br>
}<br>
<br>
// Pad with nop. They should not be executed.<br>
- for (; Buf < End; Buf += 4)<br>
- write32(Buf, 0x60000000);<br>
+ for (; buf < end; buf += 4)<br>
+ write32(buf, 0x60000000);<br>
}<br>
<br>
PPC::PPC() {<br>
- GotRel = R_PPC_GLOB_DAT;<br>
- NoneRel = R_PPC_NONE;<br>
- PltRel = R_PPC_JMP_SLOT;<br>
- RelativeRel = R_PPC_RELATIVE;<br>
- IRelativeRel = R_PPC_IRELATIVE;<br>
- SymbolicRel = R_PPC_ADDR32;<br>
- GotBaseSymInGotPlt = false;<br>
- GotHeaderEntriesNum = 3;<br>
- GotPltHeaderEntriesNum = 0;<br>
- PltHeaderSize = 64; // size of PLTresolve in .glink<br>
- PltEntrySize = 4;<br>
-<br>
- NeedsThunks = true;<br>
-<br>
- TlsModuleIndexRel = R_PPC_DTPMOD32;<br>
- TlsOffsetRel = R_PPC_DTPREL32;<br>
- TlsGotRel = R_PPC_TPREL32;<br>
+ gotRel = R_PPC_GLOB_DAT;<br>
+ noneRel = R_PPC_NONE;<br>
+ pltRel = R_PPC_JMP_SLOT;<br>
+ relativeRel = R_PPC_RELATIVE;<br>
+ iRelativeRel = R_PPC_IRELATIVE;<br>
+ symbolicRel = R_PPC_ADDR32;<br>
+ gotBaseSymInGotPlt = false;<br>
+ gotHeaderEntriesNum = 3;<br>
+ gotPltHeaderEntriesNum = 0;<br>
+ pltHeaderSize = 64; // size of PLTresolve in .glink<br>
+ pltEntrySize = 4;<br>
+<br>
+ needsThunks = true;<br>
+<br>
+ tlsModuleIndexRel = R_PPC_DTPMOD32;<br>
+ tlsOffsetRel = R_PPC_DTPREL32;<br>
+ tlsGotRel = R_PPC_TPREL32;<br>
<br>
- DefaultMaxPageSize = 65536;<br>
- DefaultImageBase = 0x10000000;<br>
+ defaultMaxPageSize = 65536;<br>
+ defaultImageBase = 0x10000000;<br>
<br>
- write32(TrapInstr.data(), 0x7fe00008);<br>
+ write32(trapInstr.data(), 0x7fe00008);<br>
}<br>
<br>
-void PPC::writeGotHeader(uint8_t *Buf) const {<br>
+void PPC::writeGotHeader(uint8_t *buf) const {<br>
// _GLOBAL_OFFSET_TABLE_[0] = _DYNAMIC<br>
// glibc stores _dl_runtime_resolve in _GLOBAL_OFFSET_TABLE_[1],<br>
// link_map in _GLOBAL_OFFSET_TABLE_[2].<br>
- write32(Buf, Main->Dynamic->getVA());<br>
+ write32(buf, mainPart->dynamic->getVA());<br>
}<br>
<br>
-void PPC::writeGotPlt(uint8_t *Buf, const Symbol &S) const {<br>
+void PPC::writeGotPlt(uint8_t *buf, const Symbol &s) const {<br>
// Address of the symbol resolver stub in .glink .<br>
- write32(Buf, In.Plt->getVA() + 4 * S.PltIndex);<br>
+ write32(buf, in.plt->getVA() + 4 * s.pltIndex);<br>
}<br>
<br>
-bool PPC::needsThunk(RelExpr Expr, RelType Type, const InputFile *File,<br>
- uint64_t BranchAddr, const Symbol &S) const {<br>
- if (Type != R_PPC_REL24 && Type != R_PPC_PLTREL24)<br>
+bool PPC::needsThunk(RelExpr expr, RelType type, const InputFile *file,<br>
+ uint64_t branchAddr, const Symbol &s) const {<br>
+ if (type != R_PPC_REL24 && type != R_PPC_PLTREL24)<br>
return false;<br>
- if (S.isInPlt())<br>
+ if (s.isInPlt())<br>
return true;<br>
- if (S.isUndefWeak())<br>
+ if (s.isUndefWeak())<br>
return false;<br>
- return !(Expr == R_PC && PPC::inBranchRange(Type, BranchAddr, S.getVA()));<br>
+ return !(expr == R_PC && PPC::inBranchRange(type, branchAddr, s.getVA()));<br>
}<br>
<br>
uint32_t PPC::getThunkSectionSpacing() const { return 0x2000000; }<br>
<br>
-bool PPC::inBranchRange(RelType Type, uint64_t Src, uint64_t Dst) const {<br>
- uint64_t Offset = Dst - Src;<br>
- if (Type == R_PPC_REL24 || Type == R_PPC_PLTREL24)<br>
- return isInt<26>(Offset);<br>
+bool PPC::inBranchRange(RelType type, uint64_t src, uint64_t dst) const {<br>
+ uint64_t offset = dst - src;<br>
+ if (type == R_PPC_REL24 || type == R_PPC_PLTREL24)<br>
+ return isInt<26>(offset);<br>
llvm_unreachable("unsupported relocation type used in branch");<br>
}<br>
<br>
-RelExpr PPC::getRelExpr(RelType Type, const Symbol &S,<br>
- const uint8_t *Loc) const {<br>
- switch (Type) {<br>
+RelExpr PPC::getRelExpr(RelType type, const Symbol &s,<br>
+ const uint8_t *loc) const {<br>
+ switch (type) {<br>
case R_PPC_DTPREL16:<br>
case R_PPC_DTPREL16_HA:<br>
case R_PPC_DTPREL16_HI:<br>
@@ -231,45 +231,45 @@ RelExpr PPC::getRelExpr(RelType Type, co<br>
}<br>
}<br>
<br>
-RelType PPC::getDynRel(RelType Type) const {<br>
- if (Type == R_PPC_ADDR32)<br>
- return Type;<br>
+RelType PPC::getDynRel(RelType type) const {<br>
+ if (type == R_PPC_ADDR32)<br>
+ return type;<br>
return R_PPC_NONE;<br>
}<br>
<br>
-static std::pair<RelType, uint64_t> fromDTPREL(RelType Type, uint64_t Val) {<br>
- uint64_t DTPBiasedVal = Val - 0x8000;<br>
- switch (Type) {<br>
+static std::pair<RelType, uint64_t> fromDTPREL(RelType type, uint64_t val) {<br>
+ uint64_t dtpBiasedVal = val - 0x8000;<br>
+ switch (type) {<br>
case R_PPC_DTPREL16:<br>
- return {R_PPC64_ADDR16, DTPBiasedVal};<br>
+ return {R_PPC64_ADDR16, dtpBiasedVal};<br>
case R_PPC_DTPREL16_HA:<br>
- return {R_PPC_ADDR16_HA, DTPBiasedVal};<br>
+ return {R_PPC_ADDR16_HA, dtpBiasedVal};<br>
case R_PPC_DTPREL16_HI:<br>
- return {R_PPC_ADDR16_HI, DTPBiasedVal};<br>
+ return {R_PPC_ADDR16_HI, dtpBiasedVal};<br>
case R_PPC_DTPREL16_LO:<br>
- return {R_PPC_ADDR16_LO, DTPBiasedVal};<br>
+ return {R_PPC_ADDR16_LO, dtpBiasedVal};<br>
case R_PPC_DTPREL32:<br>
- return {R_PPC_ADDR32, DTPBiasedVal};<br>
+ return {R_PPC_ADDR32, dtpBiasedVal};<br>
default:<br>
- return {Type, Val};<br>
+ return {type, val};<br>
}<br>
}<br>
<br>
-void PPC::relocateOne(uint8_t *Loc, RelType Type, uint64_t Val) const {<br>
- RelType NewType;<br>
- std::tie(NewType, Val) = fromDTPREL(Type, Val);<br>
- switch (NewType) {<br>
+void PPC::relocateOne(uint8_t *loc, RelType type, uint64_t val) const {<br>
+ RelType newType;<br>
+ std::tie(newType, val) = fromDTPREL(type, val);<br>
+ switch (newType) {<br>
case R_PPC_ADDR16:<br>
- checkIntUInt(Loc, Val, 16, Type);<br>
- write16(Loc, Val);<br>
+ checkIntUInt(loc, val, 16, type);<br>
+ write16(loc, val);<br>
break;<br>
case R_PPC_GOT16:<br>
case R_PPC_GOT_TLSGD16:<br>
case R_PPC_GOT_TLSLD16:<br>
case R_PPC_GOT_TPREL16:<br>
case R_PPC_TPREL16:<br>
- checkInt(Loc, Val, 16, Type);<br>
- write16(Loc, Val);<br>
+ checkInt(loc, val, 16, type);<br>
+ write16(loc, val);<br>
break;<br>
case R_PPC_ADDR16_HA:<br>
case R_PPC_DTPREL16_HA:<br>
@@ -278,7 +278,7 @@ void PPC::relocateOne(uint8_t *Loc, RelT<br>
case R_PPC_GOT_TPREL16_HA:<br>
case R_PPC_REL16_HA:<br>
case R_PPC_TPREL16_HA:<br>
- write16(Loc, ha(Val));<br>
+ write16(loc, ha(val));<br>
break;<br>
case R_PPC_ADDR16_HI:<br>
case R_PPC_DTPREL16_HI:<br>
@@ -287,7 +287,7 @@ void PPC::relocateOne(uint8_t *Loc, RelT<br>
case R_PPC_GOT_TPREL16_HI:<br>
case R_PPC_REL16_HI:<br>
case R_PPC_TPREL16_HI:<br>
- write16(Loc, Val >> 16);<br>
+ write16(loc, val >> 16);<br>
break;<br>
case R_PPC_ADDR16_LO:<br>
case R_PPC_DTPREL16_LO:<br>
@@ -296,43 +296,43 @@ void PPC::relocateOne(uint8_t *Loc, RelT<br>
case R_PPC_GOT_TPREL16_LO:<br>
case R_PPC_REL16_LO:<br>
case R_PPC_TPREL16_LO:<br>
- write16(Loc, Val);<br>
+ write16(loc, val);<br>
break;<br>
case R_PPC_ADDR32:<br>
case R_PPC_REL32:<br>
- write32(Loc, Val);<br>
+ write32(loc, val);<br>
break;<br>
case R_PPC_REL14: {<br>
- uint32_t Mask = 0x0000FFFC;<br>
- checkInt(Loc, Val, 16, Type);<br>
- checkAlignment(Loc, Val, 4, Type);<br>
- write32(Loc, (read32(Loc) & ~Mask) | (Val & Mask));<br>
+ uint32_t mask = 0x0000FFFC;<br>
+ checkInt(loc, val, 16, type);<br>
+ checkAlignment(loc, val, 4, type);<br>
+ write32(loc, (read32(loc) & ~mask) | (val & mask));<br>
break;<br>
}<br>
case R_PPC_REL24:<br>
case R_PPC_LOCAL24PC:<br>
case R_PPC_PLTREL24: {<br>
- uint32_t Mask = 0x03FFFFFC;<br>
- checkInt(Loc, Val, 26, Type);<br>
- checkAlignment(Loc, Val, 4, Type);<br>
- write32(Loc, (read32(Loc) & ~Mask) | (Val & Mask));<br>
+ uint32_t mask = 0x03FFFFFC;<br>
+ checkInt(loc, val, 26, type);<br>
+ checkAlignment(loc, val, 4, type);<br>
+ write32(loc, (read32(loc) & ~mask) | (val & mask));<br>
break;<br>
}<br>
default:<br>
- error(getErrorLocation(Loc) + "unrecognized relocation " + toString(Type));<br>
+ error(getErrorLocation(loc) + "unrecognized relocation " + toString(type));<br>
}<br>
}<br>
<br>
-RelExpr PPC::adjustRelaxExpr(RelType Type, const uint8_t *Data,<br>
- RelExpr Expr) const {<br>
- if (Expr == R_RELAX_TLS_GD_TO_IE)<br>
+RelExpr PPC::adjustRelaxExpr(RelType type, const uint8_t *data,<br>
+ RelExpr expr) const {<br>
+ if (expr == R_RELAX_TLS_GD_TO_IE)<br>
return R_RELAX_TLS_GD_TO_IE_GOT_OFF;<br>
- if (Expr == R_RELAX_TLS_LD_TO_LE)<br>
+ if (expr == R_RELAX_TLS_LD_TO_LE)<br>
return R_RELAX_TLS_LD_TO_LE_ABS;<br>
- return Expr;<br>
+ return expr;<br>
}<br>
<br>
-int PPC::getTlsGdRelaxSkip(RelType Type) const {<br>
+int PPC::getTlsGdRelaxSkip(RelType type) const {<br>
// A __tls_get_addr call instruction is marked with 2 relocations:<br>
//<br>
// R_PPC_TLSGD / R_PPC_TLSLD: marker relocation<br>
@@ -341,84 +341,84 @@ int PPC::getTlsGdRelaxSkip(RelType Type)<br>
// After the relaxation we no longer call __tls_get_addr and should skip both<br>
// relocations to not create a false dependence on __tls_get_addr being<br>
// defined.<br>
- if (Type == R_PPC_TLSGD || Type == R_PPC_TLSLD)<br>
+ if (type == R_PPC_TLSGD || type == R_PPC_TLSLD)<br>
return 2;<br>
return 1;<br>
}<br>
<br>
-void PPC::relaxTlsGdToIe(uint8_t *Loc, RelType Type, uint64_t Val) const {<br>
- switch (Type) {<br>
+void PPC::relaxTlsGdToIe(uint8_t *loc, RelType type, uint64_t val) const {<br>
+ switch (type) {<br>
case R_PPC_GOT_TLSGD16: {<br>
// addi rT, rA, x@got@tlsgd --> lwz rT, x@got@tprel(rA)<br>
- uint32_t Insn = readFromHalf16(Loc);<br>
- writeFromHalf16(Loc, 0x80000000 | (Insn & 0x03ff0000));<br>
- relocateOne(Loc, R_PPC_GOT_TPREL16, Val);<br>
+ uint32_t insn = readFromHalf16(loc);<br>
+ writeFromHalf16(loc, 0x80000000 | (insn & 0x03ff0000));<br>
+ relocateOne(loc, R_PPC_GOT_TPREL16, val);<br>
break;<br>
}<br>
case R_PPC_TLSGD:<br>
// bl __tls_get_addr(x@tldgd) --> add r3, r3, r2<br>
- write32(Loc, 0x7c631214);<br>
+ write32(loc, 0x7c631214);<br>
break;<br>
default:<br>
llvm_unreachable("unsupported relocation for TLS GD to IE relaxation");<br>
}<br>
}<br>
<br>
-void PPC::relaxTlsGdToLe(uint8_t *Loc, RelType Type, uint64_t Val) const {<br>
- switch (Type) {<br>
+void PPC::relaxTlsGdToLe(uint8_t *loc, RelType type, uint64_t val) const {<br>
+ switch (type) {<br>
case R_PPC_GOT_TLSGD16:<br>
// addi r3, r31, x@got@tlsgd --> addis r3, r2, x@tprel@ha<br>
- writeFromHalf16(Loc, 0x3c620000 | ha(Val));<br>
+ writeFromHalf16(loc, 0x3c620000 | ha(val));<br>
break;<br>
case R_PPC_TLSGD:<br>
// bl __tls_get_addr(x@tldgd) --> add r3, r3, x@tprel@l<br>
- write32(Loc, 0x38630000 | lo(Val));<br>
+ write32(loc, 0x38630000 | lo(val));<br>
break;<br>
default:<br>
llvm_unreachable("unsupported relocation for TLS GD to LE relaxation");<br>
}<br>
}<br>
<br>
-void PPC::relaxTlsLdToLe(uint8_t *Loc, RelType Type, uint64_t Val) const {<br>
- switch (Type) {<br>
+void PPC::relaxTlsLdToLe(uint8_t *loc, RelType type, uint64_t val) const {<br>
+ switch (type) {<br>
case R_PPC_GOT_TLSLD16:<br>
// addi r3, rA, x@got@tlsgd --> addis r3, r2, 0<br>
- writeFromHalf16(Loc, 0x3c620000);<br>
+ writeFromHalf16(loc, 0x3c620000);<br>
break;<br>
case R_PPC_TLSLD:<br>
// r3+x@dtprel computes r3+x-0x8000, while we want it to compute r3+x@tprel<br>
// = r3+x-0x7000, so add 4096 to r3.<br>
// bl __tls_get_addr(x@tlsld) --> addi r3, r3, 4096<br>
- write32(Loc, 0x38631000);<br>
+ write32(loc, 0x38631000);<br>
break;<br>
case R_PPC_DTPREL16:<br>
case R_PPC_DTPREL16_HA:<br>
case R_PPC_DTPREL16_HI:<br>
case R_PPC_DTPREL16_LO:<br>
- relocateOne(Loc, Type, Val);<br>
+ relocateOne(loc, type, val);<br>
break;<br>
default:<br>
llvm_unreachable("unsupported relocation for TLS LD to LE relaxation");<br>
}<br>
}<br>
<br>
-void PPC::relaxTlsIeToLe(uint8_t *Loc, RelType Type, uint64_t Val) const {<br>
- switch (Type) {<br>
+void PPC::relaxTlsIeToLe(uint8_t *loc, RelType type, uint64_t val) const {<br>
+ switch (type) {<br>
case R_PPC_GOT_TPREL16: {<br>
// lwz rT, x@got@tprel(rA) --> addis rT, r2, x@tprel@ha<br>
- uint32_t RT = readFromHalf16(Loc) & 0x03e00000;<br>
- writeFromHalf16(Loc, 0x3c020000 | RT | ha(Val));<br>
+ uint32_t rt = readFromHalf16(loc) & 0x03e00000;<br>
+ writeFromHalf16(loc, 0x3c020000 | rt | ha(val));<br>
break;<br>
}<br>
case R_PPC_TLS: {<br>
- uint32_t Insn = read32(Loc);<br>
- if (Insn >> 26 != 31)<br>
+ uint32_t insn = read32(loc);<br>
+ if (insn >> 26 != 31)<br>
error("unrecognized instruction for IE to LE R_PPC_TLS");<br>
// addi rT, rT, x@tls --> addi rT, rT, x@tprel@l<br>
- uint32_t DFormOp = getPPCDFormOp((read32(Loc) & 0x000007fe) >> 1);<br>
- if (DFormOp == 0)<br>
+ uint32_t dFormOp = getPPCDFormOp((read32(loc) & 0x000007fe) >> 1);<br>
+ if (dFormOp == 0)<br>
error("unrecognized instruction for IE to LE R_PPC_TLS");<br>
- write32(Loc, (DFormOp << 26) | (Insn & 0x03ff0000) | lo(Val));<br>
+ write32(loc, (dFormOp << 26) | (insn & 0x03ff0000) | lo(val));<br>
break;<br>
}<br>
default:<br>
@@ -427,6 +427,6 @@ void PPC::relaxTlsIeToLe(uint8_t *Loc, R<br>
}<br>
<br>
TargetInfo *elf::getPPCTargetInfo() {<br>
- static PPC Target;<br>
- return &Target;<br>
+ static PPC target;<br>
+ return ⌖<br>
}<br>
<br>
Modified: lld/trunk/ELF/Arch/PPC64.cpp<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_ELF_Arch_PPC64.cpp-3Frev-3D365595-26r1-3D365594-26r2-3D365595-26view-3Ddiff&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=EzixpdT6lyPB3vPt-x8pFLwxMAP7gZzNCEfZeFg99qE&e=" rel="noreferrer" target="_blank">https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_ELF_Arch_PPC64.cpp-3Frev-3D365595-26r1-3D365594-26r2-3D365595-26view-3Ddiff&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=EzixpdT6lyPB3vPt-x8pFLwxMAP7gZzNCEfZeFg99qE&e=</a> <br>
==============================================================================<br>
--- lld/trunk/ELF/Arch/PPC64.cpp (original)<br>
+++ lld/trunk/ELF/Arch/PPC64.cpp Tue Jul 9 22:00:37 2019<br>
@@ -19,8 +19,8 @@ using namespace llvm::ELF;<br>
using namespace lld;<br>
using namespace lld::elf;<br>
<br>
-static uint64_t PPC64TocOffset = 0x8000;<br>
-static uint64_t DynamicThreadPointerOffset = 0x8000;<br>
+static uint64_t ppc64TocOffset = 0x8000;<br>
+static uint64_t dynamicThreadPointerOffset = 0x8000;<br>
<br>
// The instruction encoding of bits 21-30 from the ISA for the Xform and Dform<br>
// instructions that can be used as part of the initial exec TLS sequence.<br>
@@ -64,16 +64,16 @@ uint64_t elf::getPPC64TocBase() {<br>
// TOC starts where the first of these sections starts. We always create a<br>
// .got when we see a relocation that uses it, so for us the start is always<br>
// the .got.<br>
- uint64_t TocVA = In.Got->getVA();<br>
+ uint64_t tocVA = in.got->getVA();<br>
<br>
// Per the ppc64-elf-linux ABI, The TOC base is TOC value plus 0x8000<br>
// thus permitting a full 64 Kbytes segment. Note that the glibc startup<br>
// code (crt1.o) assumes that you can get from the TOC base to the<br>
// start of the .toc section with only a single (signed) 16-bit relocation.<br>
- return TocVA + PPC64TocOffset;<br>
+ return tocVA + ppc64TocOffset;<br>
}<br>
<br>
-unsigned elf::getPPC64GlobalEntryToLocalEntryOffset(uint8_t StOther) {<br>
+unsigned elf::getPPC64GlobalEntryToLocalEntryOffset(uint8_t stOther) {<br>
// The offset is encoded into the 3 most significant bits of the st_other<br>
// field, with some special values described in section 3.4.1 of the ABI:<br>
// 0 --> Zero offset between the GEP and LEP, and the function does NOT use<br>
@@ -85,29 +85,29 @@ unsigned elf::getPPC64GlobalEntryToLocal<br>
// 2 --> 2^2 = 4 bytes --> 1 instruction.<br>
// 6 --> 2^6 = 64 bytes --> 16 instructions.<br>
// 7 --> Reserved.<br>
- uint8_t GepToLep = (StOther >> 5) & 7;<br>
- if (GepToLep < 2)<br>
+ uint8_t gepToLep = (stOther >> 5) & 7;<br>
+ if (gepToLep < 2)<br>
return 0;<br>
<br>
// The value encoded in the st_other bits is the<br>
// log-base-2(offset).<br>
- if (GepToLep < 7)<br>
- return 1 << GepToLep;<br>
+ if (gepToLep < 7)<br>
+ return 1 << gepToLep;<br>
<br>
error("reserved value of 7 in the 3 most-significant-bits of st_other");<br>
return 0;<br>
}<br>
<br>
-bool elf::isPPC64SmallCodeModelTocReloc(RelType Type) {<br>
+bool elf::isPPC64SmallCodeModelTocReloc(RelType type) {<br>
// The only small code model relocations that access the .toc section.<br>
- return Type == R_PPC64_TOC16 || Type == R_PPC64_TOC16_DS;<br>
+ return type == R_PPC64_TOC16 || type == R_PPC64_TOC16_DS;<br>
}<br>
<br>
// Find the R_PPC64_ADDR64 in .rela.toc with matching offset.<br>
template <typename ELFT><br>
static std::pair<Defined *, int64_t><br>
-getRelaTocSymAndAddend(InputSectionBase *TocSec, uint64_t Offset) {<br>
- if (TocSec->NumRelocations == 0)<br>
+getRelaTocSymAndAddend(InputSectionBase *tocSec, uint64_t offset) {<br>
+ if (tocSec->numRelocations == 0)<br>
return {};<br>
<br>
// .rela.toc contains exclusively R_PPC64_ADDR64 relocations sorted by<br>
@@ -119,16 +119,16 @@ getRelaTocSymAndAddend(InputSectionBase<br>
// points to a relocation with larger r_offset. Do a linear probe then.<br>
// Constants are extremely uncommon in .toc and the extra number of array<br>
// accesses can be seen as a small constant.<br>
- ArrayRef<typename ELFT::Rela> Relas = TocSec->template relas<ELFT>();<br>
- uint64_t Index = std::min<uint64_t>(Offset / 8, Relas.size() - 1);<br>
+ ArrayRef<typename ELFT::Rela> relas = tocSec->template relas<ELFT>();<br>
+ uint64_t index = std::min<uint64_t>(offset / 8, relas.size() - 1);<br>
for (;;) {<br>
- if (Relas[Index].r_offset == Offset) {<br>
- Symbol &Sym = TocSec->getFile<ELFT>()->getRelocTargetSym(Relas[Index]);<br>
- return {dyn_cast<Defined>(&Sym), getAddend<ELFT>(Relas[Index])};<br>
+ if (relas[index].r_offset == offset) {<br>
+ Symbol &sym = tocSec->getFile<ELFT>()->getRelocTargetSym(relas[index]);<br>
+ return {dyn_cast<Defined>(&sym), getAddend<ELFT>(relas[index])};<br>
}<br>
- if (Relas[Index].r_offset < Offset || Index == 0)<br>
+ if (relas[index].r_offset < offset || index == 0)<br>
break;<br>
- --Index;<br>
+ --index;<br>
}<br>
return {};<br>
}<br>
@@ -153,35 +153,35 @@ getRelaTocSymAndAddend(InputSectionBase<br>
// ld/lwa 3, 0(3) # load the value from the address<br>
//<br>
// Returns true if the relaxation is performed.<br>
-bool elf::tryRelaxPPC64TocIndirection(RelType Type, const Relocation &Rel,<br>
- uint8_t *BufLoc) {<br>
- assert(Config->TocOptimize);<br>
- if (Rel.Addend < 0)<br>
+bool elf::tryRelaxPPC64TocIndirection(RelType type, const Relocation &rel,<br>
+ uint8_t *bufLoc) {<br>
+ assert(config->tocOptimize);<br>
+ if (rel.addend < 0)<br>
return false;<br>
<br>
// If the symbol is not the .toc section, this isn't a toc-indirection.<br>
- Defined *DefSym = dyn_cast<Defined>(Rel.Sym);<br>
- if (!DefSym || !DefSym->isSection() || DefSym->Section->Name != ".toc")<br>
+ Defined *defSym = dyn_cast<Defined>(rel.sym);<br>
+ if (!defSym || !defSym->isSection() || defSym->section->name != ".toc")<br>
return false;<br>
<br>
- Defined *D;<br>
- int64_t Addend;<br>
- auto *TocISB = cast<InputSectionBase>(DefSym->Section);<br>
- std::tie(D, Addend) =<br>
- Config->IsLE ? getRelaTocSymAndAddend<ELF64LE>(TocISB, Rel.Addend)<br>
- : getRelaTocSymAndAddend<ELF64BE>(TocISB, Rel.Addend);<br>
+ Defined *d;<br>
+ int64_t addend;<br>
+ auto *tocISB = cast<InputSectionBase>(defSym->section);<br>
+ std::tie(d, addend) =<br>
+ config->isLE ? getRelaTocSymAndAddend<ELF64LE>(tocISB, rel.addend)<br>
+ : getRelaTocSymAndAddend<ELF64BE>(tocISB, rel.addend);<br>
<br>
// Only non-preemptable defined symbols can be relaxed.<br>
- if (!D || D->IsPreemptible)<br>
+ if (!d || d->isPreemptible)<br>
return false;<br>
<br>
// Two instructions can materialize a 32-bit signed offset from the toc base.<br>
- uint64_t TocRelative = D->getVA(Addend) - getPPC64TocBase();<br>
- if (!isInt<32>(TocRelative))<br>
+ uint64_t tocRelative = d->getVA(addend) - getPPC64TocBase();<br>
+ if (!isInt<32>(tocRelative))<br>
return false;<br>
<br>
// Add PPC64TocOffset that will be subtracted by relocateOne().<br>
- Target->relaxGot(BufLoc, Type, TocRelative + PPC64TocOffset);<br>
+ target->relaxGot(bufLoc, type, tocRelative + ppc64TocOffset);<br>
return true;<br>
}<br>
<br>
@@ -189,30 +189,30 @@ namespace {<br>
class PPC64 final : public TargetInfo {<br>
public:<br>
PPC64();<br>
- int getTlsGdRelaxSkip(RelType Type) const override;<br>
+ int getTlsGdRelaxSkip(RelType type) const override;<br>
uint32_t calcEFlags() const override;<br>
- RelExpr getRelExpr(RelType Type, const Symbol &S,<br>
- const uint8_t *Loc) const override;<br>
- RelType getDynRel(RelType Type) const override;<br>
- void writePltHeader(uint8_t *Buf) const override;<br>
- void writePlt(uint8_t *Buf, uint64_t GotPltEntryAddr, uint64_t PltEntryAddr,<br>
- int32_t Index, unsigned RelOff) const override;<br>
- void relocateOne(uint8_t *Loc, RelType Type, uint64_t Val) const override;<br>
- void writeGotHeader(uint8_t *Buf) const override;<br>
- bool needsThunk(RelExpr Expr, RelType Type, const InputFile *File,<br>
- uint64_t BranchAddr, const Symbol &S) const override;<br>
+ RelExpr getRelExpr(RelType type, const Symbol &s,<br>
+ const uint8_t *loc) const override;<br>
+ RelType getDynRel(RelType type) const override;<br>
+ void writePltHeader(uint8_t *buf) const override;<br>
+ void writePlt(uint8_t *buf, uint64_t gotPltEntryAddr, uint64_t pltEntryAddr,<br>
+ int32_t index, unsigned relOff) const override;<br>
+ void relocateOne(uint8_t *loc, RelType type, uint64_t val) const override;<br>
+ void writeGotHeader(uint8_t *buf) const override;<br>
+ bool needsThunk(RelExpr expr, RelType type, const InputFile *file,<br>
+ uint64_t branchAddr, const Symbol &s) const override;<br>
uint32_t getThunkSectionSpacing() const override;<br>
- bool inBranchRange(RelType Type, uint64_t Src, uint64_t Dst) const override;<br>
- RelExpr adjustRelaxExpr(RelType Type, const uint8_t *Data,<br>
- RelExpr Expr) const override;<br>
- void relaxGot(uint8_t *Loc, RelType Type, uint64_t Val) const override;<br>
- void relaxTlsGdToIe(uint8_t *Loc, RelType Type, uint64_t Val) const override;<br>
- void relaxTlsGdToLe(uint8_t *Loc, RelType Type, uint64_t Val) const override;<br>
- void relaxTlsLdToLe(uint8_t *Loc, RelType Type, uint64_t Val) const override;<br>
- void relaxTlsIeToLe(uint8_t *Loc, RelType Type, uint64_t Val) const override;<br>
+ bool inBranchRange(RelType type, uint64_t src, uint64_t dst) const override;<br>
+ RelExpr adjustRelaxExpr(RelType type, const uint8_t *data,<br>
+ RelExpr expr) const override;<br>
+ void relaxGot(uint8_t *loc, RelType type, uint64_t val) const override;<br>
+ void relaxTlsGdToIe(uint8_t *loc, RelType type, uint64_t val) const override;<br>
+ void relaxTlsGdToLe(uint8_t *loc, RelType type, uint64_t val) const override;<br>
+ void relaxTlsLdToLe(uint8_t *loc, RelType type, uint64_t val) const override;<br>
+ void relaxTlsIeToLe(uint8_t *loc, RelType type, uint64_t val) const override;<br>
<br>
- bool adjustPrologueForCrossSplitStack(uint8_t *Loc, uint8_t *End,<br>
- uint8_t StOther) const override;<br>
+ bool adjustPrologueForCrossSplitStack(uint8_t *loc, uint8_t *end,<br>
+ uint8_t stOther) const override;<br>
};<br>
} // namespace<br>
<br>
@@ -220,19 +220,19 @@ public:<br>
// #higher(value), #highera(value), #highest(value), and #highesta(value)<br>
// macros defined in section 4.5.1. Relocation Types of the PPC-elf64abi<br>
// document.<br>
-static uint16_t lo(uint64_t V) { return V; }<br>
-static uint16_t hi(uint64_t V) { return V >> 16; }<br>
-static uint16_t ha(uint64_t V) { return (V + 0x8000) >> 16; }<br>
-static uint16_t higher(uint64_t V) { return V >> 32; }<br>
-static uint16_t highera(uint64_t V) { return (V + 0x8000) >> 32; }<br>
-static uint16_t highest(uint64_t V) { return V >> 48; }<br>
-static uint16_t highesta(uint64_t V) { return (V + 0x8000) >> 48; }<br>
+static uint16_t lo(uint64_t v) { return v; }<br>
+static uint16_t hi(uint64_t v) { return v >> 16; }<br>
+static uint16_t ha(uint64_t v) { return (v + 0x8000) >> 16; }<br>
+static uint16_t higher(uint64_t v) { return v >> 32; }<br>
+static uint16_t highera(uint64_t v) { return (v + 0x8000) >> 32; }<br>
+static uint16_t highest(uint64_t v) { return v >> 48; }<br>
+static uint16_t highesta(uint64_t v) { return (v + 0x8000) >> 48; }<br>
<br>
// Extracts the 'PO' field of an instruction encoding.<br>
-static uint8_t getPrimaryOpCode(uint32_t Encoding) { return (Encoding >> 26); }<br>
+static uint8_t getPrimaryOpCode(uint32_t encoding) { return (encoding >> 26); }<br>
<br>
-static bool isDQFormInstruction(uint32_t Encoding) {<br>
- switch (getPrimaryOpCode(Encoding)) {<br>
+static bool isDQFormInstruction(uint32_t encoding) {<br>
+ switch (getPrimaryOpCode(encoding)) {<br>
default:<br>
return false;<br>
case 56:<br>
@@ -242,12 +242,12 @@ static bool isDQFormInstruction(uint32_t<br>
// There are both DS and DQ instruction forms with this primary opcode.<br>
// Namely `lxv` and `stxv` are the DQ-forms that use it.<br>
// The DS 'XO' bits being set to 01 is restricted to DQ form.<br>
- return (Encoding & 3) == 0x1;<br>
+ return (encoding & 3) == 0x1;<br>
}<br>
}<br>
<br>
-static bool isInstructionUpdateForm(uint32_t Encoding) {<br>
- switch (getPrimaryOpCode(Encoding)) {<br>
+static bool isInstructionUpdateForm(uint32_t encoding) {<br>
+ switch (getPrimaryOpCode(encoding)) {<br>
default:<br>
return false;<br>
case LBZU:<br>
@@ -266,7 +266,7 @@ static bool isInstructionUpdateForm(uint<br>
// between LD/LDU/LWA<br>
case LD:<br>
case STD:<br>
- return (Encoding & 3) == 1;<br>
+ return (encoding & 3) == 1;<br>
}<br>
}<br>
<br>
@@ -275,38 +275,38 @@ static bool isInstructionUpdateForm(uint<br>
// pointer is pointing into the middle of the word we want to extract, and on<br>
// little-endian it is pointing to the start of the word. These 2 helpers are to<br>
// simplify reading and writing in that context.<br>
-static void writeFromHalf16(uint8_t *Loc, uint32_t Insn) {<br>
- write32(Config->IsLE ? Loc : Loc - 2, Insn);<br>
+static void writeFromHalf16(uint8_t *loc, uint32_t insn) {<br>
+ write32(config->isLE ? loc : loc - 2, insn);<br>
}<br>
<br>
-static uint32_t readFromHalf16(const uint8_t *Loc) {<br>
- return read32(Config->IsLE ? Loc : Loc - 2);<br>
+static uint32_t readFromHalf16(const uint8_t *loc) {<br>
+ return read32(config->isLE ? loc : loc - 2);<br>
}<br>
<br>
PPC64::PPC64() {<br>
- GotRel = R_PPC64_GLOB_DAT;<br>
- NoneRel = R_PPC64_NONE;<br>
- PltRel = R_PPC64_JMP_SLOT;<br>
- RelativeRel = R_PPC64_RELATIVE;<br>
- IRelativeRel = R_PPC64_IRELATIVE;<br>
- SymbolicRel = R_PPC64_ADDR64;<br>
- PltEntrySize = 4;<br>
- GotBaseSymInGotPlt = false;<br>
- GotHeaderEntriesNum = 1;<br>
- GotPltHeaderEntriesNum = 2;<br>
- PltHeaderSize = 60;<br>
- NeedsThunks = true;<br>
+ gotRel = R_PPC64_GLOB_DAT;<br>
+ noneRel = R_PPC64_NONE;<br>
+ pltRel = R_PPC64_JMP_SLOT;<br>
+ relativeRel = R_PPC64_RELATIVE;<br>
+ iRelativeRel = R_PPC64_IRELATIVE;<br>
+ symbolicRel = R_PPC64_ADDR64;<br>
+ pltEntrySize = 4;<br>
+ gotBaseSymInGotPlt = false;<br>
+ gotHeaderEntriesNum = 1;<br>
+ gotPltHeaderEntriesNum = 2;<br>
+ pltHeaderSize = 60;<br>
+ needsThunks = true;<br>
<br>
- TlsModuleIndexRel = R_PPC64_DTPMOD64;<br>
- TlsOffsetRel = R_PPC64_DTPREL64;<br>
+ tlsModuleIndexRel = R_PPC64_DTPMOD64;<br>
+ tlsOffsetRel = R_PPC64_DTPREL64;<br>
<br>
- TlsGotRel = R_PPC64_TPREL64;<br>
+ tlsGotRel = R_PPC64_TPREL64;<br>
<br>
- NeedsMoreStackNonSplit = false;<br>
+ needsMoreStackNonSplit = false;<br>
<br>
// We need 64K pages (at least under glibc/Linux, the loader won't<br>
// set different permissions on a finer granularity than that).<br>
- DefaultMaxPageSize = 65536;<br>
+ defaultMaxPageSize = 65536;<br>
<br>
// The PPC64 ELF ABI v1 spec, says:<br>
//<br>
@@ -316,12 +316,12 @@ PPC64::PPC64() {<br>
//<br>
// And because the lowest non-zero 256M boundary is 0x10000000, PPC64 linkers<br>
// use 0x10000000 as the starting address.<br>
- DefaultImageBase = 0x10000000;<br>
+ defaultImageBase = 0x10000000;<br>
<br>
- write32(TrapInstr.data(), 0x7fe00008);<br>
+ write32(trapInstr.data(), 0x7fe00008);<br>
}<br>
<br>
-int PPC64::getTlsGdRelaxSkip(RelType Type) const {<br>
+int PPC64::getTlsGdRelaxSkip(RelType type) const {<br>
// A __tls_get_addr call instruction is marked with 2 relocations:<br>
//<br>
// R_PPC64_TLSGD / R_PPC64_TLSLD: marker relocation<br>
@@ -330,44 +330,44 @@ int PPC64::getTlsGdRelaxSkip(RelType Typ<br>
// After the relaxation we no longer call __tls_get_addr and should skip both<br>
// relocations to not create a false dependence on __tls_get_addr being<br>
// defined.<br>
- if (Type == R_PPC64_TLSGD || Type == R_PPC64_TLSLD)<br>
+ if (type == R_PPC64_TLSGD || type == R_PPC64_TLSLD)<br>
return 2;<br>
return 1;<br>
}<br>
<br>
-static uint32_t getEFlags(InputFile *File) {<br>
- if (Config->EKind == ELF64BEKind)<br>
- return cast<ObjFile<ELF64BE>>(File)->getObj().getHeader()->e_flags;<br>
- return cast<ObjFile<ELF64LE>>(File)->getObj().getHeader()->e_flags;<br>
+static uint32_t getEFlags(InputFile *file) {<br>
+ if (config->ekind == ELF64BEKind)<br>
+ return cast<ObjFile<ELF64BE>>(file)->getObj().getHeader()->e_flags;<br>
+ return cast<ObjFile<ELF64LE>>(file)->getObj().getHeader()->e_flags;<br>
}<br>
<br>
// This file implements v2 ABI. This function makes sure that all<br>
// object files have v2 or an unspecified version as an ABI version.<br>
uint32_t PPC64::calcEFlags() const {<br>
- for (InputFile *F : ObjectFiles) {<br>
- uint32_t Flag = getEFlags(F);<br>
- if (Flag == 1)<br>
- error(toString(F) + ": ABI version 1 is not supported");<br>
- else if (Flag > 2)<br>
- error(toString(F) + ": unrecognized e_flags: " + Twine(Flag));<br>
+ for (InputFile *f : objectFiles) {<br>
+ uint32_t flag = getEFlags(f);<br>
+ if (flag == 1)<br>
+ error(toString(f) + ": ABI version 1 is not supported");<br>
+ else if (flag > 2)<br>
+ error(toString(f) + ": unrecognized e_flags: " + Twine(flag));<br>
}<br>
return 2;<br>
}<br>
<br>
-void PPC64::relaxGot(uint8_t *Loc, RelType Type, uint64_t Val) const {<br>
- switch (Type) {<br>
+void PPC64::relaxGot(uint8_t *loc, RelType type, uint64_t val) const {<br>
+ switch (type) {<br>
case R_PPC64_TOC16_HA:<br>
// Convert "addis reg, 2, .LC0@toc@h" to "addis reg, 2, var@toc@h" or "nop".<br>
- relocateOne(Loc, Type, Val);<br>
+ relocateOne(loc, type, val);<br>
break;<br>
case R_PPC64_TOC16_LO_DS: {<br>
// Convert "ld reg, .LC0@toc@l(reg)" to "addi reg, reg, var@toc@l" or<br>
// "addi reg, 2, var@toc".<br>
- uint32_t Insn = readFromHalf16(Loc);<br>
- if (getPrimaryOpCode(Insn) != LD)<br>
+ uint32_t insn = readFromHalf16(loc);<br>
+ if (getPrimaryOpCode(insn) != LD)<br>
error("expected a 'ld' for got-indirect to toc-relative relaxing");<br>
- writeFromHalf16(Loc, (Insn & 0x03ffffff) | 0x38000000);<br>
- relocateOne(Loc, R_PPC64_TOC16_LO, Val);<br>
+ writeFromHalf16(loc, (insn & 0x03ffffff) | 0x38000000);<br>
+ relocateOne(loc, R_PPC64_TOC16_LO, val);<br>
break;<br>
}<br>
default:<br>
@@ -375,7 +375,7 @@ void PPC64::relaxGot(uint8_t *Loc, RelTy<br>
}<br>
}<br>
<br>
-void PPC64::relaxTlsGdToLe(uint8_t *Loc, RelType Type, uint64_t Val) const {<br>
+void PPC64::relaxTlsGdToLe(uint8_t *loc, RelType type, uint64_t val) const {<br>
// Reference: 3.7.4.2 of the 64-bit ELF V2 abi supplement.<br>
// The general dynamic code sequence for a global `x` will look like:<br>
// Instruction Relocation Symbol<br>
@@ -391,30 +391,30 @@ void PPC64::relaxTlsGdToLe(uint8_t *Loc,<br>
// bl __tls_get_addr(x@tlsgd) into nop<br>
// nop into addi r3, r3, x@tprel@l<br>
<br>
- switch (Type) {<br>
+ switch (type) {<br>
case R_PPC64_GOT_TLSGD16_HA:<br>
- writeFromHalf16(Loc, 0x60000000); // nop<br>
+ writeFromHalf16(loc, 0x60000000); // nop<br>
break;<br>
case R_PPC64_GOT_TLSGD16:<br>
case R_PPC64_GOT_TLSGD16_LO:<br>
- writeFromHalf16(Loc, 0x3c6d0000); // addis r3, r13<br>
- relocateOne(Loc, R_PPC64_TPREL16_HA, Val);<br>
+ writeFromHalf16(loc, 0x3c6d0000); // addis r3, r13<br>
+ relocateOne(loc, R_PPC64_TPREL16_HA, val);<br>
break;<br>
case R_PPC64_TLSGD:<br>
- write32(Loc, 0x60000000); // nop<br>
- write32(Loc + 4, 0x38630000); // addi r3, r3<br>
+ write32(loc, 0x60000000); // nop<br>
+ write32(loc + 4, 0x38630000); // addi r3, r3<br>
// Since we are relocating a half16 type relocation and Loc + 4 points to<br>
// the start of an instruction we need to advance the buffer by an extra<br>
// 2 bytes on BE.<br>
- relocateOne(Loc + 4 + (Config->EKind == ELF64BEKind ? 2 : 0),<br>
- R_PPC64_TPREL16_LO, Val);<br>
+ relocateOne(loc + 4 + (config->ekind == ELF64BEKind ? 2 : 0),<br>
+ R_PPC64_TPREL16_LO, val);<br>
break;<br>
default:<br>
llvm_unreachable("unsupported relocation for TLS GD to LE relaxation");<br>
}<br>
}<br>
<br>
-void PPC64::relaxTlsLdToLe(uint8_t *Loc, RelType Type, uint64_t Val) const {<br>
+void PPC64::relaxTlsLdToLe(uint8_t *loc, RelType type, uint64_t val) const {<br>
// Reference: 3.7.4.3 of the 64-bit ELF V2 abi supplement.<br>
// The local dynamic code sequence for a global `x` will look like:<br>
// Instruction Relocation Symbol<br>
@@ -430,16 +430,16 @@ void PPC64::relaxTlsLdToLe(uint8_t *Loc,<br>
// bl __tls_get_addr(x@tlsgd) into nop<br>
// nop into addi r3, r3, 4096<br>
<br>
- switch (Type) {<br>
+ switch (type) {<br>
case R_PPC64_GOT_TLSLD16_HA:<br>
- writeFromHalf16(Loc, 0x60000000); // nop<br>
+ writeFromHalf16(loc, 0x60000000); // nop<br>
break;<br>
case R_PPC64_GOT_TLSLD16_LO:<br>
- writeFromHalf16(Loc, 0x3c6d0000); // addis r3, r13, 0<br>
+ writeFromHalf16(loc, 0x3c6d0000); // addis r3, r13, 0<br>
break;<br>
case R_PPC64_TLSLD:<br>
- write32(Loc, 0x60000000); // nop<br>
- write32(Loc + 4, 0x38631000); // addi r3, r3, 4096<br>
+ write32(loc, 0x60000000); // nop<br>
+ write32(loc + 4, 0x38631000); // addi r3, r3, 4096<br>
break;<br>
case R_PPC64_DTPREL16:<br>
case R_PPC64_DTPREL16_HA:<br>
@@ -447,15 +447,15 @@ void PPC64::relaxTlsLdToLe(uint8_t *Loc,<br>
case R_PPC64_DTPREL16_DS:<br>
case R_PPC64_DTPREL16_LO:<br>
case R_PPC64_DTPREL16_LO_DS:<br>
- relocateOne(Loc, Type, Val);<br>
+ relocateOne(loc, type, val);<br>
break;<br>
default:<br>
llvm_unreachable("unsupported relocation for TLS LD to LE relaxation");<br>
}<br>
}<br>
<br>
-unsigned elf::getPPCDFormOp(unsigned SecondaryOp) {<br>
- switch (SecondaryOp) {<br>
+unsigned elf::getPPCDFormOp(unsigned secondaryOp) {<br>
+ switch (secondaryOp) {<br>
case LBZX:<br>
return LBZ;<br>
case LHZX:<br>
@@ -479,7 +479,7 @@ unsigned elf::getPPCDFormOp(unsigned Sec<br>
}<br>
}<br>
<br>
-void PPC64::relaxTlsIeToLe(uint8_t *Loc, RelType Type, uint64_t Val) const {<br>
+void PPC64::relaxTlsIeToLe(uint8_t *loc, RelType type, uint64_t val) const {<br>
// The initial exec code sequence for a global `x` will look like:<br>
// Instruction Relocation Symbol<br>
// addis r9, r2, x@got@tprel@ha R_PPC64_GOT_TPREL16_HA x<br>
@@ -499,28 +499,28 @@ void PPC64::relaxTlsIeToLe(uint8_t *Loc,<br>
// instruction, if we are accessing memory it will use any of the X-form<br>
// indexed load or store instructions.<br>
<br>
- unsigned Offset = (Config->EKind == ELF64BEKind) ? 2 : 0;<br>
- switch (Type) {<br>
+ unsigned offset = (config->ekind == ELF64BEKind) ? 2 : 0;<br>
+ switch (type) {<br>
case R_PPC64_GOT_TPREL16_HA:<br>
- write32(Loc - Offset, 0x60000000); // nop<br>
+ write32(loc - offset, 0x60000000); // nop<br>
break;<br>
case R_PPC64_GOT_TPREL16_LO_DS:<br>
case R_PPC64_GOT_TPREL16_DS: {<br>
- uint32_t RegNo = read32(Loc - Offset) & 0x03E00000; // bits 6-10<br>
- write32(Loc - Offset, 0x3C0D0000 | RegNo); // addis RegNo, r13<br>
- relocateOne(Loc, R_PPC64_TPREL16_HA, Val);<br>
+ uint32_t regNo = read32(loc - offset) & 0x03E00000; // bits 6-10<br>
+ write32(loc - offset, 0x3C0D0000 | regNo); // addis RegNo, r13<br>
+ relocateOne(loc, R_PPC64_TPREL16_HA, val);<br>
break;<br>
}<br>
case R_PPC64_TLS: {<br>
- uint32_t PrimaryOp = getPrimaryOpCode(read32(Loc));<br>
- if (PrimaryOp != 31)<br>
+ uint32_t primaryOp = getPrimaryOpCode(read32(loc));<br>
+ if (primaryOp != 31)<br>
error("unrecognized instruction for IE to LE R_PPC64_TLS");<br>
- uint32_t SecondaryOp = (read32(Loc) & 0x000007FE) >> 1; // bits 21-30<br>
- uint32_t DFormOp = getPPCDFormOp(SecondaryOp);<br>
- if (DFormOp == 0)<br>
+ uint32_t secondaryOp = (read32(loc) & 0x000007FE) >> 1; // bits 21-30<br>
+ uint32_t dFormOp = getPPCDFormOp(secondaryOp);<br>
+ if (dFormOp == 0)<br>
error("unrecognized instruction for IE to LE R_PPC64_TLS");<br>
- write32(Loc, ((DFormOp << 26) | (read32(Loc) & 0x03FFFFFF)));<br>
- relocateOne(Loc + Offset, R_PPC64_TPREL16_LO, Val);<br>
+ write32(loc, ((dFormOp << 26) | (read32(loc) & 0x03FFFFFF)));<br>
+ relocateOne(loc + offset, R_PPC64_TPREL16_LO, val);<br>
break;<br>
}<br>
default:<br>
@@ -529,9 +529,9 @@ void PPC64::relaxTlsIeToLe(uint8_t *Loc,<br>
}<br>
}<br>
<br>
-RelExpr PPC64::getRelExpr(RelType Type, const Symbol &S,<br>
- const uint8_t *Loc) const {<br>
- switch (Type) {<br>
+RelExpr PPC64::getRelExpr(RelType type, const Symbol &s,<br>
+ const uint8_t *loc) const {<br>
+ switch (type) {<br>
case R_PPC64_GOT16:<br>
case R_PPC64_GOT16_DS:<br>
case R_PPC64_GOT16_HA:<br>
@@ -546,7 +546,7 @@ RelExpr PPC64::getRelExpr(RelType Type,<br>
return R_GOTREL;<br>
case R_PPC64_TOC16_HA:<br>
case R_PPC64_TOC16_LO_DS:<br>
- return Config->TocOptimize ? R_PPC64_RELAX_TOC : R_GOTREL;<br>
+ return config->tocOptimize ? R_PPC64_RELAX_TOC : R_GOTREL;<br>
case R_PPC64_TOC:<br>
return R_PPC64_TOCBASE;<br>
case R_PPC64_REL14:<br>
@@ -611,121 +611,121 @@ RelExpr PPC64::getRelExpr(RelType Type,<br>
}<br>
}<br>
<br>
-RelType PPC64::getDynRel(RelType Type) const {<br>
- if (Type == R_PPC64_ADDR64 || Type == R_PPC64_TOC)<br>
+RelType PPC64::getDynRel(RelType type) const {<br>
+ if (type == R_PPC64_ADDR64 || type == R_PPC64_TOC)<br>
return R_PPC64_ADDR64;<br>
return R_PPC64_NONE;<br>
}<br>
<br>
-void PPC64::writeGotHeader(uint8_t *Buf) const {<br>
- write64(Buf, getPPC64TocBase());<br>
+void PPC64::writeGotHeader(uint8_t *buf) const {<br>
+ write64(buf, getPPC64TocBase());<br>
}<br>
<br>
-void PPC64::writePltHeader(uint8_t *Buf) const {<br>
+void PPC64::writePltHeader(uint8_t *buf) const {<br>
// The generic resolver stub goes first.<br>
- write32(Buf + 0, 0x7c0802a6); // mflr r0<br>
- write32(Buf + 4, 0x429f0005); // bcl 20,4*cr7+so,8 <_glink+0x8><br>
- write32(Buf + 8, 0x7d6802a6); // mflr r11<br>
- write32(Buf + 12, 0x7c0803a6); // mtlr r0<br>
- write32(Buf + 16, 0x7d8b6050); // subf r12, r11, r12<br>
- write32(Buf + 20, 0x380cffcc); // subi r0,r12,52<br>
- write32(Buf + 24, 0x7800f082); // srdi r0,r0,62,2<br>
- write32(Buf + 28, 0xe98b002c); // ld r12,44(r11)<br>
- write32(Buf + 32, 0x7d6c5a14); // add r11,r12,r11<br>
- write32(Buf + 36, 0xe98b0000); // ld r12,0(r11)<br>
- write32(Buf + 40, 0xe96b0008); // ld r11,8(r11)<br>
- write32(Buf + 44, 0x7d8903a6); // mtctr r12<br>
- write32(Buf + 48, 0x4e800420); // bctr<br>
+ write32(buf + 0, 0x7c0802a6); // mflr r0<br>
+ write32(buf + 4, 0x429f0005); // bcl 20,4*cr7+so,8 <_glink+0x8><br>
+ write32(buf + 8, 0x7d6802a6); // mflr r11<br>
+ write32(buf + 12, 0x7c0803a6); // mtlr r0<br>
+ write32(buf + 16, 0x7d8b6050); // subf r12, r11, r12<br>
+ write32(buf + 20, 0x380cffcc); // subi r0,r12,52<br>
+ write32(buf + 24, 0x7800f082); // srdi r0,r0,62,2<br>
+ write32(buf + 28, 0xe98b002c); // ld r12,44(r11)<br>
+ write32(buf + 32, 0x7d6c5a14); // add r11,r12,r11<br>
+ write32(buf + 36, 0xe98b0000); // ld r12,0(r11)<br>
+ write32(buf + 40, 0xe96b0008); // ld r11,8(r11)<br>
+ write32(buf + 44, 0x7d8903a6); // mtctr r12<br>
+ write32(buf + 48, 0x4e800420); // bctr<br>
<br>
// The 'bcl' instruction will set the link register to the address of the<br>
// following instruction ('mflr r11'). Here we store the offset from that<br>
// instruction to the first entry in the GotPlt section.<br>
- int64_t GotPltOffset = In.GotPlt->getVA() - (In.Plt->getVA() + 8);<br>
- write64(Buf + 52, GotPltOffset);<br>
+ int64_t gotPltOffset = in.gotPlt->getVA() - (in.plt->getVA() + 8);<br>
+ write64(buf + 52, gotPltOffset);<br>
}<br>
<br>
-void PPC64::writePlt(uint8_t *Buf, uint64_t GotPltEntryAddr,<br>
- uint64_t PltEntryAddr, int32_t Index,<br>
- unsigned RelOff) const {<br>
- int32_t Offset = PltHeaderSize + Index * PltEntrySize;<br>
+void PPC64::writePlt(uint8_t *buf, uint64_t gotPltEntryAddr,<br>
+ uint64_t pltEntryAddr, int32_t index,<br>
+ unsigned relOff) const {<br>
+ int32_t offset = pltHeaderSize + index * pltEntrySize;<br>
// bl __glink_PLTresolve<br>
- write32(Buf, 0x48000000 | ((-Offset) & 0x03FFFFFc));<br>
+ write32(buf, 0x48000000 | ((-offset) & 0x03FFFFFc));<br>
}<br>
<br>
-static std::pair<RelType, uint64_t> toAddr16Rel(RelType Type, uint64_t Val) {<br>
+static std::pair<RelType, uint64_t> toAddr16Rel(RelType type, uint64_t val) {<br>
// Relocations relative to the toc-base need to be adjusted by the Toc offset.<br>
- uint64_t TocBiasedVal = Val - PPC64TocOffset;<br>
+ uint64_t tocBiasedVal = val - ppc64TocOffset;<br>
// Relocations relative to dtv[dtpmod] need to be adjusted by the DTP offset.<br>
- uint64_t DTPBiasedVal = Val - DynamicThreadPointerOffset;<br>
+ uint64_t dtpBiasedVal = val - dynamicThreadPointerOffset;<br>
<br>
- switch (Type) {<br>
+ switch (type) {<br>
// TOC biased relocation.<br>
case R_PPC64_GOT16:<br>
case R_PPC64_GOT_TLSGD16:<br>
case R_PPC64_GOT_TLSLD16:<br>
case R_PPC64_TOC16:<br>
- return {R_PPC64_ADDR16, TocBiasedVal};<br>
+ return {R_PPC64_ADDR16, tocBiasedVal};<br>
case R_PPC64_GOT16_DS:<br>
case R_PPC64_TOC16_DS:<br>
case R_PPC64_GOT_TPREL16_DS:<br>
case R_PPC64_GOT_DTPREL16_DS:<br>
- return {R_PPC64_ADDR16_DS, TocBiasedVal};<br>
+ return {R_PPC64_ADDR16_DS, tocBiasedVal};<br>
case R_PPC64_GOT16_HA:<br>
case R_PPC64_GOT_TLSGD16_HA:<br>
case R_PPC64_GOT_TLSLD16_HA:<br>
case R_PPC64_GOT_TPREL16_HA:<br>
case R_PPC64_GOT_DTPREL16_HA:<br>
case R_PPC64_TOC16_HA:<br>
- return {R_PPC64_ADDR16_HA, TocBiasedVal};<br>
+ return {R_PPC64_ADDR16_HA, tocBiasedVal};<br>
case R_PPC64_GOT16_HI:<br>
case R_PPC64_GOT_TLSGD16_HI:<br>
case R_PPC64_GOT_TLSLD16_HI:<br>
case R_PPC64_GOT_TPREL16_HI:<br>
case R_PPC64_GOT_DTPREL16_HI:<br>
case R_PPC64_TOC16_HI:<br>
- return {R_PPC64_ADDR16_HI, TocBiasedVal};<br>
+ return {R_PPC64_ADDR16_HI, tocBiasedVal};<br>
case R_PPC64_GOT16_LO:<br>
case R_PPC64_GOT_TLSGD16_LO:<br>
case R_PPC64_GOT_TLSLD16_LO:<br>
case R_PPC64_TOC16_LO:<br>
- return {R_PPC64_ADDR16_LO, TocBiasedVal};<br>
+ return {R_PPC64_ADDR16_LO, tocBiasedVal};<br>
case R_PPC64_GOT16_LO_DS:<br>
case R_PPC64_TOC16_LO_DS:<br>
case R_PPC64_GOT_TPREL16_LO_DS:<br>
case R_PPC64_GOT_DTPREL16_LO_DS:<br>
- return {R_PPC64_ADDR16_LO_DS, TocBiasedVal};<br>
+ return {R_PPC64_ADDR16_LO_DS, tocBiasedVal};<br>
<br>
// Dynamic Thread pointer biased relocation types.<br>
case R_PPC64_DTPREL16:<br>
- return {R_PPC64_ADDR16, DTPBiasedVal};<br>
+ return {R_PPC64_ADDR16, dtpBiasedVal};<br>
case R_PPC64_DTPREL16_DS:<br>
- return {R_PPC64_ADDR16_DS, DTPBiasedVal};<br>
+ return {R_PPC64_ADDR16_DS, dtpBiasedVal};<br>
case R_PPC64_DTPREL16_HA:<br>
- return {R_PPC64_ADDR16_HA, DTPBiasedVal};<br>
+ return {R_PPC64_ADDR16_HA, dtpBiasedVal};<br>
case R_PPC64_DTPREL16_HI:<br>
- return {R_PPC64_ADDR16_HI, DTPBiasedVal};<br>
+ return {R_PPC64_ADDR16_HI, dtpBiasedVal};<br>
case R_PPC64_DTPREL16_HIGHER:<br>
- return {R_PPC64_ADDR16_HIGHER, DTPBiasedVal};<br>
+ return {R_PPC64_ADDR16_HIGHER, dtpBiasedVal};<br>
case R_PPC64_DTPREL16_HIGHERA:<br>
- return {R_PPC64_ADDR16_HIGHERA, DTPBiasedVal};<br>
+ return {R_PPC64_ADDR16_HIGHERA, dtpBiasedVal};<br>
case R_PPC64_DTPREL16_HIGHEST:<br>
- return {R_PPC64_ADDR16_HIGHEST, DTPBiasedVal};<br>
+ return {R_PPC64_ADDR16_HIGHEST, dtpBiasedVal};<br>
case R_PPC64_DTPREL16_HIGHESTA:<br>
- return {R_PPC64_ADDR16_HIGHESTA, DTPBiasedVal};<br>
+ return {R_PPC64_ADDR16_HIGHESTA, dtpBiasedVal};<br>
case R_PPC64_DTPREL16_LO:<br>
- return {R_PPC64_ADDR16_LO, DTPBiasedVal};<br>
+ return {R_PPC64_ADDR16_LO, dtpBiasedVal};<br>
case R_PPC64_DTPREL16_LO_DS:<br>
- return {R_PPC64_ADDR16_LO_DS, DTPBiasedVal};<br>
+ return {R_PPC64_ADDR16_LO_DS, dtpBiasedVal};<br>
case R_PPC64_DTPREL64:<br>
- return {R_PPC64_ADDR64, DTPBiasedVal};<br>
+ return {R_PPC64_ADDR64, dtpBiasedVal};<br>
<br>
default:<br>
- return {Type, Val};<br>
+ return {type, val};<br>
}<br>
}<br>
<br>
-static bool isTocOptType(RelType Type) {<br>
- switch (Type) {<br>
+static bool isTocOptType(RelType type) {<br>
+ switch (type) {<br>
case R_PPC64_GOT16_HA:<br>
case R_PPC64_GOT16_LO_DS:<br>
case R_PPC64_TOC16_HA:<br>
@@ -737,69 +737,69 @@ static bool isTocOptType(RelType Type) {<br>
}<br>
}<br>
<br>
-void PPC64::relocateOne(uint8_t *Loc, RelType Type, uint64_t Val) const {<br>
+void PPC64::relocateOne(uint8_t *loc, RelType type, uint64_t val) const {<br>
// We need to save the original relocation type to use in diagnostics, and<br>
// use the original type to determine if we should toc-optimize the<br>
// instructions being relocated.<br>
- RelType OriginalType = Type;<br>
- bool ShouldTocOptimize = isTocOptType(Type);<br>
+ RelType originalType = type;<br>
+ bool shouldTocOptimize = isTocOptType(type);<br>
// For dynamic thread pointer relative, toc-relative, and got-indirect<br>
// relocations, proceed in terms of the corresponding ADDR16 relocation type.<br>
- std::tie(Type, Val) = toAddr16Rel(Type, Val);<br>
+ std::tie(type, val) = toAddr16Rel(type, val);<br>
<br>
- switch (Type) {<br>
+ switch (type) {<br>
case R_PPC64_ADDR14: {<br>
- checkAlignment(Loc, Val, 4, Type);<br>
+ checkAlignment(loc, val, 4, type);<br>
// Preserve the AA/LK bits in the branch instruction<br>
- uint8_t AALK = Loc[3];<br>
- write16(Loc + 2, (AALK & 3) | (Val & 0xfffc));<br>
+ uint8_t aalk = loc[3];<br>
+ write16(loc + 2, (aalk & 3) | (val & 0xfffc));<br>
break;<br>
}<br>
case R_PPC64_ADDR16:<br>
- checkIntUInt(Loc, Val, 16, OriginalType);<br>
- write16(Loc, Val);<br>
+ checkIntUInt(loc, val, 16, originalType);<br>
+ write16(loc, val);<br>
break;<br>
case R_PPC64_ADDR32:<br>
- checkIntUInt(Loc, Val, 32, OriginalType);<br>
- write32(Loc, Val);<br>
+ checkIntUInt(loc, val, 32, originalType);<br>
+ write32(loc, val);<br>
break;<br>
case R_PPC64_ADDR16_DS:<br>
case R_PPC64_TPREL16_DS: {<br>
- checkInt(Loc, Val, 16, OriginalType);<br>
+ checkInt(loc, val, 16, originalType);<br>
// DQ-form instructions use bits 28-31 as part of the instruction encoding<br>
// DS-form instructions only use bits 30-31.<br>
- uint16_t Mask = isDQFormInstruction(readFromHalf16(Loc)) ? 0xf : 0x3;<br>
- checkAlignment(Loc, lo(Val), Mask + 1, OriginalType);<br>
- write16(Loc, (read16(Loc) & Mask) | lo(Val));<br>
+ uint16_t mask = isDQFormInstruction(readFromHalf16(loc)) ? 0xf : 0x3;<br>
+ checkAlignment(loc, lo(val), mask + 1, originalType);<br>
+ write16(loc, (read16(loc) & mask) | lo(val));<br>
} break;<br>
case R_PPC64_ADDR16_HA:<br>
case R_PPC64_REL16_HA:<br>
case R_PPC64_TPREL16_HA:<br>
- if (Config->TocOptimize && ShouldTocOptimize && ha(Val) == 0)<br>
- writeFromHalf16(Loc, 0x60000000);<br>
+ if (config->tocOptimize && shouldTocOptimize && ha(val) == 0)<br>
+ writeFromHalf16(loc, 0x60000000);<br>
else<br>
- write16(Loc, ha(Val));<br>
+ write16(loc, ha(val));<br>
break;<br>
case R_PPC64_ADDR16_HI:<br>
case R_PPC64_REL16_HI:<br>
case R_PPC64_TPREL16_HI:<br>
- write16(Loc, hi(Val));<br>
+ write16(loc, hi(val));<br>
break;<br>
case R_PPC64_ADDR16_HIGHER:<br>
case R_PPC64_TPREL16_HIGHER:<br>
- write16(Loc, higher(Val));<br>
+ write16(loc, higher(val));<br>
break;<br>
case R_PPC64_ADDR16_HIGHERA:<br>
case R_PPC64_TPREL16_HIGHERA:<br>
- write16(Loc, highera(Val));<br>
+ write16(loc, highera(val));<br>
break;<br>
case R_PPC64_ADDR16_HIGHEST:<br>
case R_PPC64_TPREL16_HIGHEST:<br>
- write16(Loc, highest(Val));<br>
+ write16(loc, highest(val));<br>
break;<br>
case R_PPC64_ADDR16_HIGHESTA:<br>
case R_PPC64_TPREL16_HIGHESTA:<br>
- write16(Loc, highesta(Val));<br>
+ write16(loc, highesta(val));<br>
break;<br>
case R_PPC64_ADDR16_LO:<br>
case R_PPC64_REL16_LO:<br>
@@ -807,93 +807,93 @@ void PPC64::relocateOne(uint8_t *Loc, Re<br>
// When the high-adjusted part of a toc relocation evalutes to 0, it is<br>
// changed into a nop. The lo part then needs to be updated to use the<br>
// toc-pointer register r2, as the base register.<br>
- if (Config->TocOptimize && ShouldTocOptimize && ha(Val) == 0) {<br>
- uint32_t Insn = readFromHalf16(Loc);<br>
- if (isInstructionUpdateForm(Insn))<br>
- error(getErrorLocation(Loc) +<br>
+ if (config->tocOptimize && shouldTocOptimize && ha(val) == 0) {<br>
+ uint32_t insn = readFromHalf16(loc);<br>
+ if (isInstructionUpdateForm(insn))<br>
+ error(getErrorLocation(loc) +<br>
"can't toc-optimize an update instruction: 0x" +<br>
- utohexstr(Insn));<br>
- writeFromHalf16(Loc, (Insn & 0xffe00000) | 0x00020000 | lo(Val));<br>
+ utohexstr(insn));<br>
+ writeFromHalf16(loc, (insn & 0xffe00000) | 0x00020000 | lo(val));<br>
} else {<br>
- write16(Loc, lo(Val));<br>
+ write16(loc, lo(val));<br>
}<br>
break;<br>
case R_PPC64_ADDR16_LO_DS:<br>
case R_PPC64_TPREL16_LO_DS: {<br>
// DQ-form instructions use bits 28-31 as part of the instruction encoding<br>
// DS-form instructions only use bits 30-31.<br>
- uint32_t Insn = readFromHalf16(Loc);<br>
- uint16_t Mask = isDQFormInstruction(Insn) ? 0xf : 0x3;<br>
- checkAlignment(Loc, lo(Val), Mask + 1, OriginalType);<br>
- if (Config->TocOptimize && ShouldTocOptimize && ha(Val) == 0) {<br>
+ uint32_t insn = readFromHalf16(loc);<br>
+ uint16_t mask = isDQFormInstruction(insn) ? 0xf : 0x3;<br>
+ checkAlignment(loc, lo(val), mask + 1, originalType);<br>
+ if (config->tocOptimize && shouldTocOptimize && ha(val) == 0) {<br>
// When the high-adjusted part of a toc relocation evalutes to 0, it is<br>
// changed into a nop. The lo part then needs to be updated to use the toc<br>
// pointer register r2, as the base register.<br>
- if (isInstructionUpdateForm(Insn))<br>
- error(getErrorLocation(Loc) +<br>
+ if (isInstructionUpdateForm(insn))<br>
+ error(getErrorLocation(loc) +<br>
"Can't toc-optimize an update instruction: 0x" +<br>
- Twine::utohexstr(Insn));<br>
- Insn &= 0xffe00000 | Mask;<br>
- writeFromHalf16(Loc, Insn | 0x00020000 | lo(Val));<br>
+ Twine::utohexstr(insn));<br>
+ insn &= 0xffe00000 | mask;<br>
+ writeFromHalf16(loc, insn | 0x00020000 | lo(val));<br>
} else {<br>
- write16(Loc, (read16(Loc) & Mask) | lo(Val));<br>
+ write16(loc, (read16(loc) & mask) | lo(val));<br>
}<br>
} break;<br>
case R_PPC64_TPREL16:<br>
- checkInt(Loc, Val, 16, OriginalType);<br>
- write16(Loc, Val);<br>
+ checkInt(loc, val, 16, originalType);<br>
+ write16(loc, val);<br>
break;<br>
case R_PPC64_REL32:<br>
- checkInt(Loc, Val, 32, Type);<br>
- write32(Loc, Val);<br>
+ checkInt(loc, val, 32, type);<br>
+ write32(loc, val);<br>
break;<br>
case R_PPC64_ADDR64:<br>
case R_PPC64_REL64:<br>
case R_PPC64_TOC:<br>
- write64(Loc, Val);<br>
+ write64(loc, val);<br>
break;<br>
case R_PPC64_REL14: {<br>
- uint32_t Mask = 0x0000FFFC;<br>
- checkInt(Loc, Val, 16, Type);<br>
- checkAlignment(Loc, Val, 4, Type);<br>
- write32(Loc, (read32(Loc) & ~Mask) | (Val & Mask));<br>
+ uint32_t mask = 0x0000FFFC;<br>
+ checkInt(loc, val, 16, type);<br>
+ checkAlignment(loc, val, 4, type);<br>
+ write32(loc, (read32(loc) & ~mask) | (val & mask));<br>
break;<br>
}<br>
case R_PPC64_REL24: {<br>
- uint32_t Mask = 0x03FFFFFC;<br>
- checkInt(Loc, Val, 26, Type);<br>
- checkAlignment(Loc, Val, 4, Type);<br>
- write32(Loc, (read32(Loc) & ~Mask) | (Val & Mask));<br>
+ uint32_t mask = 0x03FFFFFC;<br>
+ checkInt(loc, val, 26, type);<br>
+ checkAlignment(loc, val, 4, type);<br>
+ write32(loc, (read32(loc) & ~mask) | (val & mask));<br>
break;<br>
}<br>
case R_PPC64_DTPREL64:<br>
- write64(Loc, Val - DynamicThreadPointerOffset);<br>
+ write64(loc, val - dynamicThreadPointerOffset);<br>
break;<br>
default:<br>
- error(getErrorLocation(Loc) + "unrecognized relocation " + toString(Type));<br>
+ error(getErrorLocation(loc) + "unrecognized relocation " + toString(type));<br>
}<br>
}<br>
<br>
-bool PPC64::needsThunk(RelExpr Expr, RelType Type, const InputFile *File,<br>
- uint64_t BranchAddr, const Symbol &S) const {<br>
- if (Type != R_PPC64_REL14 && Type != R_PPC64_REL24)<br>
+bool PPC64::needsThunk(RelExpr expr, RelType type, const InputFile *file,<br>
+ uint64_t branchAddr, const Symbol &s) const {<br>
+ if (type != R_PPC64_REL14 && type != R_PPC64_REL24)<br>
return false;<br>
<br>
// If a function is in the Plt it needs to be called with a call-stub.<br>
- if (S.isInPlt())<br>
+ if (s.isInPlt())<br>
return true;<br>
<br>
// If a symbol is a weak undefined and we are compiling an executable<br>
// it doesn't need a range-extending thunk since it can't be called.<br>
- if (S.isUndefWeak() && !Config->Shared)<br>
+ if (s.isUndefWeak() && !config->shared)<br>
return false;<br>
<br>
// If the offset exceeds the range of the branch type then it will need<br>
// a range-extending thunk.<br>
// See the comment in getRelocTargetVA() about R_PPC64_CALL.<br>
- return !inBranchRange(Type, BranchAddr,<br>
- S.getVA() +<br>
- getPPC64GlobalEntryToLocalEntryOffset(S.StOther));<br>
+ return !inBranchRange(type, branchAddr,<br>
+ s.getVA() +<br>
+ getPPC64GlobalEntryToLocalEntryOffset(s.stOther));<br>
}<br>
<br>
uint32_t PPC64::getThunkSectionSpacing() const {<br>
@@ -904,22 +904,22 @@ uint32_t PPC64::getThunkSectionSpacing()<br>
return 0x2000000;<br>
}<br>
<br>
-bool PPC64::inBranchRange(RelType Type, uint64_t Src, uint64_t Dst) const {<br>
- int64_t Offset = Dst - Src;<br>
- if (Type == R_PPC64_REL14)<br>
- return isInt<16>(Offset);<br>
- if (Type == R_PPC64_REL24)<br>
- return isInt<26>(Offset);<br>
+bool PPC64::inBranchRange(RelType type, uint64_t src, uint64_t dst) const {<br>
+ int64_t offset = dst - src;<br>
+ if (type == R_PPC64_REL14)<br>
+ return isInt<16>(offset);<br>
+ if (type == R_PPC64_REL24)<br>
+ return isInt<26>(offset);<br>
llvm_unreachable("unsupported relocation type used in branch");<br>
}<br>
<br>
-RelExpr PPC64::adjustRelaxExpr(RelType Type, const uint8_t *Data,<br>
- RelExpr Expr) const {<br>
- if (Expr == R_RELAX_TLS_GD_TO_IE)<br>
+RelExpr PPC64::adjustRelaxExpr(RelType type, const uint8_t *data,<br>
+ RelExpr expr) const {<br>
+ if (expr == R_RELAX_TLS_GD_TO_IE)<br>
return R_RELAX_TLS_GD_TO_IE_GOT_OFF;<br>
- if (Expr == R_RELAX_TLS_LD_TO_LE)<br>
+ if (expr == R_RELAX_TLS_LD_TO_LE)<br>
return R_RELAX_TLS_LD_TO_LE_ABS;<br>
- return Expr;<br>
+ return expr;<br>
}<br>
<br>
// Reference: 3.7.4.1 of the 64-bit ELF V2 abi supplement.<br>
@@ -939,24 +939,24 @@ RelExpr PPC64::adjustRelaxExpr(RelType T<br>
// thread pointer.<br>
// Since the nop must directly follow the call, the R_PPC64_TLSGD relocation is<br>
// used as the relaxation hint for both steps 2 and 3.<br>
-void PPC64::relaxTlsGdToIe(uint8_t *Loc, RelType Type, uint64_t Val) const {<br>
- switch (Type) {<br>
+void PPC64::relaxTlsGdToIe(uint8_t *loc, RelType type, uint64_t val) const {<br>
+ switch (type) {<br>
case R_PPC64_GOT_TLSGD16_HA:<br>
// This is relaxed from addis rT, r2, sym@got@tlsgd@ha to<br>
// addis rT, r2, sym@got@tprel@ha.<br>
- relocateOne(Loc, R_PPC64_GOT_TPREL16_HA, Val);<br>
+ relocateOne(loc, R_PPC64_GOT_TPREL16_HA, val);<br>
return;<br>
case R_PPC64_GOT_TLSGD16_LO: {<br>
// Relax from addi r3, rA, sym@got@tlsgd@l to<br>
// ld r3, sym@got@tprel@l(rA)<br>
- uint32_t RA = (readFromHalf16(Loc) & (0x1f << 16));<br>
- writeFromHalf16(Loc, 0xe8600000 | RA);<br>
- relocateOne(Loc, R_PPC64_GOT_TPREL16_LO_DS, Val);<br>
+ uint32_t ra = (readFromHalf16(loc) & (0x1f << 16));<br>
+ writeFromHalf16(loc, 0xe8600000 | ra);<br>
+ relocateOne(loc, R_PPC64_GOT_TPREL16_LO_DS, val);<br>
return;<br>
}<br>
case R_PPC64_TLSGD:<br>
- write32(Loc, 0x60000000); // bl __tls_get_addr(sym@tlsgd) --> nop<br>
- write32(Loc + 4, 0x7c636A14); // nop --> add r3, r3, r13<br>
+ write32(loc, 0x60000000); // bl __tls_get_addr(sym@tlsgd) --> nop<br>
+ write32(loc + 4, 0x7c636A14); // nop --> add r3, r3, r13<br>
return;<br>
default:<br>
llvm_unreachable("unsupported relocation for TLS GD to IE relaxation");<br>
@@ -991,86 +991,86 @@ void PPC64::relaxTlsGdToIe(uint8_t *Loc,<br>
// pair by split-stack-size-adjust.<br>
// addis r12, r1, ha(-stack-frame size - split-stack-adjust-size)<br>
// addi r12, r12, l(-stack-frame size - split-stack-adjust-size)<br>
-bool PPC64::adjustPrologueForCrossSplitStack(uint8_t *Loc, uint8_t *End,<br>
- uint8_t StOther) const {<br>
+bool PPC64::adjustPrologueForCrossSplitStack(uint8_t *loc, uint8_t *end,<br>
+ uint8_t stOther) const {<br>
// If the caller has a global entry point adjust the buffer past it. The start<br>
// of the split-stack prologue will be at the local entry point.<br>
- Loc += getPPC64GlobalEntryToLocalEntryOffset(StOther);<br>
+ loc += getPPC64GlobalEntryToLocalEntryOffset(stOther);<br>
<br>
// At the very least we expect to see a load of some split-stack data from the<br>
// tcb, and 2 instructions that calculate the ending stack address this<br>
// function will require. If there is not enough room for at least 3<br>
// instructions it can't be a split-stack prologue.<br>
- if (Loc + 12 >= End)<br>
+ if (loc + 12 >= end)<br>
return false;<br>
<br>
// First instruction must be `ld r0, -0x7000-64(r13)`<br>
- if (read32(Loc) != 0xe80d8fc0)<br>
+ if (read32(loc) != 0xe80d8fc0)<br>
return false;<br>
<br>
- int16_t HiImm = 0;<br>
- int16_t LoImm = 0;<br>
+ int16_t hiImm = 0;<br>
+ int16_t loImm = 0;<br>
// First instruction can be either an addis if the frame size is larger then<br>
// 32K, or an addi if the size is less then 32K.<br>
- int32_t FirstInstr = read32(Loc + 4);<br>
- if (getPrimaryOpCode(FirstInstr) == 15) {<br>
- HiImm = FirstInstr & 0xFFFF;<br>
- } else if (getPrimaryOpCode(FirstInstr) == 14) {<br>
- LoImm = FirstInstr & 0xFFFF;<br>
+ int32_t firstInstr = read32(loc + 4);<br>
+ if (getPrimaryOpCode(firstInstr) == 15) {<br>
+ hiImm = firstInstr & 0xFFFF;<br>
+ } else if (getPrimaryOpCode(firstInstr) == 14) {<br>
+ loImm = firstInstr & 0xFFFF;<br>
} else {<br>
return false;<br>
}<br>
<br>
// Second instruction is either an addi or a nop. If the first instruction was<br>
// an addi then LoImm is set and the second instruction must be a nop.<br>
- uint32_t SecondInstr = read32(Loc + 8);<br>
- if (!LoImm && getPrimaryOpCode(SecondInstr) == 14) {<br>
- LoImm = SecondInstr & 0xFFFF;<br>
- } else if (SecondInstr != 0x60000000) {<br>
+ uint32_t secondInstr = read32(loc + 8);<br>
+ if (!loImm && getPrimaryOpCode(secondInstr) == 14) {<br>
+ loImm = secondInstr & 0xFFFF;<br>
+ } else if (secondInstr != 0x60000000) {<br>
return false;<br>
}<br>
<br>
// The register operands of the first instruction should be the stack-pointer<br>
// (r1) as the input (RA) and r12 as the output (RT). If the second<br>
// instruction is not a nop, then it should use r12 as both input and output.<br>
- auto CheckRegOperands = [](uint32_t Instr, uint8_t ExpectedRT,<br>
- uint8_t ExpectedRA) {<br>
- return ((Instr & 0x3E00000) >> 21 == ExpectedRT) &&<br>
- ((Instr & 0x1F0000) >> 16 == ExpectedRA);<br>
+ auto checkRegOperands = [](uint32_t instr, uint8_t expectedRT,<br>
+ uint8_t expectedRA) {<br>
+ return ((instr & 0x3E00000) >> 21 == expectedRT) &&<br>
+ ((instr & 0x1F0000) >> 16 == expectedRA);<br>
};<br>
- if (!CheckRegOperands(FirstInstr, 12, 1))<br>
+ if (!checkRegOperands(firstInstr, 12, 1))<br>
return false;<br>
- if (SecondInstr != 0x60000000 && !CheckRegOperands(SecondInstr, 12, 12))<br>
+ if (secondInstr != 0x60000000 && !checkRegOperands(secondInstr, 12, 12))<br>
return false;<br>
<br>
- int32_t StackFrameSize = (HiImm * 65536) + LoImm;<br>
+ int32_t stackFrameSize = (hiImm * 65536) + loImm;<br>
// Check that the adjusted size doesn't overflow what we can represent with 2<br>
// instructions.<br>
- if (StackFrameSize < Config->SplitStackAdjustSize + INT32_MIN) {<br>
- error(getErrorLocation(Loc) + "split-stack prologue adjustment overflows");<br>
+ if (stackFrameSize < config->splitStackAdjustSize + INT32_MIN) {<br>
+ error(getErrorLocation(loc) + "split-stack prologue adjustment overflows");<br>
return false;<br>
}<br>
<br>
- int32_t AdjustedStackFrameSize =<br>
- StackFrameSize - Config->SplitStackAdjustSize;<br>
+ int32_t adjustedStackFrameSize =<br>
+ stackFrameSize - config->splitStackAdjustSize;<br>
<br>
- LoImm = AdjustedStackFrameSize & 0xFFFF;<br>
- HiImm = (AdjustedStackFrameSize + 0x8000) >> 16;<br>
- if (HiImm) {<br>
- write32(Loc + 4, 0x3D810000 | (uint16_t)HiImm);<br>
+ loImm = adjustedStackFrameSize & 0xFFFF;<br>
+ hiImm = (adjustedStackFrameSize + 0x8000) >> 16;<br>
+ if (hiImm) {<br>
+ write32(loc + 4, 0x3D810000 | (uint16_t)hiImm);<br>
// If the low immediate is zero the second instruction will be a nop.<br>
- SecondInstr = LoImm ? 0x398C0000 | (uint16_t)LoImm : 0x60000000;<br>
- write32(Loc + 8, SecondInstr);<br>
+ secondInstr = loImm ? 0x398C0000 | (uint16_t)loImm : 0x60000000;<br>
+ write32(loc + 8, secondInstr);<br>
} else {<br>
// addi r12, r1, imm<br>
- write32(Loc + 4, (0x39810000) | (uint16_t)LoImm);<br>
- write32(Loc + 8, 0x60000000);<br>
+ write32(loc + 4, (0x39810000) | (uint16_t)loImm);<br>
+ write32(loc + 8, 0x60000000);<br>
}<br>
<br>
return true;<br>
}<br>
<br>
TargetInfo *elf::getPPC64TargetInfo() {<br>
- static PPC64 Target;<br>
- return &Target;<br>
+ static PPC64 target;<br>
+ return ⌖<br>
}<br>
<br>
Modified: lld/trunk/ELF/Arch/RISCV.cpp<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_ELF_Arch_RISCV.cpp-3Frev-3D365595-26r1-3D365594-26r2-3D365595-26view-3Ddiff&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=1UdBu57jfGbNMKRWbCRk2oXiBufnWWIwcMAQ8exYR_g&e=" rel="noreferrer" target="_blank">https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_ELF_Arch_RISCV.cpp-3Frev-3D365595-26r1-3D365594-26r2-3D365595-26view-3Ddiff&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=1UdBu57jfGbNMKRWbCRk2oXiBufnWWIwcMAQ8exYR_g&e=</a> <br>
==============================================================================<br>
--- lld/trunk/ELF/Arch/RISCV.cpp (original)<br>
+++ lld/trunk/ELF/Arch/RISCV.cpp Tue Jul 9 22:00:37 2019<br>
@@ -23,20 +23,20 @@ class RISCV final : public TargetInfo {<br>
public:<br>
RISCV();<br>
uint32_t calcEFlags() const override;<br>
- void writeGotHeader(uint8_t *Buf) const override;<br>
- void writeGotPlt(uint8_t *Buf, const Symbol &S) const override;<br>
- void writePltHeader(uint8_t *Buf) const override;<br>
- void writePlt(uint8_t *Buf, uint64_t GotPltEntryAddr, uint64_t PltEntryAddr,<br>
- int32_t Index, unsigned RelOff) const override;<br>
- RelType getDynRel(RelType Type) const override;<br>
- RelExpr getRelExpr(RelType Type, const Symbol &S,<br>
- const uint8_t *Loc) const override;<br>
- void relocateOne(uint8_t *Loc, RelType Type, uint64_t Val) const override;<br>
+ void writeGotHeader(uint8_t *buf) const override;<br>
+ void writeGotPlt(uint8_t *buf, const Symbol &s) const override;<br>
+ void writePltHeader(uint8_t *buf) const override;<br>
+ void writePlt(uint8_t *buf, uint64_t gotPltEntryAddr, uint64_t pltEntryAddr,<br>
+ int32_t index, unsigned relOff) const override;<br>
+ RelType getDynRel(RelType type) const override;<br>
+ RelExpr getRelExpr(RelType type, const Symbol &s,<br>
+ const uint8_t *loc) const override;<br>
+ void relocateOne(uint8_t *loc, RelType type, uint64_t val) const override;<br>
};<br>
<br>
} // end anonymous namespace<br>
<br>
-const uint64_t DTPOffset = 0x800;<br>
+const uint64_t dtpOffset = 0x800;<br>
<br>
enum Op {<br>
ADDI = 0x13,<br>
@@ -56,91 +56,91 @@ enum Reg {<br>
X_T3 = 28,<br>
};<br>
<br>
-static uint32_t hi20(uint32_t Val) { return (Val + 0x800) >> 12; }<br>
-static uint32_t lo12(uint32_t Val) { return Val & 4095; }<br>
+static uint32_t hi20(uint32_t val) { return (val + 0x800) >> 12; }<br>
+static uint32_t lo12(uint32_t val) { return val & 4095; }<br>
<br>
-static uint32_t itype(uint32_t Op, uint32_t Rd, uint32_t Rs1, uint32_t Imm) {<br>
- return Op | (Rd << 7) | (Rs1 << 15) | (Imm << 20);<br>
+static uint32_t itype(uint32_t op, uint32_t rd, uint32_t rs1, uint32_t imm) {<br>
+ return op | (rd << 7) | (rs1 << 15) | (imm << 20);<br>
}<br>
-static uint32_t rtype(uint32_t Op, uint32_t Rd, uint32_t Rs1, uint32_t Rs2) {<br>
- return Op | (Rd << 7) | (Rs1 << 15) | (Rs2 << 20);<br>
+static uint32_t rtype(uint32_t op, uint32_t rd, uint32_t rs1, uint32_t rs2) {<br>
+ return op | (rd << 7) | (rs1 << 15) | (rs2 << 20);<br>
}<br>
-static uint32_t utype(uint32_t Op, uint32_t Rd, uint32_t Imm) {<br>
- return Op | (Rd << 7) | (Imm << 12);<br>
+static uint32_t utype(uint32_t op, uint32_t rd, uint32_t imm) {<br>
+ return op | (rd << 7) | (imm << 12);<br>
}<br>
<br>
RISCV::RISCV() {<br>
- CopyRel = R_RISCV_COPY;<br>
- NoneRel = R_RISCV_NONE;<br>
- PltRel = R_RISCV_JUMP_SLOT;<br>
- RelativeRel = R_RISCV_RELATIVE;<br>
- if (Config->Is64) {<br>
- SymbolicRel = R_RISCV_64;<br>
- TlsModuleIndexRel = R_RISCV_TLS_DTPMOD64;<br>
- TlsOffsetRel = R_RISCV_TLS_DTPREL64;<br>
- TlsGotRel = R_RISCV_TLS_TPREL64;<br>
+ copyRel = R_RISCV_COPY;<br>
+ noneRel = R_RISCV_NONE;<br>
+ pltRel = R_RISCV_JUMP_SLOT;<br>
+ relativeRel = R_RISCV_RELATIVE;<br>
+ if (config->is64) {<br>
+ symbolicRel = R_RISCV_64;<br>
+ tlsModuleIndexRel = R_RISCV_TLS_DTPMOD64;<br>
+ tlsOffsetRel = R_RISCV_TLS_DTPREL64;<br>
+ tlsGotRel = R_RISCV_TLS_TPREL64;<br>
} else {<br>
- SymbolicRel = R_RISCV_32;<br>
- TlsModuleIndexRel = R_RISCV_TLS_DTPMOD32;<br>
- TlsOffsetRel = R_RISCV_TLS_DTPREL32;<br>
- TlsGotRel = R_RISCV_TLS_TPREL32;<br>
+ symbolicRel = R_RISCV_32;<br>
+ tlsModuleIndexRel = R_RISCV_TLS_DTPMOD32;<br>
+ tlsOffsetRel = R_RISCV_TLS_DTPREL32;<br>
+ tlsGotRel = R_RISCV_TLS_TPREL32;<br>
}<br>
- GotRel = SymbolicRel;<br>
+ gotRel = symbolicRel;<br>
<br>
// .got[0] = _DYNAMIC<br>
- GotBaseSymInGotPlt = false;<br>
- GotHeaderEntriesNum = 1;<br>
+ gotBaseSymInGotPlt = false;<br>
+ gotHeaderEntriesNum = 1;<br>
<br>
// .got.plt[0] = _dl_runtime_resolve, .got.plt[1] = link_map<br>
- GotPltHeaderEntriesNum = 2;<br>
+ gotPltHeaderEntriesNum = 2;<br>
<br>
- PltEntrySize = 16;<br>
- PltHeaderSize = 32;<br>
+ pltEntrySize = 16;<br>
+ pltHeaderSize = 32;<br>
}<br>
<br>
-static uint32_t getEFlags(InputFile *F) {<br>
- if (Config->Is64)<br>
- return cast<ObjFile<ELF64LE>>(F)->getObj().getHeader()->e_flags;<br>
- return cast<ObjFile<ELF32LE>>(F)->getObj().getHeader()->e_flags;<br>
+static uint32_t getEFlags(InputFile *f) {<br>
+ if (config->is64)<br>
+ return cast<ObjFile<ELF64LE>>(f)->getObj().getHeader()->e_flags;<br>
+ return cast<ObjFile<ELF32LE>>(f)->getObj().getHeader()->e_flags;<br>
}<br>
<br>
uint32_t RISCV::calcEFlags() const {<br>
- assert(!ObjectFiles.empty());<br>
+ assert(!objectFiles.empty());<br>
<br>
- uint32_t Target = getEFlags(ObjectFiles.front());<br>
+ uint32_t target = getEFlags(objectFiles.front());<br>
<br>
- for (InputFile *F : ObjectFiles) {<br>
- uint32_t EFlags = getEFlags(F);<br>
- if (EFlags & EF_RISCV_RVC)<br>
- Target |= EF_RISCV_RVC;<br>
+ for (InputFile *f : objectFiles) {<br>
+ uint32_t eflags = getEFlags(f);<br>
+ if (eflags & EF_RISCV_RVC)<br>
+ target |= EF_RISCV_RVC;<br>
<br>
- if ((EFlags & EF_RISCV_FLOAT_ABI) != (Target & EF_RISCV_FLOAT_ABI))<br>
- error(toString(F) +<br>
+ if ((eflags & EF_RISCV_FLOAT_ABI) != (target & EF_RISCV_FLOAT_ABI))<br>
+ error(toString(f) +<br>
": cannot link object files with different floating-point ABI");<br>
<br>
- if ((EFlags & EF_RISCV_RVE) != (Target & EF_RISCV_RVE))<br>
- error(toString(F) +<br>
+ if ((eflags & EF_RISCV_RVE) != (target & EF_RISCV_RVE))<br>
+ error(toString(f) +<br>
": cannot link object files with different EF_RISCV_RVE");<br>
}<br>
<br>
- return Target;<br>
+ return target;<br>
}<br>
<br>
-void RISCV::writeGotHeader(uint8_t *Buf) const {<br>
- if (Config->Is64)<br>
- write64le(Buf, Main->Dynamic->getVA());<br>
+void RISCV::writeGotHeader(uint8_t *buf) const {<br>
+ if (config->is64)<br>
+ write64le(buf, mainPart->dynamic->getVA());<br>
else<br>
- write32le(Buf, Main->Dynamic->getVA());<br>
+ write32le(buf, mainPart->dynamic->getVA());<br>
}<br>
<br>
-void RISCV::writeGotPlt(uint8_t *Buf, const Symbol &S) const {<br>
- if (Config->Is64)<br>
- write64le(Buf, In.Plt->getVA());<br>
+void RISCV::writeGotPlt(uint8_t *buf, const Symbol &s) const {<br>
+ if (config->is64)<br>
+ write64le(buf, in.plt->getVA());<br>
else<br>
- write32le(Buf, In.Plt->getVA());<br>
+ write32le(buf, in.plt->getVA());<br>
}<br>
<br>
-void RISCV::writePltHeader(uint8_t *Buf) const {<br>
+void RISCV::writePltHeader(uint8_t *buf) const {<br>
// 1: auipc t2, %pcrel_hi(.got.plt)<br>
// sub t1, t1, t3<br>
// l[wd] t3, %pcrel_lo(1b)(t2); t3 = _dl_runtime_resolve<br>
@@ -149,40 +149,40 @@ void RISCV::writePltHeader(uint8_t *Buf)<br>
// srli t1, t1, (rv64?1:2); t1 = &.got.plt[i] - &.got.plt[0]<br>
// l[wd] t0, Wordsize(t0); t0 = link_map<br>
// jr t3<br>
- uint32_t Offset = In.GotPlt->getVA() - In.Plt->getVA();<br>
- uint32_t Load = Config->Is64 ? LD : LW;<br>
- write32le(Buf + 0, utype(AUIPC, X_T2, hi20(Offset)));<br>
- write32le(Buf + 4, rtype(SUB, X_T1, X_T1, X_T3));<br>
- write32le(Buf + 8, itype(Load, X_T3, X_T2, lo12(Offset)));<br>
- write32le(Buf + 12, itype(ADDI, X_T1, X_T1, -Target->PltHeaderSize - 12));<br>
- write32le(Buf + 16, itype(ADDI, X_T0, X_T2, lo12(Offset)));<br>
- write32le(Buf + 20, itype(SRLI, X_T1, X_T1, Config->Is64 ? 1 : 2));<br>
- write32le(Buf + 24, itype(Load, X_T0, X_T0, Config->Wordsize));<br>
- write32le(Buf + 28, itype(JALR, 0, X_T3, 0));<br>
+ uint32_t offset = in.gotPlt->getVA() - in.plt->getVA();<br>
+ uint32_t load = config->is64 ? LD : LW;<br>
+ write32le(buf + 0, utype(AUIPC, X_T2, hi20(offset)));<br>
+ write32le(buf + 4, rtype(SUB, X_T1, X_T1, X_T3));<br>
+ write32le(buf + 8, itype(load, X_T3, X_T2, lo12(offset)));<br>
+ write32le(buf + 12, itype(ADDI, X_T1, X_T1, -target->pltHeaderSize - 12));<br>
+ write32le(buf + 16, itype(ADDI, X_T0, X_T2, lo12(offset)));<br>
+ write32le(buf + 20, itype(SRLI, X_T1, X_T1, config->is64 ? 1 : 2));<br>
+ write32le(buf + 24, itype(load, X_T0, X_T0, config->wordsize));<br>
+ write32le(buf + 28, itype(JALR, 0, X_T3, 0));<br>
}<br>
<br>
-void RISCV::writePlt(uint8_t *Buf, uint64_t GotPltEntryAddr,<br>
- uint64_t PltEntryAddr, int32_t Index,<br>
- unsigned RelOff) const {<br>
+void RISCV::writePlt(uint8_t *buf, uint64_t gotPltEntryAddr,<br>
+ uint64_t pltEntryAddr, int32_t index,<br>
+ unsigned relOff) const {<br>
// 1: auipc t3, %pcrel_hi(f@.got.plt)<br>
// l[wd] t3, %pcrel_lo(1b)(t3)<br>
// jalr t1, t3<br>
// nop<br>
- uint32_t Offset = GotPltEntryAddr - PltEntryAddr;<br>
- write32le(Buf + 0, utype(AUIPC, X_T3, hi20(Offset)));<br>
- write32le(Buf + 4, itype(Config->Is64 ? LD : LW, X_T3, X_T3, lo12(Offset)));<br>
- write32le(Buf + 8, itype(JALR, X_T1, X_T3, 0));<br>
- write32le(Buf + 12, itype(ADDI, 0, 0, 0));<br>
+ uint32_t offset = gotPltEntryAddr - pltEntryAddr;<br>
+ write32le(buf + 0, utype(AUIPC, X_T3, hi20(offset)));<br>
+ write32le(buf + 4, itype(config->is64 ? LD : LW, X_T3, X_T3, lo12(offset)));<br>
+ write32le(buf + 8, itype(JALR, X_T1, X_T3, 0));<br>
+ write32le(buf + 12, itype(ADDI, 0, 0, 0));<br>
}<br>
<br>
-RelType RISCV::getDynRel(RelType Type) const {<br>
- return Type == Target->SymbolicRel ? Type<br>
+RelType RISCV::getDynRel(RelType type) const {<br>
+ return type == target->symbolicRel ? type<br>
: static_cast<RelType>(R_RISCV_NONE);<br>
}<br>
<br>
-RelExpr RISCV::getRelExpr(const RelType Type, const Symbol &S,<br>
- const uint8_t *Loc) const {<br>
- switch (Type) {<br>
+RelExpr RISCV::getRelExpr(const RelType type, const Symbol &s,<br>
+ const uint8_t *loc) const {<br>
+ switch (type) {<br>
case R_RISCV_ADD8:<br>
case R_RISCV_ADD16:<br>
case R_RISCV_ADD32:<br>
@@ -215,7 +215,7 @@ RelExpr RISCV::getRelExpr(const RelType<br>
case R_RISCV_TLS_GD_HI20:<br>
return R_TLSGD_PC;<br>
case R_RISCV_TLS_GOT_HI20:<br>
- Config->HasStaticTlsModel = true;<br>
+ config->hasStaticTlsModel = true;<br>
return R_GOT_PC;<br>
case R_RISCV_TPREL_HI20:<br>
case R_RISCV_TPREL_LO12_I:<br>
@@ -231,106 +231,106 @@ RelExpr RISCV::getRelExpr(const RelType<br>
}<br>
<br>
// Extract bits V[Begin:End], where range is inclusive, and Begin must be < 63.<br>
-static uint32_t extractBits(uint64_t V, uint32_t Begin, uint32_t End) {<br>
- return (V & ((1ULL << (Begin + 1)) - 1)) >> End;<br>
+static uint32_t extractBits(uint64_t v, uint32_t begin, uint32_t end) {<br>
+ return (v & ((1ULL << (begin + 1)) - 1)) >> end;<br>
}<br>
<br>
-void RISCV::relocateOne(uint8_t *Loc, const RelType Type,<br>
- const uint64_t Val) const {<br>
- const unsigned Bits = Config->Wordsize * 8;<br>
+void RISCV::relocateOne(uint8_t *loc, const RelType type,<br>
+ const uint64_t val) const {<br>
+ const unsigned bits = config->wordsize * 8;<br>
<br>
- switch (Type) {<br>
+ switch (type) {<br>
case R_RISCV_32:<br>
- write32le(Loc, Val);<br>
+ write32le(loc, val);<br>
return;<br>
case R_RISCV_64:<br>
- write64le(Loc, Val);<br>
+ write64le(loc, val);<br>
return;<br>
<br>
case R_RISCV_RVC_BRANCH: {<br>
- checkInt(Loc, static_cast<int64_t>(Val) >> 1, 8, Type);<br>
- checkAlignment(Loc, Val, 2, Type);<br>
- uint16_t Insn = read16le(Loc) & 0xE383;<br>
- uint16_t Imm8 = extractBits(Val, 8, 8) << 12;<br>
- uint16_t Imm4_3 = extractBits(Val, 4, 3) << 10;<br>
- uint16_t Imm7_6 = extractBits(Val, 7, 6) << 5;<br>
- uint16_t Imm2_1 = extractBits(Val, 2, 1) << 3;<br>
- uint16_t Imm5 = extractBits(Val, 5, 5) << 2;<br>
- Insn |= Imm8 | Imm4_3 | Imm7_6 | Imm2_1 | Imm5;<br>
+ checkInt(loc, static_cast<int64_t>(val) >> 1, 8, type);<br>
+ checkAlignment(loc, val, 2, type);<br>
+ uint16_t insn = read16le(loc) & 0xE383;<br>
+ uint16_t imm8 = extractBits(val, 8, 8) << 12;<br>
+ uint16_t imm4_3 = extractBits(val, 4, 3) << 10;<br>
+ uint16_t imm7_6 = extractBits(val, 7, 6) << 5;<br>
+ uint16_t imm2_1 = extractBits(val, 2, 1) << 3;<br>
+ uint16_t imm5 = extractBits(val, 5, 5) << 2;<br>
+ insn |= imm8 | imm4_3 | imm7_6 | imm2_1 | imm5;<br>
<br>
- write16le(Loc, Insn);<br>
+ write16le(loc, insn);<br>
return;<br>
}<br>
<br>
case R_RISCV_RVC_JUMP: {<br>
- checkInt(Loc, static_cast<int64_t>(Val) >> 1, 11, Type);<br>
- checkAlignment(Loc, Val, 2, Type);<br>
- uint16_t Insn = read16le(Loc) & 0xE003;<br>
- uint16_t Imm11 = extractBits(Val, 11, 11) << 12;<br>
- uint16_t Imm4 = extractBits(Val, 4, 4) << 11;<br>
- uint16_t Imm9_8 = extractBits(Val, 9, 8) << 9;<br>
- uint16_t Imm10 = extractBits(Val, 10, 10) << 8;<br>
- uint16_t Imm6 = extractBits(Val, 6, 6) << 7;<br>
- uint16_t Imm7 = extractBits(Val, 7, 7) << 6;<br>
- uint16_t Imm3_1 = extractBits(Val, 3, 1) << 3;<br>
- uint16_t Imm5 = extractBits(Val, 5, 5) << 2;<br>
- Insn |= Imm11 | Imm4 | Imm9_8 | Imm10 | Imm6 | Imm7 | Imm3_1 | Imm5;<br>
+ checkInt(loc, static_cast<int64_t>(val) >> 1, 11, type);<br>
+ checkAlignment(loc, val, 2, type);<br>
+ uint16_t insn = read16le(loc) & 0xE003;<br>
+ uint16_t imm11 = extractBits(val, 11, 11) << 12;<br>
+ uint16_t imm4 = extractBits(val, 4, 4) << 11;<br>
+ uint16_t imm9_8 = extractBits(val, 9, 8) << 9;<br>
+ uint16_t imm10 = extractBits(val, 10, 10) << 8;<br>
+ uint16_t imm6 = extractBits(val, 6, 6) << 7;<br>
+ uint16_t imm7 = extractBits(val, 7, 7) << 6;<br>
+ uint16_t imm3_1 = extractBits(val, 3, 1) << 3;<br>
+ uint16_t imm5 = extractBits(val, 5, 5) << 2;<br>
+ insn |= imm11 | imm4 | imm9_8 | imm10 | imm6 | imm7 | imm3_1 | imm5;<br>
<br>
- write16le(Loc, Insn);<br>
+ write16le(loc, insn);<br>
return;<br>
}<br>
<br>
case R_RISCV_RVC_LUI: {<br>
- int64_t Imm = SignExtend64(Val + 0x800, Bits) >> 12;<br>
- checkInt(Loc, Imm, 6, Type);<br>
- if (Imm == 0) { // `c.lui rd, 0` is illegal, convert to `<a href="http://c.li" rel="noreferrer" target="_blank">c.li</a> rd, 0`<br>
- write16le(Loc, (read16le(Loc) & 0x0F83) | 0x4000);<br>
+ int64_t imm = SignExtend64(val + 0x800, bits) >> 12;<br>
+ checkInt(loc, imm, 6, type);<br>
+ if (imm == 0) { // `c.lui rd, 0` is illegal, convert to `<a href="http://c.li" rel="noreferrer" target="_blank">c.li</a> rd, 0`<br>
+ write16le(loc, (read16le(loc) & 0x0F83) | 0x4000);<br>
} else {<br>
- uint16_t Imm17 = extractBits(Val + 0x800, 17, 17) << 12;<br>
- uint16_t Imm16_12 = extractBits(Val + 0x800, 16, 12) << 2;<br>
- write16le(Loc, (read16le(Loc) & 0xEF83) | Imm17 | Imm16_12);<br>
+ uint16_t imm17 = extractBits(val + 0x800, 17, 17) << 12;<br>
+ uint16_t imm16_12 = extractBits(val + 0x800, 16, 12) << 2;<br>
+ write16le(loc, (read16le(loc) & 0xEF83) | imm17 | imm16_12);<br>
}<br>
return;<br>
}<br>
<br>
case R_RISCV_JAL: {<br>
- checkInt(Loc, static_cast<int64_t>(Val) >> 1, 20, Type);<br>
- checkAlignment(Loc, Val, 2, Type);<br>
+ checkInt(loc, static_cast<int64_t>(val) >> 1, 20, type);<br>
+ checkAlignment(loc, val, 2, type);<br>
<br>
- uint32_t Insn = read32le(Loc) & 0xFFF;<br>
- uint32_t Imm20 = extractBits(Val, 20, 20) << 31;<br>
- uint32_t Imm10_1 = extractBits(Val, 10, 1) << 21;<br>
- uint32_t Imm11 = extractBits(Val, 11, 11) << 20;<br>
- uint32_t Imm19_12 = extractBits(Val, 19, 12) << 12;<br>
- Insn |= Imm20 | Imm10_1 | Imm11 | Imm19_12;<br>
+ uint32_t insn = read32le(loc) & 0xFFF;<br>
+ uint32_t imm20 = extractBits(val, 20, 20) << 31;<br>
+ uint32_t imm10_1 = extractBits(val, 10, 1) << 21;<br>
+ uint32_t imm11 = extractBits(val, 11, 11) << 20;<br>
+ uint32_t imm19_12 = extractBits(val, 19, 12) << 12;<br>
+ insn |= imm20 | imm10_1 | imm11 | imm19_12;<br>
<br>
- write32le(Loc, Insn);<br>
+ write32le(loc, insn);<br>
return;<br>
}<br>
<br>
case R_RISCV_BRANCH: {<br>
- checkInt(Loc, static_cast<int64_t>(Val) >> 1, 12, Type);<br>
- checkAlignment(Loc, Val, 2, Type);<br>
+ checkInt(loc, static_cast<int64_t>(val) >> 1, 12, type);<br>
+ checkAlignment(loc, val, 2, type);<br>
<br>
- uint32_t Insn = read32le(Loc) & 0x1FFF07F;<br>
- uint32_t Imm12 = extractBits(Val, 12, 12) << 31;<br>
- uint32_t Imm10_5 = extractBits(Val, 10, 5) << 25;<br>
- uint32_t Imm4_1 = extractBits(Val, 4, 1) << 8;<br>
- uint32_t Imm11 = extractBits(Val, 11, 11) << 7;<br>
- Insn |= Imm12 | Imm10_5 | Imm4_1 | Imm11;<br>
+ uint32_t insn = read32le(loc) & 0x1FFF07F;<br>
+ uint32_t imm12 = extractBits(val, 12, 12) << 31;<br>
+ uint32_t imm10_5 = extractBits(val, 10, 5) << 25;<br>
+ uint32_t imm4_1 = extractBits(val, 4, 1) << 8;<br>
+ uint32_t imm11 = extractBits(val, 11, 11) << 7;<br>
+ insn |= imm12 | imm10_5 | imm4_1 | imm11;<br>
<br>
- write32le(Loc, Insn);<br>
+ write32le(loc, insn);<br>
return;<br>
}<br>
<br>
// auipc + jalr pair<br>
case R_RISCV_CALL:<br>
case R_RISCV_CALL_PLT: {<br>
- int64_t Hi = SignExtend64(Val + 0x800, Bits) >> 12;<br>
- checkInt(Loc, Hi, 20, Type);<br>
- if (isInt<20>(Hi)) {<br>
- relocateOne(Loc, R_RISCV_PCREL_HI20, Val);<br>
- relocateOne(Loc + 4, R_RISCV_PCREL_LO12_I, Val);<br>
+ int64_t hi = SignExtend64(val + 0x800, bits) >> 12;<br>
+ checkInt(loc, hi, 20, type);<br>
+ if (isInt<20>(hi)) {<br>
+ relocateOne(loc, R_RISCV_PCREL_HI20, val);<br>
+ relocateOne(loc + 4, R_RISCV_PCREL_LO12_I, val);<br>
}<br>
return;<br>
}<br>
@@ -341,78 +341,78 @@ void RISCV::relocateOne(uint8_t *Loc, co<br>
case R_RISCV_TLS_GOT_HI20:<br>
case R_RISCV_TPREL_HI20:<br>
case R_RISCV_HI20: {<br>
- uint64_t Hi = Val + 0x800;<br>
- checkInt(Loc, SignExtend64(Hi, Bits) >> 12, 20, Type);<br>
- write32le(Loc, (read32le(Loc) & 0xFFF) | (Hi & 0xFFFFF000));<br>
+ uint64_t hi = val + 0x800;<br>
+ checkInt(loc, SignExtend64(hi, bits) >> 12, 20, type);<br>
+ write32le(loc, (read32le(loc) & 0xFFF) | (hi & 0xFFFFF000));<br>
return;<br>
}<br>
<br>
case R_RISCV_PCREL_LO12_I:<br>
case R_RISCV_TPREL_LO12_I:<br>
case R_RISCV_LO12_I: {<br>
- uint64_t Hi = (Val + 0x800) >> 12;<br>
- uint64_t Lo = Val - (Hi << 12);<br>
- write32le(Loc, (read32le(Loc) & 0xFFFFF) | ((Lo & 0xFFF) << 20));<br>
+ uint64_t hi = (val + 0x800) >> 12;<br>
+ uint64_t lo = val - (hi << 12);<br>
+ write32le(loc, (read32le(loc) & 0xFFFFF) | ((lo & 0xFFF) << 20));<br>
return;<br>
}<br>
<br>
case R_RISCV_PCREL_LO12_S:<br>
case R_RISCV_TPREL_LO12_S:<br>
case R_RISCV_LO12_S: {<br>
- uint64_t Hi = (Val + 0x800) >> 12;<br>
- uint64_t Lo = Val - (Hi << 12);<br>
- uint32_t Imm11_5 = extractBits(Lo, 11, 5) << 25;<br>
- uint32_t Imm4_0 = extractBits(Lo, 4, 0) << 7;<br>
- write32le(Loc, (read32le(Loc) & 0x1FFF07F) | Imm11_5 | Imm4_0);<br>
+ uint64_t hi = (val + 0x800) >> 12;<br>
+ uint64_t lo = val - (hi << 12);<br>
+ uint32_t imm11_5 = extractBits(lo, 11, 5) << 25;<br>
+ uint32_t imm4_0 = extractBits(lo, 4, 0) << 7;<br>
+ write32le(loc, (read32le(loc) & 0x1FFF07F) | imm11_5 | imm4_0);<br>
return;<br>
}<br>
<br>
case R_RISCV_ADD8:<br>
- *Loc += Val;<br>
+ *loc += val;<br>
return;<br>
case R_RISCV_ADD16:<br>
- write16le(Loc, read16le(Loc) + Val);<br>
+ write16le(loc, read16le(loc) + val);<br>
return;<br>
case R_RISCV_ADD32:<br>
- write32le(Loc, read32le(Loc) + Val);<br>
+ write32le(loc, read32le(loc) + val);<br>
return;<br>
case R_RISCV_ADD64:<br>
- write64le(Loc, read64le(Loc) + Val);<br>
+ write64le(loc, read64le(loc) + val);<br>
return;<br>
case R_RISCV_SUB6:<br>
- *Loc = (*Loc & 0xc0) | (((*Loc & 0x3f) - Val) & 0x3f);<br>
+ *loc = (*loc & 0xc0) | (((*loc & 0x3f) - val) & 0x3f);<br>
return;<br>
case R_RISCV_SUB8:<br>
- *Loc -= Val;<br>
+ *loc -= val;<br>
return;<br>
case R_RISCV_SUB16:<br>
- write16le(Loc, read16le(Loc) - Val);<br>
+ write16le(loc, read16le(loc) - val);<br>
return;<br>
case R_RISCV_SUB32:<br>
- write32le(Loc, read32le(Loc) - Val);<br>
+ write32le(loc, read32le(loc) - val);<br>
return;<br>
case R_RISCV_SUB64:<br>
- write64le(Loc, read64le(Loc) - Val);<br>
+ write64le(loc, read64le(loc) - val);<br>
return;<br>
case R_RISCV_SET6:<br>
- *Loc = (*Loc & 0xc0) | (Val & 0x3f);<br>
+ *loc = (*loc & 0xc0) | (val & 0x3f);<br>
return;<br>
case R_RISCV_SET8:<br>
- *Loc = Val;<br>
+ *loc = val;<br>
return;<br>
case R_RISCV_SET16:<br>
- write16le(Loc, Val);<br>
+ write16le(loc, val);<br>
return;<br>
case R_RISCV_SET32:<br>
case R_RISCV_32_PCREL:<br>
- write32le(Loc, Val);<br>
+ write32le(loc, val);<br>
return;<br>
<br>
case R_RISCV_TLS_DTPREL32:<br>
- write32le(Loc, Val - DTPOffset);<br>
+ write32le(loc, val - dtpOffset);<br>
break;<br>
case R_RISCV_TLS_DTPREL64:<br>
- write64le(Loc, Val - DTPOffset);<br>
+ write64le(loc, val - dtpOffset);<br>
break;<br>
<br>
case R_RISCV_ALIGN:<br>
@@ -430,13 +430,13 @@ void RISCV::relocateOne(uint8_t *Loc, co<br>
case R_RISCV_GPREL_I:<br>
case R_RISCV_GPREL_S:<br>
default:<br>
- error(getErrorLocation(Loc) +<br>
- "unimplemented relocation: " + toString(Type));<br>
+ error(getErrorLocation(loc) +<br>
+ "unimplemented relocation: " + toString(type));<br>
return;<br>
}<br>
}<br>
<br>
TargetInfo *elf::getRISCVTargetInfo() {<br>
- static RISCV Target;<br>
- return &Target;<br>
+ static RISCV target;<br>
+ return ⌖<br>
}<br>
<br>
Modified: lld/trunk/ELF/Arch/SPARCV9.cpp<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_ELF_Arch_SPARCV9.cpp-3Frev-3D365595-26r1-3D365594-26r2-3D365595-26view-3Ddiff&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=OJ_bWBG79cEd8wnTohjOqJjcK_6NQIDMrXX550rPwPE&e=" rel="noreferrer" target="_blank">https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_ELF_Arch_SPARCV9.cpp-3Frev-3D365595-26r1-3D365594-26r2-3D365595-26view-3Ddiff&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=OJ_bWBG79cEd8wnTohjOqJjcK_6NQIDMrXX550rPwPE&e=</a> <br>
==============================================================================<br>
--- lld/trunk/ELF/Arch/SPARCV9.cpp (original)<br>
+++ lld/trunk/ELF/Arch/SPARCV9.cpp Tue Jul 9 22:00:37 2019<br>
@@ -23,32 +23,32 @@ namespace {<br>
class SPARCV9 final : public TargetInfo {<br>
public:<br>
SPARCV9();<br>
- RelExpr getRelExpr(RelType Type, const Symbol &S,<br>
- const uint8_t *Loc) const override;<br>
- void writePlt(uint8_t *Buf, uint64_t GotEntryAddr, uint64_t PltEntryAddr,<br>
- int32_t Index, unsigned RelOff) const override;<br>
- void relocateOne(uint8_t *Loc, RelType Type, uint64_t Val) const override;<br>
+ RelExpr getRelExpr(RelType type, const Symbol &s,<br>
+ const uint8_t *loc) const override;<br>
+ void writePlt(uint8_t *buf, uint64_t gotEntryAddr, uint64_t pltEntryAddr,<br>
+ int32_t index, unsigned relOff) const override;<br>
+ void relocateOne(uint8_t *loc, RelType type, uint64_t val) const override;<br>
};<br>
} // namespace<br>
<br>
SPARCV9::SPARCV9() {<br>
- CopyRel = R_SPARC_COPY;<br>
- GotRel = R_SPARC_GLOB_DAT;<br>
- NoneRel = R_SPARC_NONE;<br>
- PltRel = R_SPARC_JMP_SLOT;<br>
- RelativeRel = R_SPARC_RELATIVE;<br>
- SymbolicRel = R_SPARC_64;<br>
- PltEntrySize = 32;<br>
- PltHeaderSize = 4 * PltEntrySize;<br>
-<br>
- DefaultCommonPageSize = 8192;<br>
- DefaultMaxPageSize = 0x100000;<br>
- DefaultImageBase = 0x100000;<br>
+ copyRel = R_SPARC_COPY;<br>
+ gotRel = R_SPARC_GLOB_DAT;<br>
+ noneRel = R_SPARC_NONE;<br>
+ pltRel = R_SPARC_JMP_SLOT;<br>
+ relativeRel = R_SPARC_RELATIVE;<br>
+ symbolicRel = R_SPARC_64;<br>
+ pltEntrySize = 32;<br>
+ pltHeaderSize = 4 * pltEntrySize;<br>
+<br>
+ defaultCommonPageSize = 8192;<br>
+ defaultMaxPageSize = 0x100000;<br>
+ defaultImageBase = 0x100000;<br>
}<br>
<br>
-RelExpr SPARCV9::getRelExpr(RelType Type, const Symbol &S,<br>
- const uint8_t *Loc) const {<br>
- switch (Type) {<br>
+RelExpr SPARCV9::getRelExpr(RelType type, const Symbol &s,<br>
+ const uint8_t *loc) const {<br>
+ switch (type) {<br>
case R_SPARC_32:<br>
case R_SPARC_UA32:<br>
case R_SPARC_64:<br>
@@ -68,65 +68,65 @@ RelExpr SPARCV9::getRelExpr(RelType Type<br>
case R_SPARC_NONE:<br>
return R_NONE;<br>
default:<br>
- error(getErrorLocation(Loc) + "unknown relocation (" + Twine(Type) +<br>
- ") against symbol " + toString(S));<br>
+ error(getErrorLocation(loc) + "unknown relocation (" + Twine(type) +<br>
+ ") against symbol " + toString(s));<br>
return R_NONE;<br>
}<br>
}<br>
<br>
-void SPARCV9::relocateOne(uint8_t *Loc, RelType Type, uint64_t Val) const {<br>
- switch (Type) {<br>
+void SPARCV9::relocateOne(uint8_t *loc, RelType type, uint64_t val) const {<br>
+ switch (type) {<br>
case R_SPARC_32:<br>
case R_SPARC_UA32:<br>
// V-word32<br>
- checkUInt(Loc, Val, 32, Type);<br>
- write32be(Loc, Val);<br>
+ checkUInt(loc, val, 32, type);<br>
+ write32be(loc, val);<br>
break;<br>
case R_SPARC_DISP32:<br>
// V-disp32<br>
- checkInt(Loc, Val, 32, Type);<br>
- write32be(Loc, Val);<br>
+ checkInt(loc, val, 32, type);<br>
+ write32be(loc, val);<br>
break;<br>
case R_SPARC_WDISP30:<br>
case R_SPARC_WPLT30:<br>
// V-disp30<br>
- checkInt(Loc, Val, 32, Type);<br>
- write32be(Loc, (read32be(Loc) & ~0x3fffffff) | ((Val >> 2) & 0x3fffffff));<br>
+ checkInt(loc, val, 32, type);<br>
+ write32be(loc, (read32be(loc) & ~0x3fffffff) | ((val >> 2) & 0x3fffffff));<br>
break;<br>
case R_SPARC_22:<br>
// V-imm22<br>
- checkUInt(Loc, Val, 22, Type);<br>
- write32be(Loc, (read32be(Loc) & ~0x003fffff) | (Val & 0x003fffff));<br>
+ checkUInt(loc, val, 22, type);<br>
+ write32be(loc, (read32be(loc) & ~0x003fffff) | (val & 0x003fffff));<br>
break;<br>
case R_SPARC_GOT22:<br>
case R_SPARC_PC22:<br>
// T-imm22<br>
- write32be(Loc, (read32be(Loc) & ~0x003fffff) | ((Val >> 10) & 0x003fffff));<br>
+ write32be(loc, (read32be(loc) & ~0x003fffff) | ((val >> 10) & 0x003fffff));<br>
break;<br>
case R_SPARC_WDISP19:<br>
// V-disp19<br>
- checkInt(Loc, Val, 21, Type);<br>
- write32be(Loc, (read32be(Loc) & ~0x0007ffff) | ((Val >> 2) & 0x0007ffff));<br>
+ checkInt(loc, val, 21, type);<br>
+ write32be(loc, (read32be(loc) & ~0x0007ffff) | ((val >> 2) & 0x0007ffff));<br>
break;<br>
case R_SPARC_GOT10:<br>
case R_SPARC_PC10:<br>
// T-simm10<br>
- write32be(Loc, (read32be(Loc) & ~0x000003ff) | (Val & 0x000003ff));<br>
+ write32be(loc, (read32be(loc) & ~0x000003ff) | (val & 0x000003ff));<br>
break;<br>
case R_SPARC_64:<br>
case R_SPARC_UA64:<br>
// V-xword64<br>
- write64be(Loc, Val);<br>
+ write64be(loc, val);<br>
break;<br>
default:<br>
llvm_unreachable("unknown relocation");<br>
}<br>
}<br>
<br>
-void SPARCV9::writePlt(uint8_t *Buf, uint64_t GotEntryAddr,<br>
- uint64_t PltEntryAddr, int32_t Index,<br>
- unsigned RelOff) const {<br>
- const uint8_t PltData[] = {<br>
+void SPARCV9::writePlt(uint8_t *buf, uint64_t gotEntryAddr,<br>
+ uint64_t pltEntryAddr, int32_t index,<br>
+ unsigned relOff) const {<br>
+ const uint8_t pltData[] = {<br>
0x03, 0x00, 0x00, 0x00, // sethi (. - .PLT0), %g1<br>
0x30, 0x68, 0x00, 0x00, // ba,a %xcc, .PLT1<br>
0x01, 0x00, 0x00, 0x00, // nop<br>
@@ -136,14 +136,14 @@ void SPARCV9::writePlt(uint8_t *Buf, uin<br>
0x01, 0x00, 0x00, 0x00, // nop<br>
0x01, 0x00, 0x00, 0x00 // nop<br>
};<br>
- memcpy(Buf, PltData, sizeof(PltData));<br>
+ memcpy(buf, pltData, sizeof(pltData));<br>
<br>
- uint64_t Off = PltHeaderSize + PltEntrySize * Index;<br>
- relocateOne(Buf, R_SPARC_22, Off);<br>
- relocateOne(Buf + 4, R_SPARC_WDISP19, -(Off + 4 - PltEntrySize));<br>
+ uint64_t off = pltHeaderSize + pltEntrySize * index;<br>
+ relocateOne(buf, R_SPARC_22, off);<br>
+ relocateOne(buf + 4, R_SPARC_WDISP19, -(off + 4 - pltEntrySize));<br>
}<br>
<br>
TargetInfo *elf::getSPARCV9TargetInfo() {<br>
- static SPARCV9 Target;<br>
- return &Target;<br>
+ static SPARCV9 target;<br>
+ return ⌖<br>
}<br>
<br>
Modified: lld/trunk/ELF/Arch/X86.cpp<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_ELF_Arch_X86.cpp-3Frev-3D365595-26r1-3D365594-26r2-3D365595-26view-3Ddiff&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=cApiwTib39xcmU3JhNlSqsKs-D0E8YFIZQpR8rbxwUs&e=" rel="noreferrer" target="_blank">https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_ELF_Arch_X86.cpp-3Frev-3D365595-26r1-3D365594-26r2-3D365595-26view-3Ddiff&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=cApiwTib39xcmU3JhNlSqsKs-D0E8YFIZQpR8rbxwUs&e=</a> <br>
==============================================================================<br>
--- lld/trunk/ELF/Arch/X86.cpp (original)<br>
+++ lld/trunk/ELF/Arch/X86.cpp Tue Jul 9 22:00:37 2019<br>
@@ -23,63 +23,63 @@ namespace {<br>
class X86 : public TargetInfo {<br>
public:<br>
X86();<br>
- int getTlsGdRelaxSkip(RelType Type) const override;<br>
- RelExpr getRelExpr(RelType Type, const Symbol &S,<br>
- const uint8_t *Loc) const override;<br>
- int64_t getImplicitAddend(const uint8_t *Buf, RelType Type) const override;<br>
- void writeGotPltHeader(uint8_t *Buf) const override;<br>
- RelType getDynRel(RelType Type) const override;<br>
- void writeGotPlt(uint8_t *Buf, const Symbol &S) const override;<br>
- void writeIgotPlt(uint8_t *Buf, const Symbol &S) const override;<br>
- void writePltHeader(uint8_t *Buf) const override;<br>
- void writePlt(uint8_t *Buf, uint64_t GotPltEntryAddr, uint64_t PltEntryAddr,<br>
- int32_t Index, unsigned RelOff) const override;<br>
- void relocateOne(uint8_t *Loc, RelType Type, uint64_t Val) const override;<br>
-<br>
- RelExpr adjustRelaxExpr(RelType Type, const uint8_t *Data,<br>
- RelExpr Expr) const override;<br>
- void relaxTlsGdToIe(uint8_t *Loc, RelType Type, uint64_t Val) const override;<br>
- void relaxTlsGdToLe(uint8_t *Loc, RelType Type, uint64_t Val) const override;<br>
- void relaxTlsIeToLe(uint8_t *Loc, RelType Type, uint64_t Val) const override;<br>
- void relaxTlsLdToLe(uint8_t *Loc, RelType Type, uint64_t Val) const override;<br>
+ int getTlsGdRelaxSkip(RelType type) const override;<br>
+ RelExpr getRelExpr(RelType type, const Symbol &s,<br>
+ const uint8_t *loc) const override;<br>
+ int64_t getImplicitAddend(const uint8_t *buf, RelType type) const override;<br>
+ void writeGotPltHeader(uint8_t *buf) const override;<br>
+ RelType getDynRel(RelType type) const override;<br>
+ void writeGotPlt(uint8_t *buf, const Symbol &s) const override;<br>
+ void writeIgotPlt(uint8_t *buf, const Symbol &s) const override;<br>
+ void writePltHeader(uint8_t *buf) const override;<br>
+ void writePlt(uint8_t *buf, uint64_t gotPltEntryAddr, uint64_t pltEntryAddr,<br>
+ int32_t index, unsigned relOff) const override;<br>
+ void relocateOne(uint8_t *loc, RelType type, uint64_t val) const override;<br>
+<br>
+ RelExpr adjustRelaxExpr(RelType type, const uint8_t *data,<br>
+ RelExpr expr) const override;<br>
+ void relaxTlsGdToIe(uint8_t *loc, RelType type, uint64_t val) const override;<br>
+ void relaxTlsGdToLe(uint8_t *loc, RelType type, uint64_t val) const override;<br>
+ void relaxTlsIeToLe(uint8_t *loc, RelType type, uint64_t val) const override;<br>
+ void relaxTlsLdToLe(uint8_t *loc, RelType type, uint64_t val) const override;<br>
};<br>
} // namespace<br>
<br>
X86::X86() {<br>
- CopyRel = R_386_COPY;<br>
- GotRel = R_386_GLOB_DAT;<br>
- NoneRel = R_386_NONE;<br>
- PltRel = R_386_JUMP_SLOT;<br>
- IRelativeRel = R_386_IRELATIVE;<br>
- RelativeRel = R_386_RELATIVE;<br>
- SymbolicRel = R_386_32;<br>
- TlsGotRel = R_386_TLS_TPOFF;<br>
- TlsModuleIndexRel = R_386_TLS_DTPMOD32;<br>
- TlsOffsetRel = R_386_TLS_DTPOFF32;<br>
- PltEntrySize = 16;<br>
- PltHeaderSize = 16;<br>
- TrapInstr = {0xcc, 0xcc, 0xcc, 0xcc}; // 0xcc = INT3<br>
+ copyRel = R_386_COPY;<br>
+ gotRel = R_386_GLOB_DAT;<br>
+ noneRel = R_386_NONE;<br>
+ pltRel = R_386_JUMP_SLOT;<br>
+ iRelativeRel = R_386_IRELATIVE;<br>
+ relativeRel = R_386_RELATIVE;<br>
+ symbolicRel = R_386_32;<br>
+ tlsGotRel = R_386_TLS_TPOFF;<br>
+ tlsModuleIndexRel = R_386_TLS_DTPMOD32;<br>
+ tlsOffsetRel = R_386_TLS_DTPOFF32;<br>
+ pltEntrySize = 16;<br>
+ pltHeaderSize = 16;<br>
+ trapInstr = {0xcc, 0xcc, 0xcc, 0xcc}; // 0xcc = INT3<br>
<br>
// Align to the non-PAE large page size (known as a superpage or huge page).<br>
// FreeBSD automatically promotes large, superpage-aligned allocations.<br>
- DefaultImageBase = 0x400000;<br>
+ defaultImageBase = 0x400000;<br>
}<br>
<br>
-int X86::getTlsGdRelaxSkip(RelType Type) const {<br>
+int X86::getTlsGdRelaxSkip(RelType type) const {<br>
return 2;<br>
}<br>
<br>
-RelExpr X86::getRelExpr(RelType Type, const Symbol &S,<br>
- const uint8_t *Loc) const {<br>
+RelExpr X86::getRelExpr(RelType type, const Symbol &s,<br>
+ const uint8_t *loc) const {<br>
// There are 4 different TLS variable models with varying degrees of<br>
// flexibility and performance. LocalExec and InitialExec models are fast but<br>
// less-flexible models. If they are in use, we set DF_STATIC_TLS flag in the<br>
// dynamic section to let runtime know about that.<br>
- if (Type == R_386_TLS_LE || Type == R_386_TLS_LE_32 || Type == R_386_TLS_IE ||<br>
- Type == R_386_TLS_GOTIE)<br>
- Config->HasStaticTlsModel = true;<br>
+ if (type == R_386_TLS_LE || type == R_386_TLS_LE_32 || type == R_386_TLS_IE ||<br>
+ type == R_386_TLS_GOTIE)<br>
+ config->hasStaticTlsModel = true;<br>
<br>
- switch (Type) {<br>
+ switch (type) {<br>
case R_386_8:<br>
case R_386_16:<br>
case R_386_32:<br>
@@ -137,7 +137,7 @@ RelExpr X86::getRelExpr(RelType Type, co<br>
// instruction. That means a ModRM byte is at Loc[-1]. By taking a look at<br>
// the byte, we can determine whether the instruction uses the operand as an<br>
// absolute address (R_GOT) or a register-relative address (R_GOTPLT).<br>
- return (Loc[-1] & 0xc7) == 0x5 ? R_GOT : R_GOTPLT;<br>
+ return (loc[-1] & 0xc7) == 0x5 ? R_GOT : R_GOTPLT;<br>
case R_386_TLS_GOTIE:<br>
return R_GOTPLT;<br>
case R_386_GOTOFF:<br>
@@ -149,17 +149,17 @@ RelExpr X86::getRelExpr(RelType Type, co<br>
case R_386_NONE:<br>
return R_NONE;<br>
default:<br>
- error(getErrorLocation(Loc) + "unknown relocation (" + Twine(Type) +<br>
- ") against symbol " + toString(S));<br>
+ error(getErrorLocation(loc) + "unknown relocation (" + Twine(type) +<br>
+ ") against symbol " + toString(s));<br>
return R_NONE;<br>
}<br>
}<br>
<br>
-RelExpr X86::adjustRelaxExpr(RelType Type, const uint8_t *Data,<br>
- RelExpr Expr) const {<br>
- switch (Expr) {<br>
+RelExpr X86::adjustRelaxExpr(RelType type, const uint8_t *data,<br>
+ RelExpr expr) const {<br>
+ switch (expr) {<br>
default:<br>
- return Expr;<br>
+ return expr;<br>
case R_RELAX_TLS_GD_TO_IE:<br>
return R_RELAX_TLS_GD_TO_IE_GOTPLT;<br>
case R_RELAX_TLS_GD_TO_LE:<br>
@@ -167,84 +167,84 @@ RelExpr X86::adjustRelaxExpr(RelType Typ<br>
}<br>
}<br>
<br>
-void X86::writeGotPltHeader(uint8_t *Buf) const {<br>
- write32le(Buf, Main->Dynamic->getVA());<br>
+void X86::writeGotPltHeader(uint8_t *buf) const {<br>
+ write32le(buf, mainPart->dynamic->getVA());<br>
}<br>
<br>
-void X86::writeGotPlt(uint8_t *Buf, const Symbol &S) const {<br>
+void X86::writeGotPlt(uint8_t *buf, const Symbol &s) const {<br>
// Entries in .got.plt initially points back to the corresponding<br>
// PLT entries with a fixed offset to skip the first instruction.<br>
- write32le(Buf, S.getPltVA() + 6);<br>
+ write32le(buf, s.getPltVA() + 6);<br>
}<br>
<br>
-void X86::writeIgotPlt(uint8_t *Buf, const Symbol &S) const {<br>
+void X86::writeIgotPlt(uint8_t *buf, const Symbol &s) const {<br>
// An x86 entry is the address of the ifunc resolver function.<br>
- write32le(Buf, S.getVA());<br>
+ write32le(buf, s.getVA());<br>
}<br>
<br>
-RelType X86::getDynRel(RelType Type) const {<br>
- if (Type == R_386_TLS_LE)<br>
+RelType X86::getDynRel(RelType type) const {<br>
+ if (type == R_386_TLS_LE)<br>
return R_386_TLS_TPOFF;<br>
- if (Type == R_386_TLS_LE_32)<br>
+ if (type == R_386_TLS_LE_32)<br>
return R_386_TLS_TPOFF32;<br>
- return Type;<br>
+ return type;<br>
}<br>
<br>
-void X86::writePltHeader(uint8_t *Buf) const {<br>
- if (Config->Pic) {<br>
- const uint8_t V[] = {<br>
+void X86::writePltHeader(uint8_t *buf) const {<br>
+ if (config->isPic) {<br>
+ const uint8_t v[] = {<br>
0xff, 0xb3, 0x04, 0x00, 0x00, 0x00, // pushl 4(%ebx)<br>
0xff, 0xa3, 0x08, 0x00, 0x00, 0x00, // jmp *8(%ebx)<br>
0x90, 0x90, 0x90, 0x90 // nop<br>
};<br>
- memcpy(Buf, V, sizeof(V));<br>
+ memcpy(buf, v, sizeof(v));<br>
return;<br>
}<br>
<br>
- const uint8_t PltData[] = {<br>
+ const uint8_t pltData[] = {<br>
0xff, 0x35, 0, 0, 0, 0, // pushl (GOTPLT+4)<br>
0xff, 0x25, 0, 0, 0, 0, // jmp *(GOTPLT+8)<br>
0x90, 0x90, 0x90, 0x90, // nop<br>
};<br>
- memcpy(Buf, PltData, sizeof(PltData));<br>
- uint32_t GotPlt = In.GotPlt->getVA();<br>
- write32le(Buf + 2, GotPlt + 4);<br>
- write32le(Buf + 8, GotPlt + 8);<br>
+ memcpy(buf, pltData, sizeof(pltData));<br>
+ uint32_t gotPlt = in.gotPlt->getVA();<br>
+ write32le(buf + 2, gotPlt + 4);<br>
+ write32le(buf + 8, gotPlt + 8);<br>
}<br>
<br>
-void X86::writePlt(uint8_t *Buf, uint64_t GotPltEntryAddr,<br>
- uint64_t PltEntryAddr, int32_t Index,<br>
- unsigned RelOff) const {<br>
- if (Config->Pic) {<br>
- const uint8_t Inst[] = {<br>
+void X86::writePlt(uint8_t *buf, uint64_t gotPltEntryAddr,<br>
+ uint64_t pltEntryAddr, int32_t index,<br>
+ unsigned relOff) const {<br>
+ if (config->isPic) {<br>
+ const uint8_t inst[] = {<br>
0xff, 0xa3, 0, 0, 0, 0, // jmp *foo@GOT(%ebx)<br>
0x68, 0, 0, 0, 0, // pushl $reloc_offset<br>
0xe9, 0, 0, 0, 0, // jmp .PLT0@PC<br>
};<br>
- memcpy(Buf, Inst, sizeof(Inst));<br>
- write32le(Buf + 2, GotPltEntryAddr - In.GotPlt->getVA());<br>
+ memcpy(buf, inst, sizeof(inst));<br>
+ write32le(buf + 2, gotPltEntryAddr - in.gotPlt->getVA());<br>
} else {<br>
- const uint8_t Inst[] = {<br>
+ const uint8_t inst[] = {<br>
0xff, 0x25, 0, 0, 0, 0, // jmp *foo@GOT<br>
0x68, 0, 0, 0, 0, // pushl $reloc_offset<br>
0xe9, 0, 0, 0, 0, // jmp .PLT0@PC<br>
};<br>
- memcpy(Buf, Inst, sizeof(Inst));<br>
- write32le(Buf + 2, GotPltEntryAddr);<br>
+ memcpy(buf, inst, sizeof(inst));<br>
+ write32le(buf + 2, gotPltEntryAddr);<br>
}<br>
<br>
- write32le(Buf + 7, RelOff);<br>
- write32le(Buf + 12, -PltHeaderSize - PltEntrySize * Index - 16);<br>
+ write32le(buf + 7, relOff);<br>
+ write32le(buf + 12, -pltHeaderSize - pltEntrySize * index - 16);<br>
}<br>
<br>
-int64_t X86::getImplicitAddend(const uint8_t *Buf, RelType Type) const {<br>
- switch (Type) {<br>
+int64_t X86::getImplicitAddend(const uint8_t *buf, RelType type) const {<br>
+ switch (type) {<br>
case R_386_8:<br>
case R_386_PC8:<br>
- return SignExtend64<8>(*Buf);<br>
+ return SignExtend64<8>(*buf);<br>
case R_386_16:<br>
case R_386_PC16:<br>
- return SignExtend64<16>(read16le(Buf));<br>
+ return SignExtend64<16>(read16le(buf));<br>
case R_386_32:<br>
case R_386_GOT32:<br>
case R_386_GOT32X:<br>
@@ -254,28 +254,28 @@ int64_t X86::getImplicitAddend(const uin<br>
case R_386_PLT32:<br>
case R_386_TLS_LDO_32:<br>
case R_386_TLS_LE:<br>
- return SignExtend64<32>(read32le(Buf));<br>
+ return SignExtend64<32>(read32le(buf));<br>
default:<br>
return 0;<br>
}<br>
}<br>
<br>
-void X86::relocateOne(uint8_t *Loc, RelType Type, uint64_t Val) const {<br>
- switch (Type) {<br>
+void X86::relocateOne(uint8_t *loc, RelType type, uint64_t val) const {<br>
+ switch (type) {<br>
case R_386_8:<br>
// R_386_{PC,}{8,16} are not part of the i386 psABI, but they are<br>
// being used for some 16-bit programs such as boot loaders, so<br>
// we want to support them.<br>
- checkIntUInt(Loc, Val, 8, Type);<br>
- *Loc = Val;<br>
+ checkIntUInt(loc, val, 8, type);<br>
+ *loc = val;<br>
break;<br>
case R_386_PC8:<br>
- checkInt(Loc, Val, 8, Type);<br>
- *Loc = Val;<br>
+ checkInt(loc, val, 8, type);<br>
+ *loc = val;<br>
break;<br>
case R_386_16:<br>
- checkIntUInt(Loc, Val, 16, Type);<br>
- write16le(Loc, Val);<br>
+ checkIntUInt(loc, val, 16, type);<br>
+ write16le(loc, val);<br>
break;<br>
case R_386_PC16:<br>
// R_386_PC16 is normally used with 16 bit code. In that situation<br>
@@ -288,8 +288,8 @@ void X86::relocateOne(uint8_t *Loc, RelT<br>
// current location subtracted from it.<br>
// We just check that Val fits in 17 bits. This misses some cases, but<br>
// should have no false positives.<br>
- checkInt(Loc, Val, 17, Type);<br>
- write16le(Loc, Val);<br>
+ checkInt(loc, val, 17, type);<br>
+ write16le(loc, val);<br>
break;<br>
case R_386_32:<br>
case R_386_GOT32:<br>
@@ -310,86 +310,86 @@ void X86::relocateOne(uint8_t *Loc, RelT<br>
case R_386_TLS_LE_32:<br>
case R_386_TLS_TPOFF:<br>
case R_386_TLS_TPOFF32:<br>
- checkInt(Loc, Val, 32, Type);<br>
- write32le(Loc, Val);<br>
+ checkInt(loc, val, 32, type);<br>
+ write32le(loc, val);<br>
break;<br>
default:<br>
llvm_unreachable("unknown relocation");<br>
}<br>
}<br>
<br>
-void X86::relaxTlsGdToLe(uint8_t *Loc, RelType Type, uint64_t Val) const {<br>
+void X86::relaxTlsGdToLe(uint8_t *loc, RelType type, uint64_t val) const {<br>
// Convert<br>
// leal x@tlsgd(, %ebx, 1),<br>
// call __tls_get_addr@plt<br>
// to<br>
// movl %gs:0,%eax<br>
// subl $x@ntpoff,%eax<br>
- const uint8_t Inst[] = {<br>
+ const uint8_t inst[] = {<br>
0x65, 0xa1, 0x00, 0x00, 0x00, 0x00, // movl %gs:0, %eax<br>
0x81, 0xe8, 0, 0, 0, 0, // subl Val(%ebx), %eax<br>
};<br>
- memcpy(Loc - 3, Inst, sizeof(Inst));<br>
- write32le(Loc + 5, Val);<br>
+ memcpy(loc - 3, inst, sizeof(inst));<br>
+ write32le(loc + 5, val);<br>
}<br>
<br>
-void X86::relaxTlsGdToIe(uint8_t *Loc, RelType Type, uint64_t Val) const {<br>
+void X86::relaxTlsGdToIe(uint8_t *loc, RelType type, uint64_t val) const {<br>
// Convert<br>
// leal x@tlsgd(, %ebx, 1),<br>
// call __tls_get_addr@plt<br>
// to<br>
// movl %gs:0, %eax<br>
// addl x@gotntpoff(%ebx), %eax<br>
- const uint8_t Inst[] = {<br>
+ const uint8_t inst[] = {<br>
0x65, 0xa1, 0x00, 0x00, 0x00, 0x00, // movl %gs:0, %eax<br>
0x03, 0x83, 0, 0, 0, 0, // addl Val(%ebx), %eax<br>
};<br>
- memcpy(Loc - 3, Inst, sizeof(Inst));<br>
- write32le(Loc + 5, Val);<br>
+ memcpy(loc - 3, inst, sizeof(inst));<br>
+ write32le(loc + 5, val);<br>
}<br>
<br>
// In some conditions, relocations can be optimized to avoid using GOT.<br>
// This function does that for Initial Exec to Local Exec case.<br>
-void X86::relaxTlsIeToLe(uint8_t *Loc, RelType Type, uint64_t Val) const {<br>
+void X86::relaxTlsIeToLe(uint8_t *loc, RelType type, uint64_t val) const {<br>
// Ulrich's document section 6.2 says that @gotntpoff can<br>
// be used with MOVL or ADDL instructions.<br>
// @indntpoff is similar to @gotntpoff, but for use in<br>
// position dependent code.<br>
- uint8_t Reg = (Loc[-1] >> 3) & 7;<br>
+ uint8_t reg = (loc[-1] >> 3) & 7;<br>
<br>
- if (Type == R_386_TLS_IE) {<br>
- if (Loc[-1] == 0xa1) {<br>
+ if (type == R_386_TLS_IE) {<br>
+ if (loc[-1] == 0xa1) {<br>
// "movl foo@indntpoff,%eax" -> "movl $foo,%eax"<br>
// This case is different from the generic case below because<br>
// this is a 5 byte instruction while below is 6 bytes.<br>
- Loc[-1] = 0xb8;<br>
- } else if (Loc[-2] == 0x8b) {<br>
+ loc[-1] = 0xb8;<br>
+ } else if (loc[-2] == 0x8b) {<br>
// "movl foo@indntpoff,%reg" -> "movl $foo,%reg"<br>
- Loc[-2] = 0xc7;<br>
- Loc[-1] = 0xc0 | Reg;<br>
+ loc[-2] = 0xc7;<br>
+ loc[-1] = 0xc0 | reg;<br>
} else {<br>
// "addl foo@indntpoff,%reg" -> "addl $foo,%reg"<br>
- Loc[-2] = 0x81;<br>
- Loc[-1] = 0xc0 | Reg;<br>
+ loc[-2] = 0x81;<br>
+ loc[-1] = 0xc0 | reg;<br>
}<br>
} else {<br>
- assert(Type == R_386_TLS_GOTIE);<br>
- if (Loc[-2] == 0x8b) {<br>
+ assert(type == R_386_TLS_GOTIE);<br>
+ if (loc[-2] == 0x8b) {<br>
// "movl foo@gottpoff(%rip),%reg" -> "movl $foo,%reg"<br>
- Loc[-2] = 0xc7;<br>
- Loc[-1] = 0xc0 | Reg;<br>
+ loc[-2] = 0xc7;<br>
+ loc[-1] = 0xc0 | reg;<br>
} else {<br>
// "addl foo@gotntpoff(%rip),%reg" -> "leal foo(%reg),%reg"<br>
- Loc[-2] = 0x8d;<br>
- Loc[-1] = 0x80 | (Reg << 3) | Reg;<br>
+ loc[-2] = 0x8d;<br>
+ loc[-1] = 0x80 | (reg << 3) | reg;<br>
}<br>
}<br>
- write32le(Loc, Val);<br>
+ write32le(loc, val);<br>
}<br>
<br>
-void X86::relaxTlsLdToLe(uint8_t *Loc, RelType Type, uint64_t Val) const {<br>
- if (Type == R_386_TLS_LDO_32) {<br>
- write32le(Loc, Val);<br>
+void X86::relaxTlsLdToLe(uint8_t *loc, RelType type, uint64_t val) const {<br>
+ if (type == R_386_TLS_LDO_32) {<br>
+ write32le(loc, val);<br>
return;<br>
}<br>
<br>
@@ -400,45 +400,45 @@ void X86::relaxTlsLdToLe(uint8_t *Loc, R<br>
// movl %gs:0,%eax<br>
// nop<br>
// leal 0(%esi,1),%esi<br>
- const uint8_t Inst[] = {<br>
+ const uint8_t inst[] = {<br>
0x65, 0xa1, 0x00, 0x00, 0x00, 0x00, // movl %gs:0,%eax<br>
0x90, // nop<br>
0x8d, 0x74, 0x26, 0x00, // leal 0(%esi,1),%esi<br>
};<br>
- memcpy(Loc - 2, Inst, sizeof(Inst));<br>
+ memcpy(loc - 2, inst, sizeof(inst));<br>
}<br>
<br>
namespace {<br>
class RetpolinePic : public X86 {<br>
public:<br>
RetpolinePic();<br>
- void writeGotPlt(uint8_t *Buf, const Symbol &S) const override;<br>
- void writePltHeader(uint8_t *Buf) const override;<br>
- void writePlt(uint8_t *Buf, uint64_t GotPltEntryAddr, uint64_t PltEntryAddr,<br>
- int32_t Index, unsigned RelOff) const override;<br>
+ void writeGotPlt(uint8_t *buf, const Symbol &s) const override;<br>
+ void writePltHeader(uint8_t *buf) const override;<br>
+ void writePlt(uint8_t *buf, uint64_t gotPltEntryAddr, uint64_t pltEntryAddr,<br>
+ int32_t index, unsigned relOff) const override;<br>
};<br>
<br>
class RetpolineNoPic : public X86 {<br>
public:<br>
RetpolineNoPic();<br>
- void writeGotPlt(uint8_t *Buf, const Symbol &S) const override;<br>
- void writePltHeader(uint8_t *Buf) const override;<br>
- void writePlt(uint8_t *Buf, uint64_t GotPltEntryAddr, uint64_t PltEntryAddr,<br>
- int32_t Index, unsigned RelOff) const override;<br>
+ void writeGotPlt(uint8_t *buf, const Symbol &s) const override;<br>
+ void writePltHeader(uint8_t *buf) const override;<br>
+ void writePlt(uint8_t *buf, uint64_t gotPltEntryAddr, uint64_t pltEntryAddr,<br>
+ int32_t index, unsigned relOff) const override;<br>
};<br>
} // namespace<br>
<br>
RetpolinePic::RetpolinePic() {<br>
- PltHeaderSize = 48;<br>
- PltEntrySize = 32;<br>
+ pltHeaderSize = 48;<br>
+ pltEntrySize = 32;<br>
}<br>
<br>
-void RetpolinePic::writeGotPlt(uint8_t *Buf, const Symbol &S) const {<br>
- write32le(Buf, S.getPltVA() + 17);<br>
+void RetpolinePic::writeGotPlt(uint8_t *buf, const Symbol &s) const {<br>
+ write32le(buf, s.getPltVA() + 17);<br>
}<br>
<br>
-void RetpolinePic::writePltHeader(uint8_t *Buf) const {<br>
- const uint8_t Insn[] = {<br>
+void RetpolinePic::writePltHeader(uint8_t *buf) const {<br>
+ const uint8_t insn[] = {<br>
0xff, 0xb3, 4, 0, 0, 0, // 0: pushl 4(%ebx)<br>
0x50, // 6: pushl %eax<br>
0x8b, 0x83, 8, 0, 0, 0, // 7: mov 8(%ebx), %eax<br>
@@ -455,13 +455,13 @@ void RetpolinePic::writePltHeader(uint8_<br>
0xc3, // 2e: ret<br>
0xcc, // 2f: int3; padding<br>
};<br>
- memcpy(Buf, Insn, sizeof(Insn));<br>
+ memcpy(buf, insn, sizeof(insn));<br>
}<br>
<br>
-void RetpolinePic::writePlt(uint8_t *Buf, uint64_t GotPltEntryAddr,<br>
- uint64_t PltEntryAddr, int32_t Index,<br>
- unsigned RelOff) const {<br>
- const uint8_t Insn[] = {<br>
+void RetpolinePic::writePlt(uint8_t *buf, uint64_t gotPltEntryAddr,<br>
+ uint64_t pltEntryAddr, int32_t index,<br>
+ unsigned relOff) const {<br>
+ const uint8_t insn[] = {<br>
0x50, // pushl %eax<br>
0x8b, 0x83, 0, 0, 0, 0, // mov foo@GOT(%ebx), %eax<br>
0xe8, 0, 0, 0, 0, // call plt+0x20<br>
@@ -470,28 +470,28 @@ void RetpolinePic::writePlt(uint8_t *Buf<br>
0xe9, 0, 0, 0, 0, // jmp plt+0<br>
0xcc, 0xcc, 0xcc, 0xcc, 0xcc, // int3; padding<br>
};<br>
- memcpy(Buf, Insn, sizeof(Insn));<br>
+ memcpy(buf, insn, sizeof(insn));<br>
<br>
- uint32_t Ebx = In.GotPlt->getVA();<br>
- unsigned Off = PltHeaderSize + PltEntrySize * Index;<br>
- write32le(Buf + 3, GotPltEntryAddr - Ebx);<br>
- write32le(Buf + 8, -Off - 12 + 32);<br>
- write32le(Buf + 13, -Off - 17 + 18);<br>
- write32le(Buf + 18, RelOff);<br>
- write32le(Buf + 23, -Off - 27);<br>
+ uint32_t ebx = in.gotPlt->getVA();<br>
+ unsigned off = pltHeaderSize + pltEntrySize * index;<br>
+ write32le(buf + 3, gotPltEntryAddr - ebx);<br>
+ write32le(buf + 8, -off - 12 + 32);<br>
+ write32le(buf + 13, -off - 17 + 18);<br>
+ write32le(buf + 18, relOff);<br>
+ write32le(buf + 23, -off - 27);<br>
}<br>
<br>
RetpolineNoPic::RetpolineNoPic() {<br>
- PltHeaderSize = 48;<br>
- PltEntrySize = 32;<br>
+ pltHeaderSize = 48;<br>
+ pltEntrySize = 32;<br>
}<br>
<br>
-void RetpolineNoPic::writeGotPlt(uint8_t *Buf, const Symbol &S) const {<br>
- write32le(Buf, S.getPltVA() + 16);<br>
+void RetpolineNoPic::writeGotPlt(uint8_t *buf, const Symbol &s) const {<br>
+ write32le(buf, s.getPltVA() + 16);<br>
}<br>
<br>
-void RetpolineNoPic::writePltHeader(uint8_t *Buf) const {<br>
- const uint8_t Insn[] = {<br>
+void RetpolineNoPic::writePltHeader(uint8_t *buf) const {<br>
+ const uint8_t insn[] = {<br>
0xff, 0x35, 0, 0, 0, 0, // 0: pushl GOTPLT+4<br>
0x50, // 6: pushl %eax<br>
0xa1, 0, 0, 0, 0, // 7: mov GOTPLT+8, %eax<br>
@@ -509,17 +509,17 @@ void RetpolineNoPic::writePltHeader(uint<br>
0xc3, // 2e: ret<br>
0xcc, // 2f: int3; padding<br>
};<br>
- memcpy(Buf, Insn, sizeof(Insn));<br>
+ memcpy(buf, insn, sizeof(insn));<br>
<br>
- uint32_t GotPlt = In.GotPlt->getVA();<br>
- write32le(Buf + 2, GotPlt + 4);<br>
- write32le(Buf + 8, GotPlt + 8);<br>
+ uint32_t gotPlt = in.gotPlt->getVA();<br>
+ write32le(buf + 2, gotPlt + 4);<br>
+ write32le(buf + 8, gotPlt + 8);<br>
}<br>
<br>
-void RetpolineNoPic::writePlt(uint8_t *Buf, uint64_t GotPltEntryAddr,<br>
- uint64_t PltEntryAddr, int32_t Index,<br>
- unsigned RelOff) const {<br>
- const uint8_t Insn[] = {<br>
+void RetpolineNoPic::writePlt(uint8_t *buf, uint64_t gotPltEntryAddr,<br>
+ uint64_t pltEntryAddr, int32_t index,<br>
+ unsigned relOff) const {<br>
+ const uint8_t insn[] = {<br>
0x50, // 0: pushl %eax<br>
0xa1, 0, 0, 0, 0, // 1: mov foo_in_GOT, %eax<br>
0xe8, 0, 0, 0, 0, // 6: call plt+0x20<br>
@@ -529,26 +529,26 @@ void RetpolineNoPic::writePlt(uint8_t *B<br>
0xcc, 0xcc, 0xcc, 0xcc, 0xcc, // 1a: int3; padding<br>
0xcc, // 1f: int3; padding<br>
};<br>
- memcpy(Buf, Insn, sizeof(Insn));<br>
+ memcpy(buf, insn, sizeof(insn));<br>
<br>
- unsigned Off = PltHeaderSize + PltEntrySize * Index;<br>
- write32le(Buf + 2, GotPltEntryAddr);<br>
- write32le(Buf + 7, -Off - 11 + 32);<br>
- write32le(Buf + 12, -Off - 16 + 17);<br>
- write32le(Buf + 17, RelOff);<br>
- write32le(Buf + 22, -Off - 26);<br>
+ unsigned off = pltHeaderSize + pltEntrySize * index;<br>
+ write32le(buf + 2, gotPltEntryAddr);<br>
+ write32le(buf + 7, -off - 11 + 32);<br>
+ write32le(buf + 12, -off - 16 + 17);<br>
+ write32le(buf + 17, relOff);<br>
+ write32le(buf + 22, -off - 26);<br>
}<br>
<br>
TargetInfo *elf::getX86TargetInfo() {<br>
- if (Config->ZRetpolineplt) {<br>
- if (Config->Pic) {<br>
- static RetpolinePic T;<br>
- return &T;<br>
+ if (config->zRetpolineplt) {<br>
+ if (config->isPic) {<br>
+ static RetpolinePic t;<br>
+ return &t;<br>
}<br>
- static RetpolineNoPic T;<br>
- return &T;<br>
+ static RetpolineNoPic t;<br>
+ return &t;<br>
}<br>
<br>
- static X86 T;<br>
- return &T;<br>
+ static X86 t;<br>
+ return &t;<br>
}<br>
<br>
Modified: lld/trunk/ELF/Arch/X86_64.cpp<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_ELF_Arch_X86-5F64.cpp-3Frev-3D365595-26r1-3D365594-26r2-3D365595-26view-3Ddiff&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=TGAOZ7veH0Ul105s3GGTO0vrS286zSLemA1NY1QmSc4&e=" rel="noreferrer" target="_blank">https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_ELF_Arch_X86-5F64.cpp-3Frev-3D365595-26r1-3D365594-26r2-3D365595-26view-3Ddiff&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=TGAOZ7veH0Ul105s3GGTO0vrS286zSLemA1NY1QmSc4&e=</a> <br>
==============================================================================<br>
--- lld/trunk/ELF/Arch/X86_64.cpp (original)<br>
+++ lld/trunk/ELF/Arch/X86_64.cpp Tue Jul 9 22:00:37 2019<br>
@@ -25,58 +25,58 @@ namespace {<br>
class X86_64 : public TargetInfo {<br>
public:<br>
X86_64();<br>
- int getTlsGdRelaxSkip(RelType Type) const override;<br>
- RelExpr getRelExpr(RelType Type, const Symbol &S,<br>
- const uint8_t *Loc) const override;<br>
- RelType getDynRel(RelType Type) const override;<br>
- void writeGotPltHeader(uint8_t *Buf) const override;<br>
- void writeGotPlt(uint8_t *Buf, const Symbol &S) const override;<br>
- void writePltHeader(uint8_t *Buf) const override;<br>
- void writePlt(uint8_t *Buf, uint64_t GotPltEntryAddr, uint64_t PltEntryAddr,<br>
- int32_t Index, unsigned RelOff) const override;<br>
- void relocateOne(uint8_t *Loc, RelType Type, uint64_t Val) const override;<br>
-<br>
- RelExpr adjustRelaxExpr(RelType Type, const uint8_t *Data,<br>
- RelExpr Expr) const override;<br>
- void relaxGot(uint8_t *Loc, RelType Type, uint64_t Val) const override;<br>
- void relaxTlsGdToIe(uint8_t *Loc, RelType Type, uint64_t Val) const override;<br>
- void relaxTlsGdToLe(uint8_t *Loc, RelType Type, uint64_t Val) const override;<br>
- void relaxTlsIeToLe(uint8_t *Loc, RelType Type, uint64_t Val) const override;<br>
- void relaxTlsLdToLe(uint8_t *Loc, RelType Type, uint64_t Val) const override;<br>
- bool adjustPrologueForCrossSplitStack(uint8_t *Loc, uint8_t *End,<br>
- uint8_t StOther) const override;<br>
+ int getTlsGdRelaxSkip(RelType type) const override;<br>
+ RelExpr getRelExpr(RelType type, const Symbol &s,<br>
+ const uint8_t *loc) const override;<br>
+ RelType getDynRel(RelType type) const override;<br>
+ void writeGotPltHeader(uint8_t *buf) const override;<br>
+ void writeGotPlt(uint8_t *buf, const Symbol &s) const override;<br>
+ void writePltHeader(uint8_t *buf) const override;<br>
+ void writePlt(uint8_t *buf, uint64_t gotPltEntryAddr, uint64_t pltEntryAddr,<br>
+ int32_t index, unsigned relOff) const override;<br>
+ void relocateOne(uint8_t *loc, RelType type, uint64_t val) const override;<br>
+<br>
+ RelExpr adjustRelaxExpr(RelType type, const uint8_t *data,<br>
+ RelExpr expr) const override;<br>
+ void relaxGot(uint8_t *loc, RelType type, uint64_t val) const override;<br>
+ void relaxTlsGdToIe(uint8_t *loc, RelType type, uint64_t val) const override;<br>
+ void relaxTlsGdToLe(uint8_t *loc, RelType type, uint64_t val) const override;<br>
+ void relaxTlsIeToLe(uint8_t *loc, RelType type, uint64_t val) const override;<br>
+ void relaxTlsLdToLe(uint8_t *loc, RelType type, uint64_t val) const override;<br>
+ bool adjustPrologueForCrossSplitStack(uint8_t *loc, uint8_t *end,<br>
+ uint8_t stOther) const override;<br>
};<br>
} // namespace<br>
<br>
X86_64::X86_64() {<br>
- CopyRel = R_X86_64_COPY;<br>
- GotRel = R_X86_64_GLOB_DAT;<br>
- NoneRel = R_X86_64_NONE;<br>
- PltRel = R_X86_64_JUMP_SLOT;<br>
- RelativeRel = R_X86_64_RELATIVE;<br>
- IRelativeRel = R_X86_64_IRELATIVE;<br>
- SymbolicRel = R_X86_64_64;<br>
- TlsDescRel = R_X86_64_TLSDESC;<br>
- TlsGotRel = R_X86_64_TPOFF64;<br>
- TlsModuleIndexRel = R_X86_64_DTPMOD64;<br>
- TlsOffsetRel = R_X86_64_DTPOFF64;<br>
- PltEntrySize = 16;<br>
- PltHeaderSize = 16;<br>
- TrapInstr = {0xcc, 0xcc, 0xcc, 0xcc}; // 0xcc = INT3<br>
+ copyRel = R_X86_64_COPY;<br>
+ gotRel = R_X86_64_GLOB_DAT;<br>
+ noneRel = R_X86_64_NONE;<br>
+ pltRel = R_X86_64_JUMP_SLOT;<br>
+ relativeRel = R_X86_64_RELATIVE;<br>
+ iRelativeRel = R_X86_64_IRELATIVE;<br>
+ symbolicRel = R_X86_64_64;<br>
+ tlsDescRel = R_X86_64_TLSDESC;<br>
+ tlsGotRel = R_X86_64_TPOFF64;<br>
+ tlsModuleIndexRel = R_X86_64_DTPMOD64;<br>
+ tlsOffsetRel = R_X86_64_DTPOFF64;<br>
+ pltEntrySize = 16;<br>
+ pltHeaderSize = 16;<br>
+ trapInstr = {0xcc, 0xcc, 0xcc, 0xcc}; // 0xcc = INT3<br>
<br>
// Align to the large page size (known as a superpage or huge page).<br>
// FreeBSD automatically promotes large, superpage-aligned allocations.<br>
- DefaultImageBase = 0x200000;<br>
+ defaultImageBase = 0x200000;<br>
}<br>
<br>
-int X86_64::getTlsGdRelaxSkip(RelType Type) const { return 2; }<br>
+int X86_64::getTlsGdRelaxSkip(RelType type) const { return 2; }<br>
<br>
-RelExpr X86_64::getRelExpr(RelType Type, const Symbol &S,<br>
- const uint8_t *Loc) const {<br>
- if (Type == R_X86_64_GOTTPOFF)<br>
- Config->HasStaticTlsModel = true;<br>
+RelExpr X86_64::getRelExpr(RelType type, const Symbol &s,<br>
+ const uint8_t *loc) const {<br>
+ if (type == R_X86_64_GOTTPOFF)<br>
+ config->hasStaticTlsModel = true;<br>
<br>
- switch (Type) {<br>
+ switch (type) {<br>
case R_X86_64_8:<br>
case R_X86_64_16:<br>
case R_X86_64_32:<br>
@@ -122,62 +122,62 @@ RelExpr X86_64::getRelExpr(RelType Type,<br>
case R_X86_64_NONE:<br>
return R_NONE;<br>
default:<br>
- error(getErrorLocation(Loc) + "unknown relocation (" + Twine(Type) +<br>
- ") against symbol " + toString(S));<br>
+ error(getErrorLocation(loc) + "unknown relocation (" + Twine(type) +<br>
+ ") against symbol " + toString(s));<br>
return R_NONE;<br>
}<br>
}<br>
<br>
-void X86_64::writeGotPltHeader(uint8_t *Buf) const {<br>
+void X86_64::writeGotPltHeader(uint8_t *buf) const {<br>
// The first entry holds the value of _DYNAMIC. It is not clear why that is<br>
// required, but it is documented in the psabi and the glibc dynamic linker<br>
// seems to use it (note that this is relevant for linking ld.so, not any<br>
// other program).<br>
- write64le(Buf, Main->Dynamic->getVA());<br>
+ write64le(buf, mainPart->dynamic->getVA());<br>
}<br>
<br>
-void X86_64::writeGotPlt(uint8_t *Buf, const Symbol &S) const {<br>
+void X86_64::writeGotPlt(uint8_t *buf, const Symbol &s) const {<br>
// See comments in X86::writeGotPlt.<br>
- write64le(Buf, S.getPltVA() + 6);<br>
+ write64le(buf, s.getPltVA() + 6);<br>
}<br>
<br>
-void X86_64::writePltHeader(uint8_t *Buf) const {<br>
- const uint8_t PltData[] = {<br>
+void X86_64::writePltHeader(uint8_t *buf) const {<br>
+ const uint8_t pltData[] = {<br>
0xff, 0x35, 0, 0, 0, 0, // pushq GOTPLT+8(%rip)<br>
0xff, 0x25, 0, 0, 0, 0, // jmp *GOTPLT+16(%rip)<br>
0x0f, 0x1f, 0x40, 0x00, // nop<br>
};<br>
- memcpy(Buf, PltData, sizeof(PltData));<br>
- uint64_t GotPlt = In.GotPlt->getVA();<br>
- uint64_t Plt = In.Plt->getVA();<br>
- write32le(Buf + 2, GotPlt - Plt + 2); // GOTPLT+8<br>
- write32le(Buf + 8, GotPlt - Plt + 4); // GOTPLT+16<br>
+ memcpy(buf, pltData, sizeof(pltData));<br>
+ uint64_t gotPlt = in.gotPlt->getVA();<br>
+ uint64_t plt = in.plt->getVA();<br>
+ write32le(buf + 2, gotPlt - plt + 2); // GOTPLT+8<br>
+ write32le(buf + 8, gotPlt - plt + 4); // GOTPLT+16<br>
}<br>
<br>
-void X86_64::writePlt(uint8_t *Buf, uint64_t GotPltEntryAddr,<br>
- uint64_t PltEntryAddr, int32_t Index,<br>
- unsigned RelOff) const {<br>
- const uint8_t Inst[] = {<br>
+void X86_64::writePlt(uint8_t *buf, uint64_t gotPltEntryAddr,<br>
+ uint64_t pltEntryAddr, int32_t index,<br>
+ unsigned relOff) const {<br>
+ const uint8_t inst[] = {<br>
0xff, 0x25, 0, 0, 0, 0, // jmpq *got(%rip)<br>
0x68, 0, 0, 0, 0, // pushq <relocation index><br>
0xe9, 0, 0, 0, 0, // jmpq plt[0]<br>
};<br>
- memcpy(Buf, Inst, sizeof(Inst));<br>
+ memcpy(buf, inst, sizeof(inst));<br>
<br>
- write32le(Buf + 2, GotPltEntryAddr - PltEntryAddr - 6);<br>
- write32le(Buf + 7, Index);<br>
- write32le(Buf + 12, -PltHeaderSize - PltEntrySize * Index - 16);<br>
+ write32le(buf + 2, gotPltEntryAddr - pltEntryAddr - 6);<br>
+ write32le(buf + 7, index);<br>
+ write32le(buf + 12, -pltHeaderSize - pltEntrySize * index - 16);<br>
}<br>
<br>
-RelType X86_64::getDynRel(RelType Type) const {<br>
- if (Type == R_X86_64_64 || Type == R_X86_64_PC64 || Type == R_X86_64_SIZE32 ||<br>
- Type == R_X86_64_SIZE64)<br>
- return Type;<br>
+RelType X86_64::getDynRel(RelType type) const {<br>
+ if (type == R_X86_64_64 || type == R_X86_64_PC64 || type == R_X86_64_SIZE32 ||<br>
+ type == R_X86_64_SIZE64)<br>
+ return type;<br>
return R_X86_64_NONE;<br>
}<br>
<br>
-void X86_64::relaxTlsGdToLe(uint8_t *Loc, RelType Type, uint64_t Val) const {<br>
- if (Type == R_X86_64_TLSGD) {<br>
+void X86_64::relaxTlsGdToLe(uint8_t *loc, RelType type, uint64_t val) const {<br>
+ if (type == R_X86_64_TLSGD) {<br>
// Convert<br>
// .byte 0x66<br>
// leaq x@tlsgd(%rip), %rdi<br>
@@ -185,39 +185,39 @@ void X86_64::relaxTlsGdToLe(uint8_t *Loc<br>
// rex64<br>
// call __tls_get_addr@plt<br>
// to the following two instructions.<br>
- const uint8_t Inst[] = {<br>
+ const uint8_t inst[] = {<br>
0x64, 0x48, 0x8b, 0x04, 0x25, 0x00, 0x00,<br>
0x00, 0x00, // mov %fs:0x0,%rax<br>
0x48, 0x8d, 0x80, 0, 0, 0, 0, // lea x@tpoff,%rax<br>
};<br>
- memcpy(Loc - 4, Inst, sizeof(Inst));<br>
+ memcpy(loc - 4, inst, sizeof(inst));<br>
<br>
// The original code used a pc relative relocation and so we have to<br>
// compensate for the -4 in had in the addend.<br>
- write32le(Loc + 8, Val + 4);<br>
+ write32le(loc + 8, val + 4);<br>
} else {<br>
// Convert<br>
// lea x@tlsgd(%rip), %rax<br>
// call *(%rax)<br>
// to the following two instructions.<br>
- assert(Type == R_X86_64_GOTPC32_TLSDESC);<br>
- if (memcmp(Loc - 3, "\x48\x8d\x05", 3)) {<br>
- error(getErrorLocation(Loc - 3) + "R_X86_64_GOTPC32_TLSDESC must be used "<br>
+ assert(type == R_X86_64_GOTPC32_TLSDESC);<br>
+ if (memcmp(loc - 3, "\x48\x8d\x05", 3)) {<br>
+ error(getErrorLocation(loc - 3) + "R_X86_64_GOTPC32_TLSDESC must be used "<br>
"in callq *x@tlsdesc(%rip), %rax");<br>
return;<br>
}<br>
// movq $x@tpoff(%rip),%rax<br>
- Loc[-2] = 0xc7;<br>
- Loc[-1] = 0xc0;<br>
- write32le(Loc, Val + 4);<br>
+ loc[-2] = 0xc7;<br>
+ loc[-1] = 0xc0;<br>
+ write32le(loc, val + 4);<br>
// xchg ax,ax<br>
- Loc[4] = 0x66;<br>
- Loc[5] = 0x90;<br>
+ loc[4] = 0x66;<br>
+ loc[5] = 0x90;<br>
}<br>
}<br>
<br>
-void X86_64::relaxTlsGdToIe(uint8_t *Loc, RelType Type, uint64_t Val) const {<br>
- if (Type == R_X86_64_TLSGD) {<br>
+void X86_64::relaxTlsGdToIe(uint8_t *loc, RelType type, uint64_t val) const {<br>
+ if (type == R_X86_64_TLSGD) {<br>
// Convert<br>
// .byte 0x66<br>
// leaq x@tlsgd(%rip), %rdi<br>
@@ -225,96 +225,96 @@ void X86_64::relaxTlsGdToIe(uint8_t *Loc<br>
// rex64<br>
// call __tls_get_addr@plt<br>
// to the following two instructions.<br>
- const uint8_t Inst[] = {<br>
+ const uint8_t inst[] = {<br>
0x64, 0x48, 0x8b, 0x04, 0x25, 0x00, 0x00,<br>
0x00, 0x00, // mov %fs:0x0,%rax<br>
0x48, 0x03, 0x05, 0, 0, 0, 0, // addq x@gottpoff(%rip),%rax<br>
};<br>
- memcpy(Loc - 4, Inst, sizeof(Inst));<br>
+ memcpy(loc - 4, inst, sizeof(inst));<br>
<br>
// Both code sequences are PC relatives, but since we are moving the<br>
// constant forward by 8 bytes we have to subtract the value by 8.<br>
- write32le(Loc + 8, Val - 8);<br>
+ write32le(loc + 8, val - 8);<br>
} else {<br>
// Convert<br>
// lea x@tlsgd(%rip), %rax<br>
// call *(%rax)<br>
// to the following two instructions.<br>
- assert(Type == R_X86_64_GOTPC32_TLSDESC);<br>
- if (memcmp(Loc - 3, "\x48\x8d\x05", 3)) {<br>
- error(getErrorLocation(Loc - 3) + "R_X86_64_GOTPC32_TLSDESC must be used "<br>
+ assert(type == R_X86_64_GOTPC32_TLSDESC);<br>
+ if (memcmp(loc - 3, "\x48\x8d\x05", 3)) {<br>
+ error(getErrorLocation(loc - 3) + "R_X86_64_GOTPC32_TLSDESC must be used "<br>
"in callq *x@tlsdesc(%rip), %rax");<br>
return;<br>
}<br>
// movq x@gottpoff(%rip),%rax<br>
- Loc[-2] = 0x8b;<br>
- write32le(Loc, Val);<br>
+ loc[-2] = 0x8b;<br>
+ write32le(loc, val);<br>
// xchg ax,ax<br>
- Loc[4] = 0x66;<br>
- Loc[5] = 0x90;<br>
+ loc[4] = 0x66;<br>
+ loc[5] = 0x90;<br>
}<br>
}<br>
<br>
// In some conditions, R_X86_64_GOTTPOFF relocation can be optimized to<br>
// R_X86_64_TPOFF32 so that it does not use GOT.<br>
-void X86_64::relaxTlsIeToLe(uint8_t *Loc, RelType Type, uint64_t Val) const {<br>
- uint8_t *Inst = Loc - 3;<br>
- uint8_t Reg = Loc[-1] >> 3;<br>
- uint8_t *RegSlot = Loc - 1;<br>
+void X86_64::relaxTlsIeToLe(uint8_t *loc, RelType type, uint64_t val) const {<br>
+ uint8_t *inst = loc - 3;<br>
+ uint8_t reg = loc[-1] >> 3;<br>
+ uint8_t *regSlot = loc - 1;<br>
<br>
// Note that ADD with RSP or R12 is converted to ADD instead of LEA<br>
// because LEA with these registers needs 4 bytes to encode and thus<br>
// wouldn't fit the space.<br>
<br>
- if (memcmp(Inst, "\x48\x03\x25", 3) == 0) {<br>
+ if (memcmp(inst, "\x48\x03\x25", 3) == 0) {<br>
// "addq foo@gottpoff(%rip),%rsp" -> "addq $foo,%rsp"<br>
- memcpy(Inst, "\x48\x81\xc4", 3);<br>
- } else if (memcmp(Inst, "\x4c\x03\x25", 3) == 0) {<br>
+ memcpy(inst, "\x48\x81\xc4", 3);<br>
+ } else if (memcmp(inst, "\x4c\x03\x25", 3) == 0) {<br>
// "addq foo@gottpoff(%rip),%r12" -> "addq $foo,%r12"<br>
- memcpy(Inst, "\x49\x81\xc4", 3);<br>
- } else if (memcmp(Inst, "\x4c\x03", 2) == 0) {<br>
+ memcpy(inst, "\x49\x81\xc4", 3);<br>
+ } else if (memcmp(inst, "\x4c\x03", 2) == 0) {<br>
// "addq foo@gottpoff(%rip),%r[8-15]" -> "leaq foo(%r[8-15]),%r[8-15]"<br>
- memcpy(Inst, "\x4d\x8d", 2);<br>
- *RegSlot = 0x80 | (Reg << 3) | Reg;<br>
- } else if (memcmp(Inst, "\x48\x03", 2) == 0) {<br>
+ memcpy(inst, "\x4d\x8d", 2);<br>
+ *regSlot = 0x80 | (reg << 3) | reg;<br>
+ } else if (memcmp(inst, "\x48\x03", 2) == 0) {<br>
// "addq foo@gottpoff(%rip),%reg -> "leaq foo(%reg),%reg"<br>
- memcpy(Inst, "\x48\x8d", 2);<br>
- *RegSlot = 0x80 | (Reg << 3) | Reg;<br>
- } else if (memcmp(Inst, "\x4c\x8b", 2) == 0) {<br>
+ memcpy(inst, "\x48\x8d", 2);<br>
+ *regSlot = 0x80 | (reg << 3) | reg;<br>
+ } else if (memcmp(inst, "\x4c\x8b", 2) == 0) {<br>
// "movq foo@gottpoff(%rip),%r[8-15]" -> "movq $foo,%r[8-15]"<br>
- memcpy(Inst, "\x49\xc7", 2);<br>
- *RegSlot = 0xc0 | Reg;<br>
- } else if (memcmp(Inst, "\x48\x8b", 2) == 0) {<br>
+ memcpy(inst, "\x49\xc7", 2);<br>
+ *regSlot = 0xc0 | reg;<br>
+ } else if (memcmp(inst, "\x48\x8b", 2) == 0) {<br>
// "movq foo@gottpoff(%rip),%reg" -> "movq $foo,%reg"<br>
- memcpy(Inst, "\x48\xc7", 2);<br>
- *RegSlot = 0xc0 | Reg;<br>
+ memcpy(inst, "\x48\xc7", 2);<br>
+ *regSlot = 0xc0 | reg;<br>
} else {<br>
- error(getErrorLocation(Loc - 3) +<br>
+ error(getErrorLocation(loc - 3) +<br>
"R_X86_64_GOTTPOFF must be used in MOVQ or ADDQ instructions only");<br>
}<br>
<br>
// The original code used a PC relative relocation.<br>
// Need to compensate for the -4 it had in the addend.<br>
- write32le(Loc, Val + 4);<br>
+ write32le(loc, val + 4);<br>
}<br>
<br>
-void X86_64::relaxTlsLdToLe(uint8_t *Loc, RelType Type, uint64_t Val) const {<br>
- if (Type == R_X86_64_DTPOFF64) {<br>
- write64le(Loc, Val);<br>
+void X86_64::relaxTlsLdToLe(uint8_t *loc, RelType type, uint64_t val) const {<br>
+ if (type == R_X86_64_DTPOFF64) {<br>
+ write64le(loc, val);<br>
return;<br>
}<br>
- if (Type == R_X86_64_DTPOFF32) {<br>
- write32le(Loc, Val);<br>
+ if (type == R_X86_64_DTPOFF32) {<br>
+ write32le(loc, val);<br>
return;<br>
}<br>
<br>
- const uint8_t Inst[] = {<br>
+ const uint8_t inst[] = {<br>
0x66, 0x66, // .word 0x6666<br>
0x66, // .byte 0x66<br>
0x64, 0x48, 0x8b, 0x04, 0x25, 0x00, 0x00, 0x00, 0x00, // mov %fs:0,%rax<br>
};<br>
<br>
- if (Loc[4] == 0xe8) {<br>
+ if (loc[4] == 0xe8) {<br>
// Convert<br>
// leaq bar@tlsld(%rip), %rdi # 48 8d 3d <Loc><br>
// callq __tls_get_addr@PLT # e8 <disp32><br>
@@ -324,11 +324,11 @@ void X86_64::relaxTlsLdToLe(uint8_t *Loc<br>
// .byte 0x66<br>
// mov %fs:0,%rax<br>
// leaq bar@tpoff(%rax), %rcx<br>
- memcpy(Loc - 3, Inst, sizeof(Inst));<br>
+ memcpy(loc - 3, inst, sizeof(inst));<br>
return;<br>
}<br>
<br>
- if (Loc[4] == 0xff && Loc[5] == 0x15) {<br>
+ if (loc[4] == 0xff && loc[5] == 0x15) {<br>
// Convert<br>
// leaq x@tlsld(%rip),%rdi # 48 8d 3d <Loc><br>
// call *__tls_get_addr@GOTPCREL(%rip) # ff 15 <disp32><br>
@@ -337,36 +337,36 @@ void X86_64::relaxTlsLdToLe(uint8_t *Loc<br>
// movq %fs:0,%rax<br>
// See "Table 11.9: LD -> LE Code Transition (LP64)" in<br>
// <a href="https://urldefense.proofpoint.com/v2/url?u=https-3A__raw.githubusercontent.com_wiki_hjl-2Dtools_x86-2DpsABI_x86-2D64-2DpsABI-2D1.0.pdf&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=dCSIEZTA2rQv4Ih9njsVKtftDKD74swhRtAi89d7yRo&e=" rel="noreferrer" target="_blank">https://urldefense.proofpoint.com/v2/url?u=https-3A__raw.githubusercontent.com_wiki_hjl-2Dtools_x86-2DpsABI_x86-2D64-2DpsABI-2D1.0.pdf&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=dCSIEZTA2rQv4Ih9njsVKtftDKD74swhRtAi89d7yRo&e=</a> <br>
- Loc[-3] = 0x66;<br>
- memcpy(Loc - 2, Inst, sizeof(Inst));<br>
+ loc[-3] = 0x66;<br>
+ memcpy(loc - 2, inst, sizeof(inst));<br>
return;<br>
}<br>
<br>
- error(getErrorLocation(Loc - 3) +<br>
+ error(getErrorLocation(loc - 3) +<br>
"expected R_X86_64_PLT32 or R_X86_64_GOTPCRELX after R_X86_64_TLSLD");<br>
}<br>
<br>
-void X86_64::relocateOne(uint8_t *Loc, RelType Type, uint64_t Val) const {<br>
- switch (Type) {<br>
+void X86_64::relocateOne(uint8_t *loc, RelType type, uint64_t val) const {<br>
+ switch (type) {<br>
case R_X86_64_8:<br>
- checkIntUInt(Loc, Val, 8, Type);<br>
- *Loc = Val;<br>
+ checkIntUInt(loc, val, 8, type);<br>
+ *loc = val;<br>
break;<br>
case R_X86_64_PC8:<br>
- checkInt(Loc, Val, 8, Type);<br>
- *Loc = Val;<br>
+ checkInt(loc, val, 8, type);<br>
+ *loc = val;<br>
break;<br>
case R_X86_64_16:<br>
- checkIntUInt(Loc, Val, 16, Type);<br>
- write16le(Loc, Val);<br>
+ checkIntUInt(loc, val, 16, type);<br>
+ write16le(loc, val);<br>
break;<br>
case R_X86_64_PC16:<br>
- checkInt(Loc, Val, 16, Type);<br>
- write16le(Loc, Val);<br>
+ checkInt(loc, val, 16, type);<br>
+ write16le(loc, val);<br>
break;<br>
case R_X86_64_32:<br>
- checkUInt(Loc, Val, 32, Type);<br>
- write32le(Loc, Val);<br>
+ checkUInt(loc, val, 32, type);<br>
+ write32le(loc, val);<br>
break;<br>
case R_X86_64_32S:<br>
case R_X86_64_TPOFF32:<br>
@@ -383,8 +383,8 @@ void X86_64::relocateOne(uint8_t *Loc, R<br>
case R_X86_64_TLSLD:<br>
case R_X86_64_DTPOFF32:<br>
case R_X86_64_SIZE32:<br>
- checkInt(Loc, Val, 32, Type);<br>
- write32le(Loc, Val);<br>
+ checkInt(loc, val, 32, type);<br>
+ write32le(loc, val);<br>
break;<br>
case R_X86_64_64:<br>
case R_X86_64_DTPOFF64:<br>
@@ -393,37 +393,37 @@ void X86_64::relocateOne(uint8_t *Loc, R<br>
case R_X86_64_GOT64:<br>
case R_X86_64_GOTOFF64:<br>
case R_X86_64_GOTPC64:<br>
- write64le(Loc, Val);<br>
+ write64le(loc, val);<br>
break;<br>
default:<br>
llvm_unreachable("unknown relocation");<br>
}<br>
}<br>
<br>
-RelExpr X86_64::adjustRelaxExpr(RelType Type, const uint8_t *Data,<br>
- RelExpr RelExpr) const {<br>
- if (Type != R_X86_64_GOTPCRELX && Type != R_X86_64_REX_GOTPCRELX)<br>
- return RelExpr;<br>
- const uint8_t Op = Data[-2];<br>
- const uint8_t ModRm = Data[-1];<br>
+RelExpr X86_64::adjustRelaxExpr(RelType type, const uint8_t *data,<br>
+ RelExpr relExpr) const {<br>
+ if (type != R_X86_64_GOTPCRELX && type != R_X86_64_REX_GOTPCRELX)<br>
+ return relExpr;<br>
+ const uint8_t op = data[-2];<br>
+ const uint8_t modRm = data[-1];<br>
<br>
// FIXME: When PIC is disabled and foo is defined locally in the<br>
// lower 32 bit address space, memory operand in mov can be converted into<br>
// immediate operand. Otherwise, mov must be changed to lea. We support only<br>
// latter relaxation at this moment.<br>
- if (Op == 0x8b)<br>
+ if (op == 0x8b)<br>
return R_RELAX_GOT_PC;<br>
<br>
// Relax call and jmp.<br>
- if (Op == 0xff && (ModRm == 0x15 || ModRm == 0x25))<br>
+ if (op == 0xff && (modRm == 0x15 || modRm == 0x25))<br>
return R_RELAX_GOT_PC;<br>
<br>
// Relaxation of test, adc, add, and, cmp, or, sbb, sub, xor.<br>
// If PIC then no relaxation is available.<br>
// We also don't relax test/binop instructions without REX byte,<br>
// they are 32bit operations and not common to have.<br>
- assert(Type == R_X86_64_REX_GOTPCRELX);<br>
- return Config->Pic ? RelExpr : R_RELAX_GOT_PC_NOPIC;<br>
+ assert(type == R_X86_64_REX_GOTPCRELX);<br>
+ return config->isPic ? relExpr : R_RELAX_GOT_PC_NOPIC;<br>
}<br>
<br>
// A subset of relaxations can only be applied for no-PIC. This method<br>
@@ -431,11 +431,11 @@ RelExpr X86_64::adjustRelaxExpr(RelType<br>
// "Intel 64 and IA-32 Architectures Software Developer's Manual V2"<br>
// (<a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__www.intel.com_content_dam_www_public_us_en_documents_manuals_&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=sIEBEeFXuFPtqrzXsYt1Xiee8tYhUuv6AY5UmD7WjX0&e=" rel="noreferrer" target="_blank">https://urldefense.proofpoint.com/v2/url?u=http-3A__www.intel.com_content_dam_www_public_us_en_documents_manuals_&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=sIEBEeFXuFPtqrzXsYt1Xiee8tYhUuv6AY5UmD7WjX0&e=</a> <br>
// 64-ia-32-architectures-software-developer-instruction-set-reference-manual-325383.pdf)<br>
-static void relaxGotNoPic(uint8_t *Loc, uint64_t Val, uint8_t Op,<br>
- uint8_t ModRm) {<br>
- const uint8_t Rex = Loc[-3];<br>
+static void relaxGotNoPic(uint8_t *loc, uint64_t val, uint8_t op,<br>
+ uint8_t modRm) {<br>
+ const uint8_t rex = loc[-3];<br>
// Convert "test %reg, foo@GOTPCREL(%rip)" to "test $foo, %reg".<br>
- if (Op == 0x85) {<br>
+ if (op == 0x85) {<br>
// See "TEST-Logical Compare" (4-428 Vol. 2B),<br>
// TEST r/m64, r64 uses "full" ModR / M byte (no opcode extension).<br>
<br>
@@ -452,11 +452,11 @@ static void relaxGotNoPic(uint8_t *Loc,<br>
// 0x38 == 00 111 000 binary.<br>
// We transfer reg2 to reg1 here as operand.<br>
// See "2.1.3 ModR/M and SIB Bytes" (Vol. 2A 2-3).<br>
- Loc[-1] = 0xc0 | (ModRm & 0x38) >> 3; // ModR/M byte.<br>
+ loc[-1] = 0xc0 | (modRm & 0x38) >> 3; // ModR/M byte.<br>
<br>
// Change opcode from TEST r/m64, r64 to TEST r/m64, imm32<br>
// See "TEST-Logical Compare" (4-428 Vol. 2B).<br>
- Loc[-2] = 0xf7;<br>
+ loc[-2] = 0xf7;<br>
<br>
// Move R bit to the B bit in REX byte.<br>
// REX byte is encoded as 0100WRXB, where<br>
@@ -469,8 +469,8 @@ static void relaxGotNoPic(uint8_t *Loc,<br>
// REX.B This 1-bit value is an extension to the MODRM.rm field or the<br>
// SIB.base field.<br>
// See "2.2.1.2 More on REX Prefix Fields " (2-8 Vol. 2A).<br>
- Loc[-3] = (Rex & ~0x4) | (Rex & 0x4) >> 2;<br>
- write32le(Loc, Val);<br>
+ loc[-3] = (rex & ~0x4) | (rex & 0x4) >> 2;<br>
+ write32le(loc, val);<br>
return;<br>
}<br>
<br>
@@ -480,7 +480,7 @@ static void relaxGotNoPic(uint8_t *Loc,<br>
// Convert "binop foo@GOTPCREL(%rip), %reg" to "binop $foo, %reg".<br>
// Logic is close to one for test instruction above, but we also<br>
// write opcode extension here, see below for details.<br>
- Loc[-1] = 0xc0 | (ModRm & 0x38) >> 3 | (Op & 0x3c); // ModR/M byte.<br>
+ loc[-1] = 0xc0 | (modRm & 0x38) >> 3 | (op & 0x3c); // ModR/M byte.<br>
<br>
// Primary opcode is 0x81, opcode extension is one of:<br>
// 000b = ADD, 001b is OR, 010b is ADC, 011b is SBB,<br>
@@ -489,67 +489,67 @@ static void relaxGotNoPic(uint8_t *Loc,<br>
// See "3.2 INSTRUCTIONS (A-M)" (Vol. 2A 3-15),<br>
// "INSTRUCTION SET REFERENCE, N-Z" (Vol. 2B 4-1) for<br>
// descriptions about each operation.<br>
- Loc[-2] = 0x81;<br>
- Loc[-3] = (Rex & ~0x4) | (Rex & 0x4) >> 2;<br>
- write32le(Loc, Val);<br>
+ loc[-2] = 0x81;<br>
+ loc[-3] = (rex & ~0x4) | (rex & 0x4) >> 2;<br>
+ write32le(loc, val);<br>
}<br>
<br>
-void X86_64::relaxGot(uint8_t *Loc, RelType Type, uint64_t Val) const {<br>
- const uint8_t Op = Loc[-2];<br>
- const uint8_t ModRm = Loc[-1];<br>
+void X86_64::relaxGot(uint8_t *loc, RelType type, uint64_t val) const {<br>
+ const uint8_t op = loc[-2];<br>
+ const uint8_t modRm = loc[-1];<br>
<br>
// Convert "mov foo@GOTPCREL(%rip),%reg" to "lea foo(%rip),%reg".<br>
- if (Op == 0x8b) {<br>
- Loc[-2] = 0x8d;<br>
- write32le(Loc, Val);<br>
+ if (op == 0x8b) {<br>
+ loc[-2] = 0x8d;<br>
+ write32le(loc, val);<br>
return;<br>
}<br>
<br>
- if (Op != 0xff) {<br>
+ if (op != 0xff) {<br>
// We are relaxing a rip relative to an absolute, so compensate<br>
// for the old -4 addend.<br>
- assert(!Config->Pic);<br>
- relaxGotNoPic(Loc, Val + 4, Op, ModRm);<br>
+ assert(!config->isPic);<br>
+ relaxGotNoPic(loc, val + 4, op, modRm);<br>
return;<br>
}<br>
<br>
// Convert call/jmp instructions.<br>
- if (ModRm == 0x15) {<br>
+ if (modRm == 0x15) {<br>
// ABI says we can convert "call *foo@GOTPCREL(%rip)" to "nop; call foo".<br>
// Instead we convert to "addr32 call foo" where addr32 is an instruction<br>
// prefix. That makes result expression to be a single instruction.<br>
- Loc[-2] = 0x67; // addr32 prefix<br>
- Loc[-1] = 0xe8; // call<br>
- write32le(Loc, Val);<br>
+ loc[-2] = 0x67; // addr32 prefix<br>
+ loc[-1] = 0xe8; // call<br>
+ write32le(loc, val);<br>
return;<br>
}<br>
<br>
// Convert "jmp *foo@GOTPCREL(%rip)" to "jmp foo; nop".<br>
// jmp doesn't return, so it is fine to use nop here, it is just a stub.<br>
- assert(ModRm == 0x25);<br>
- Loc[-2] = 0xe9; // jmp<br>
- Loc[3] = 0x90; // nop<br>
- write32le(Loc - 1, Val + 1);<br>
+ assert(modRm == 0x25);<br>
+ loc[-2] = 0xe9; // jmp<br>
+ loc[3] = 0x90; // nop<br>
+ write32le(loc - 1, val + 1);<br>
}<br>
<br>
// A split-stack prologue starts by checking the amount of stack remaining<br>
// in one of two ways:<br>
// A) Comparing of the stack pointer to a field in the tcb.<br>
// B) Or a load of a stack pointer offset with an lea to r10 or r11.<br>
-bool X86_64::adjustPrologueForCrossSplitStack(uint8_t *Loc, uint8_t *End,<br>
- uint8_t StOther) const {<br>
- if (!Config->Is64) {<br>
+bool X86_64::adjustPrologueForCrossSplitStack(uint8_t *loc, uint8_t *end,<br>
+ uint8_t stOther) const {<br>
+ if (!config->is64) {<br>
error("Target doesn't support split stacks.");<br>
return false;<br>
}<br>
<br>
- if (Loc + 8 >= End)<br>
+ if (loc + 8 >= end)<br>
return false;<br>
<br>
// Replace "cmp %fs:0x70,%rsp" and subsequent branch<br>
// with "stc, nopl 0x0(%rax,%rax,1)"<br>
- if (memcmp(Loc, "\x64\x48\x3b\x24\x25", 5) == 0) {<br>
- memcpy(Loc, "\xf9\x0f\x1f\x84\x00\x00\x00\x00", 8);<br>
+ if (memcmp(loc, "\x64\x48\x3b\x24\x25", 5) == 0) {<br>
+ memcpy(loc, "\xf9\x0f\x1f\x84\x00\x00\x00\x00", 8);<br>
return true;<br>
}<br>
<br>
@@ -557,11 +557,11 @@ bool X86_64::adjustPrologueForCrossSplit<br>
// be r10 or r11. The lea instruction feeds a subsequent compare which checks<br>
// if there is X available stack space. Making X larger effectively reserves<br>
// that much additional space. The stack grows downward so subtract the value.<br>
- if (memcmp(Loc, "\x4c\x8d\x94\x24", 4) == 0 ||<br>
- memcmp(Loc, "\x4c\x8d\x9c\x24", 4) == 0) {<br>
+ if (memcmp(loc, "\x4c\x8d\x94\x24", 4) == 0 ||<br>
+ memcmp(loc, "\x4c\x8d\x9c\x24", 4) == 0) {<br>
// The offset bytes are encoded four bytes after the start of the<br>
// instruction.<br>
- write32le(Loc + 4, read32le(Loc + 4) - 0x4000);<br>
+ write32le(loc + 4, read32le(loc + 4) - 0x4000);<br>
return true;<br>
}<br>
return false;<br>
@@ -580,33 +580,33 @@ namespace {<br>
class Retpoline : public X86_64 {<br>
public:<br>
Retpoline();<br>
- void writeGotPlt(uint8_t *Buf, const Symbol &S) const override;<br>
- void writePltHeader(uint8_t *Buf) const override;<br>
- void writePlt(uint8_t *Buf, uint64_t GotPltEntryAddr, uint64_t PltEntryAddr,<br>
- int32_t Index, unsigned RelOff) const override;<br>
+ void writeGotPlt(uint8_t *buf, const Symbol &s) const override;<br>
+ void writePltHeader(uint8_t *buf) const override;<br>
+ void writePlt(uint8_t *buf, uint64_t gotPltEntryAddr, uint64_t pltEntryAddr,<br>
+ int32_t index, unsigned relOff) const override;<br>
};<br>
<br>
class RetpolineZNow : public X86_64 {<br>
public:<br>
RetpolineZNow();<br>
- void writeGotPlt(uint8_t *Buf, const Symbol &S) const override {}<br>
- void writePltHeader(uint8_t *Buf) const override;<br>
- void writePlt(uint8_t *Buf, uint64_t GotPltEntryAddr, uint64_t PltEntryAddr,<br>
- int32_t Index, unsigned RelOff) const override;<br>
+ void writeGotPlt(uint8_t *buf, const Symbol &s) const override {}<br>
+ void writePltHeader(uint8_t *buf) const override;<br>
+ void writePlt(uint8_t *buf, uint64_t gotPltEntryAddr, uint64_t pltEntryAddr,<br>
+ int32_t index, unsigned relOff) const override;<br>
};<br>
} // namespace<br>
<br>
Retpoline::Retpoline() {<br>
- PltHeaderSize = 48;<br>
- PltEntrySize = 32;<br>
+ pltHeaderSize = 48;<br>
+ pltEntrySize = 32;<br>
}<br>
<br>
-void Retpoline::writeGotPlt(uint8_t *Buf, const Symbol &S) const {<br>
- write64le(Buf, S.getPltVA() + 17);<br>
+void Retpoline::writeGotPlt(uint8_t *buf, const Symbol &s) const {<br>
+ write64le(buf, s.getPltVA() + 17);<br>
}<br>
<br>
-void Retpoline::writePltHeader(uint8_t *Buf) const {<br>
- const uint8_t Insn[] = {<br>
+void Retpoline::writePltHeader(uint8_t *buf) const {<br>
+ const uint8_t insn[] = {<br>
0xff, 0x35, 0, 0, 0, 0, // 0: pushq GOTPLT+8(%rip)<br>
0x4c, 0x8b, 0x1d, 0, 0, 0, 0, // 6: mov GOTPLT+16(%rip), %r11<br>
0xe8, 0x0e, 0x00, 0x00, 0x00, // d: callq next<br>
@@ -619,18 +619,18 @@ void Retpoline::writePltHeader(uint8_t *<br>
0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, // 25: int3; padding<br>
0xcc, 0xcc, 0xcc, 0xcc, // 2c: int3; padding<br>
};<br>
- memcpy(Buf, Insn, sizeof(Insn));<br>
+ memcpy(buf, insn, sizeof(insn));<br>
<br>
- uint64_t GotPlt = In.GotPlt->getVA();<br>
- uint64_t Plt = In.Plt->getVA();<br>
- write32le(Buf + 2, GotPlt - Plt - 6 + 8);<br>
- write32le(Buf + 9, GotPlt - Plt - 13 + 16);<br>
+ uint64_t gotPlt = in.gotPlt->getVA();<br>
+ uint64_t plt = in.plt->getVA();<br>
+ write32le(buf + 2, gotPlt - plt - 6 + 8);<br>
+ write32le(buf + 9, gotPlt - plt - 13 + 16);<br>
}<br>
<br>
-void Retpoline::writePlt(uint8_t *Buf, uint64_t GotPltEntryAddr,<br>
- uint64_t PltEntryAddr, int32_t Index,<br>
- unsigned RelOff) const {<br>
- const uint8_t Insn[] = {<br>
+void Retpoline::writePlt(uint8_t *buf, uint64_t gotPltEntryAddr,<br>
+ uint64_t pltEntryAddr, int32_t index,<br>
+ unsigned relOff) const {<br>
+ const uint8_t insn[] = {<br>
0x4c, 0x8b, 0x1d, 0, 0, 0, 0, // 0: mov foo@GOTPLT(%rip), %r11<br>
0xe8, 0, 0, 0, 0, // 7: callq plt+0x20<br>
0xe9, 0, 0, 0, 0, // c: jmp plt+0x12<br>
@@ -638,24 +638,24 @@ void Retpoline::writePlt(uint8_t *Buf, u<br>
0xe9, 0, 0, 0, 0, // 16: jmp plt+0<br>
0xcc, 0xcc, 0xcc, 0xcc, 0xcc, // 1b: int3; padding<br>
};<br>
- memcpy(Buf, Insn, sizeof(Insn));<br>
+ memcpy(buf, insn, sizeof(insn));<br>
<br>
- uint64_t Off = PltHeaderSize + PltEntrySize * Index;<br>
+ uint64_t off = pltHeaderSize + pltEntrySize * index;<br>
<br>
- write32le(Buf + 3, GotPltEntryAddr - PltEntryAddr - 7);<br>
- write32le(Buf + 8, -Off - 12 + 32);<br>
- write32le(Buf + 13, -Off - 17 + 18);<br>
- write32le(Buf + 18, Index);<br>
- write32le(Buf + 23, -Off - 27);<br>
+ write32le(buf + 3, gotPltEntryAddr - pltEntryAddr - 7);<br>
+ write32le(buf + 8, -off - 12 + 32);<br>
+ write32le(buf + 13, -off - 17 + 18);<br>
+ write32le(buf + 18, index);<br>
+ write32le(buf + 23, -off - 27);<br>
}<br>
<br>
RetpolineZNow::RetpolineZNow() {<br>
- PltHeaderSize = 32;<br>
- PltEntrySize = 16;<br>
+ pltHeaderSize = 32;<br>
+ pltEntrySize = 16;<br>
}<br>
<br>
-void RetpolineZNow::writePltHeader(uint8_t *Buf) const {<br>
- const uint8_t Insn[] = {<br>
+void RetpolineZNow::writePltHeader(uint8_t *buf) const {<br>
+ const uint8_t insn[] = {<br>
0xe8, 0x0b, 0x00, 0x00, 0x00, // 0: call next<br>
0xf3, 0x90, // 5: loop: pause<br>
0x0f, 0xae, 0xe8, // 7: lfence<br>
@@ -667,35 +667,35 @@ void RetpolineZNow::writePltHeader(uint8<br>
0xcc, 0xcc, 0xcc, 0xcc, 0xcc, // 1a: int3; padding<br>
0xcc, // 1f: int3; padding<br>
};<br>
- memcpy(Buf, Insn, sizeof(Insn));<br>
+ memcpy(buf, insn, sizeof(insn));<br>
}<br>
<br>
-void RetpolineZNow::writePlt(uint8_t *Buf, uint64_t GotPltEntryAddr,<br>
- uint64_t PltEntryAddr, int32_t Index,<br>
- unsigned RelOff) const {<br>
- const uint8_t Insn[] = {<br>
+void RetpolineZNow::writePlt(uint8_t *buf, uint64_t gotPltEntryAddr,<br>
+ uint64_t pltEntryAddr, int32_t index,<br>
+ unsigned relOff) const {<br>
+ const uint8_t insn[] = {<br>
0x4c, 0x8b, 0x1d, 0, 0, 0, 0, // mov foo@GOTPLT(%rip), %r11<br>
0xe9, 0, 0, 0, 0, // jmp plt+0<br>
0xcc, 0xcc, 0xcc, 0xcc, // int3; padding<br>
};<br>
- memcpy(Buf, Insn, sizeof(Insn));<br>
+ memcpy(buf, insn, sizeof(insn));<br>
<br>
- write32le(Buf + 3, GotPltEntryAddr - PltEntryAddr - 7);<br>
- write32le(Buf + 8, -PltHeaderSize - PltEntrySize * Index - 12);<br>
+ write32le(buf + 3, gotPltEntryAddr - pltEntryAddr - 7);<br>
+ write32le(buf + 8, -pltHeaderSize - pltEntrySize * index - 12);<br>
}<br>
<br>
static TargetInfo *getTargetInfo() {<br>
- if (Config->ZRetpolineplt) {<br>
- if (Config->ZNow) {<br>
- static RetpolineZNow T;<br>
- return &T;<br>
+ if (config->zRetpolineplt) {<br>
+ if (config->zNow) {<br>
+ static RetpolineZNow t;<br>
+ return &t;<br>
}<br>
- static Retpoline T;<br>
- return &T;<br>
+ static Retpoline t;<br>
+ return &t;<br>
}<br>
<br>
- static X86_64 T;<br>
- return &T;<br>
+ static X86_64 t;<br>
+ return &t;<br>
}<br>
<br>
TargetInfo *elf::getX86_64TargetInfo() { return getTargetInfo(); }<br>
<br>
Modified: lld/trunk/ELF/CallGraphSort.cpp<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_ELF_CallGraphSort.cpp-3Frev-3D365595-26r1-3D365594-26r2-3D365595-26view-3Ddiff&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=DB-x29S8eVeIYCA2mlQi3CPqh7MHn1MHuT7UcQ8E6Wg&e=" rel="noreferrer" target="_blank">https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_ELF_CallGraphSort.cpp-3Frev-3D365595-26r1-3D365594-26r2-3D365595-26view-3Ddiff&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=DB-x29S8eVeIYCA2mlQi3CPqh7MHn1MHuT7UcQ8E6Wg&e=</a> <br>
==============================================================================<br>
--- lld/trunk/ELF/CallGraphSort.cpp (original)<br>
+++ lld/trunk/ELF/CallGraphSort.cpp Tue Jul 9 22:00:37 2019<br>
@@ -51,24 +51,24 @@ using namespace lld::elf;<br>
<br>
namespace {<br>
struct Edge {<br>
- int From;<br>
- uint64_t Weight;<br>
+ int from;<br>
+ uint64_t weight;<br>
};<br>
<br>
struct Cluster {<br>
- Cluster(int Sec, size_t S) : Sections{Sec}, Size(S) {}<br>
+ Cluster(int sec, size_t s) : sections{sec}, size(s) {}<br>
<br>
double getDensity() const {<br>
- if (Size == 0)<br>
+ if (size == 0)<br>
return 0;<br>
- return double(Weight) / double(Size);<br>
+ return double(weight) / double(size);<br>
}<br>
<br>
- std::vector<int> Sections;<br>
- size_t Size = 0;<br>
- uint64_t Weight = 0;<br>
- uint64_t InitialWeight = 0;<br>
- Edge BestPred = {-1, 0};<br>
+ std::vector<int> sections;<br>
+ size_t size = 0;<br>
+ uint64_t weight = 0;<br>
+ uint64_t initialWeight = 0;<br>
+ Edge bestPred = {-1, 0};<br>
};<br>
<br>
class CallGraphSort {<br>
@@ -78,8 +78,8 @@ public:<br>
DenseMap<const InputSectionBase *, int> run();<br>
<br>
private:<br>
- std::vector<Cluster> Clusters;<br>
- std::vector<const InputSectionBase *> Sections;<br>
+ std::vector<Cluster> clusters;<br>
+ std::vector<const InputSectionBase *> sections;<br>
<br>
void groupClusters();<br>
};<br>
@@ -99,23 +99,23 @@ using SectionPair =<br>
// Symbols, and generate a graph between InputSections with the provided<br>
// weights.<br>
CallGraphSort::CallGraphSort() {<br>
- MapVector<SectionPair, uint64_t> &Profile = Config->CallGraphProfile;<br>
- DenseMap<const InputSectionBase *, int> SecToCluster;<br>
+ MapVector<SectionPair, uint64_t> &profile = config->callGraphProfile;<br>
+ DenseMap<const InputSectionBase *, int> secToCluster;<br>
<br>
- auto GetOrCreateNode = [&](const InputSectionBase *IS) -> int {<br>
- auto Res = SecToCluster.insert(std::make_pair(IS, Clusters.size()));<br>
- if (Res.second) {<br>
- Sections.push_back(IS);<br>
- Clusters.emplace_back(Clusters.size(), IS->getSize());<br>
+ auto getOrCreateNode = [&](const InputSectionBase *isec) -> int {<br>
+ auto res = secToCluster.insert(std::make_pair(isec, clusters.size()));<br>
+ if (res.second) {<br>
+ sections.push_back(isec);<br>
+ clusters.emplace_back(clusters.size(), isec->getSize());<br>
}<br>
- return Res.first->second;<br>
+ return res.first->second;<br>
};<br>
<br>
// Create the graph.<br>
- for (std::pair<SectionPair, uint64_t> &C : Profile) {<br>
- const auto *FromSB = cast<InputSectionBase>(C.first.first->Repl);<br>
- const auto *ToSB = cast<InputSectionBase>(C.first.second->Repl);<br>
- uint64_t Weight = C.second;<br>
+ for (std::pair<SectionPair, uint64_t> &c : profile) {<br>
+ const auto *fromSB = cast<InputSectionBase>(c.first.first->repl);<br>
+ const auto *toSB = cast<InputSectionBase>(c.first.second->repl);<br>
+ uint64_t weight = c.second;<br>
<br>
// Ignore edges between input sections belonging to different output<br>
// sections. This is done because otherwise we would end up with clusters<br>
@@ -123,94 +123,94 @@ CallGraphSort::CallGraphSort() {<br>
// output. This messes with the cluster size and density calculations. We<br>
// would also end up moving input sections in other output sections without<br>
// moving them closer to what calls them.<br>
- if (FromSB->getOutputSection() != ToSB->getOutputSection())<br>
+ if (fromSB->getOutputSection() != toSB->getOutputSection())<br>
continue;<br>
<br>
- int From = GetOrCreateNode(FromSB);<br>
- int To = GetOrCreateNode(ToSB);<br>
+ int from = getOrCreateNode(fromSB);<br>
+ int to = getOrCreateNode(toSB);<br>
<br>
- Clusters[To].Weight += Weight;<br>
+ clusters[to].weight += weight;<br>
<br>
- if (From == To)<br>
+ if (from == to)<br>
continue;<br>
<br>
// Remember the best edge.<br>
- Cluster &ToC = Clusters[To];<br>
- if (ToC.BestPred.From == -1 || ToC.BestPred.Weight < Weight) {<br>
- ToC.BestPred.From = From;<br>
- ToC.BestPred.Weight = Weight;<br>
+ Cluster &toC = clusters[to];<br>
+ if (toC.bestPred.from == -1 || toC.bestPred.weight < weight) {<br>
+ toC.bestPred.from = from;<br>
+ toC.bestPred.weight = weight;<br>
}<br>
}<br>
- for (Cluster &C : Clusters)<br>
- C.InitialWeight = C.Weight;<br>
+ for (Cluster &c : clusters)<br>
+ c.initialWeight = c.weight;<br>
}<br>
<br>
// It's bad to merge clusters which would degrade the density too much.<br>
-static bool isNewDensityBad(Cluster &A, Cluster &B) {<br>
- double NewDensity = double(A.Weight + B.Weight) / double(A.Size + B.Size);<br>
- return NewDensity < A.getDensity() / MAX_DENSITY_DEGRADATION;<br>
+static bool isNewDensityBad(Cluster &a, Cluster &b) {<br>
+ double newDensity = double(a.weight + b.weight) / double(a.size + b.size);<br>
+ return newDensity < a.getDensity() / MAX_DENSITY_DEGRADATION;<br>
}<br>
<br>
-static void mergeClusters(Cluster &Into, Cluster &From) {<br>
- Into.Sections.insert(Into.Sections.end(), From.Sections.begin(),<br>
- From.Sections.end());<br>
- Into.Size += From.Size;<br>
- Into.Weight += From.Weight;<br>
- From.Sections.clear();<br>
- From.Size = 0;<br>
- From.Weight = 0;<br>
+static void mergeClusters(Cluster &into, Cluster &from) {<br>
+ into.sections.insert(into.sections.end(), from.sections.begin(),<br>
+ from.sections.end());<br>
+ into.size += from.size;<br>
+ into.weight += from.weight;<br>
+ from.sections.clear();<br>
+ from.size = 0;<br>
+ from.weight = 0;<br>
}<br>
<br>
// Group InputSections into clusters using the Call-Chain Clustering heuristic<br>
// then sort the clusters by density.<br>
void CallGraphSort::groupClusters() {<br>
- std::vector<int> SortedSecs(Clusters.size());<br>
- std::vector<Cluster *> SecToCluster(Clusters.size());<br>
+ std::vector<int> sortedSecs(clusters.size());<br>
+ std::vector<Cluster *> secToCluster(clusters.size());<br>
<br>
- for (size_t I = 0; I < Clusters.size(); ++I) {<br>
- SortedSecs[I] = I;<br>
- SecToCluster[I] = &Clusters[I];<br>
+ for (size_t i = 0; i < clusters.size(); ++i) {<br>
+ sortedSecs[i] = i;<br>
+ secToCluster[i] = &clusters[i];<br>
}<br>
<br>
- llvm::stable_sort(SortedSecs, [&](int A, int B) {<br>
- return Clusters[A].getDensity() > Clusters[B].getDensity();<br>
+ llvm::stable_sort(sortedSecs, [&](int a, int b) {<br>
+ return clusters[a].getDensity() > clusters[b].getDensity();<br>
});<br>
<br>
- for (int SI : SortedSecs) {<br>
+ for (int si : sortedSecs) {<br>
// Clusters[SI] is the same as SecToClusters[SI] here because it has not<br>
// been merged into another cluster yet.<br>
- Cluster &C = Clusters[SI];<br>
+ Cluster &c = clusters[si];<br>
<br>
// Don't consider merging if the edge is unlikely.<br>
- if (C.BestPred.From == -1 || C.BestPred.Weight * 10 <= C.InitialWeight)<br>
+ if (c.bestPred.from == -1 || c.bestPred.weight * 10 <= c.initialWeight)<br>
continue;<br>
<br>
- Cluster *PredC = SecToCluster[C.BestPred.From];<br>
- if (PredC == &C)<br>
+ Cluster *predC = secToCluster[c.bestPred.from];<br>
+ if (predC == &c)<br>
continue;<br>
<br>
- if (C.Size + PredC->Size > MAX_CLUSTER_SIZE)<br>
+ if (c.size + predC->size > MAX_CLUSTER_SIZE)<br>
continue;<br>
<br>
- if (isNewDensityBad(*PredC, C))<br>
+ if (isNewDensityBad(*predC, c))<br>
continue;<br>
<br>
// NOTE: Consider using a disjoint-set to track section -> cluster mapping<br>
// if this is ever slow.<br>
- for (int SI : C.Sections)<br>
- SecToCluster[SI] = PredC;<br>
+ for (int si : c.sections)<br>
+ secToCluster[si] = predC;<br>
<br>
- mergeClusters(*PredC, C);<br>
+ mergeClusters(*predC, c);<br>
}<br>
<br>
// Remove empty or dead nodes. Invalidates all cluster indices.<br>
- llvm::erase_if(Clusters, [](const Cluster &C) {<br>
- return C.Size == 0 || C.Sections.empty();<br>
+ llvm::erase_if(clusters, [](const Cluster &c) {<br>
+ return c.size == 0 || c.sections.empty();<br>
});<br>
<br>
// Sort by density.<br>
- llvm::stable_sort(Clusters, [](const Cluster &A, const Cluster &B) {<br>
- return A.getDensity() > B.getDensity();<br>
+ llvm::stable_sort(clusters, [](const Cluster &a, const Cluster &b) {<br>
+ return a.getDensity() > b.getDensity();<br>
});<br>
}<br>
<br>
@@ -218,35 +218,35 @@ DenseMap<const InputSectionBase *, int><br>
groupClusters();<br>
<br>
// Generate order.<br>
- DenseMap<const InputSectionBase *, int> OrderMap;<br>
- ssize_t CurOrder = 1;<br>
+ DenseMap<const InputSectionBase *, int> orderMap;<br>
+ ssize_t curOrder = 1;<br>
<br>
- for (const Cluster &C : Clusters)<br>
- for (int SecIndex : C.Sections)<br>
- OrderMap[Sections[SecIndex]] = CurOrder++;<br>
-<br>
- if (!Config->PrintSymbolOrder.empty()) {<br>
- std::error_code EC;<br>
- raw_fd_ostream OS(Config->PrintSymbolOrder, EC, sys::fs::F_None);<br>
- if (EC) {<br>
- error("cannot open " + Config->PrintSymbolOrder + ": " + EC.message());<br>
- return OrderMap;<br>
+ for (const Cluster &c : clusters)<br>
+ for (int secIndex : c.sections)<br>
+ orderMap[sections[secIndex]] = curOrder++;<br>
+<br>
+ if (!config->printSymbolOrder.empty()) {<br>
+ std::error_code ec;<br>
+ raw_fd_ostream os(config->printSymbolOrder, ec, sys::fs::F_None);<br>
+ if (ec) {<br>
+ error("cannot open " + config->printSymbolOrder + ": " + ec.message());<br>
+ return orderMap;<br>
}<br>
<br>
// Print the symbols ordered by C3, in the order of increasing CurOrder<br>
// Instead of sorting all the OrderMap, just repeat the loops above.<br>
- for (const Cluster &C : Clusters)<br>
- for (int SecIndex : C.Sections)<br>
+ for (const Cluster &c : clusters)<br>
+ for (int secIndex : c.sections)<br>
// Search all the symbols in the file of the section<br>
// and find out a Defined symbol with name that is within the section.<br>
- for (Symbol *Sym: Sections[SecIndex]->File->getSymbols())<br>
- if (!Sym->isSection()) // Filter out section-type symbols here.<br>
- if (auto *D = dyn_cast<Defined>(Sym))<br>
- if (Sections[SecIndex] == D->Section)<br>
- OS << Sym->getName() << "\n";<br>
+ for (Symbol *sym: sections[secIndex]->file->getSymbols())<br>
+ if (!sym->isSection()) // Filter out section-type symbols here.<br>
+ if (auto *d = dyn_cast<Defined>(sym))<br>
+ if (sections[secIndex] == d->section)<br>
+ os << sym->getName() << "\n";<br>
}<br>
<br>
- return OrderMap;<br>
+ return orderMap;<br>
}<br>
<br>
// Sort sections by the profile data provided by -callgraph-profile-file<br>
<br>
Modified: lld/trunk/ELF/Config.h<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_ELF_Config.h-3Frev-3D365595-26r1-3D365594-26r2-3D365595-26view-3Ddiff&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=QpGb94Dq6oEgxb6qrfgCHW1bQkDf00XI7rs-EQ0ToHg&e=" rel="noreferrer" target="_blank">https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_ELF_Config.h-3Frev-3D365595-26r1-3D365594-26r2-3D365595-26view-3Ddiff&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=QpGb94Dq6oEgxb6qrfgCHW1bQkDf00XI7rs-EQ0ToHg&e=</a> <br>
==============================================================================<br>
--- lld/trunk/ELF/Config.h (original)<br>
+++ lld/trunk/ELF/Config.h Tue Jul 9 22:00:37 2019<br>
@@ -62,17 +62,17 @@ enum class Target2Policy { Abs, Rel, Got<br>
enum class ARMVFPArgKind { Default, Base, VFP, ToolChain };<br>
<br>
struct SymbolVersion {<br>
- llvm::StringRef Name;<br>
- bool IsExternCpp;<br>
- bool HasWildcard;<br>
+ llvm::StringRef name;<br>
+ bool isExternCpp;<br>
+ bool hasWildcard;<br>
};<br>
<br>
// This struct contains symbols version definition that<br>
// can be found in version script if it is used for link.<br>
struct VersionDefinition {<br>
- llvm::StringRef Name;<br>
- uint16_t Id = 0;<br>
- std::vector<SymbolVersion> Globals;<br>
+ llvm::StringRef name;<br>
+ uint16_t id = 0;<br>
+ std::vector<SymbolVersion> globals;<br>
};<br>
<br>
// This struct contains the global configuration for the linker.<br>
@@ -80,177 +80,177 @@ struct VersionDefinition {<br>
// and such fields have the same name as the corresponding options.<br>
// Most fields are initialized by the driver.<br>
struct Configuration {<br>
- uint8_t OSABI = 0;<br>
- uint32_t AndFeatures = 0;<br>
- llvm::CachePruningPolicy ThinLTOCachePolicy;<br>
- llvm::StringMap<uint64_t> SectionStartMap;<br>
- llvm::StringRef Chroot;<br>
- llvm::StringRef DynamicLinker;<br>
- llvm::StringRef DwoDir;<br>
- llvm::StringRef Entry;<br>
- llvm::StringRef Emulation;<br>
- llvm::StringRef Fini;<br>
- llvm::StringRef Init;<br>
- llvm::StringRef LTOAAPipeline;<br>
- llvm::StringRef LTOCSProfileFile;<br>
- llvm::StringRef LTONewPmPasses;<br>
- llvm::StringRef LTOObjPath;<br>
- llvm::StringRef LTOSampleProfile;<br>
- llvm::StringRef MapFile;<br>
- llvm::StringRef OutputFile;<br>
- llvm::StringRef OptRemarksFilename;<br>
- llvm::StringRef OptRemarksPasses;<br>
- llvm::StringRef OptRemarksFormat;<br>
- llvm::StringRef ProgName;<br>
- llvm::StringRef PrintSymbolOrder;<br>
- llvm::StringRef SoName;<br>
- llvm::StringRef Sysroot;<br>
- llvm::StringRef ThinLTOCacheDir;<br>
- llvm::StringRef ThinLTOIndexOnlyArg;<br>
- std::pair<llvm::StringRef, llvm::StringRef> ThinLTOObjectSuffixReplace;<br>
- std::pair<llvm::StringRef, llvm::StringRef> ThinLTOPrefixReplace;<br>
- std::string Rpath;<br>
- std::vector<VersionDefinition> VersionDefinitions;<br>
- std::vector<llvm::StringRef> AuxiliaryList;<br>
- std::vector<llvm::StringRef> FilterList;<br>
- std::vector<llvm::StringRef> SearchPaths;<br>
- std::vector<llvm::StringRef> SymbolOrderingFile;<br>
- std::vector<llvm::StringRef> Undefined;<br>
- std::vector<SymbolVersion> DynamicList;<br>
- std::vector<SymbolVersion> VersionScriptGlobals;<br>
- std::vector<SymbolVersion> VersionScriptLocals;<br>
- std::vector<uint8_t> BuildIdVector;<br>
+ uint8_t osabi = 0;<br>
+ uint32_t andFeatures = 0;<br>
+ llvm::CachePruningPolicy thinLTOCachePolicy;<br>
+ llvm::StringMap<uint64_t> sectionStartMap;<br>
+ llvm::StringRef chroot;<br>
+ llvm::StringRef dynamicLinker;<br>
+ llvm::StringRef dwoDir;<br>
+ llvm::StringRef entry;<br>
+ llvm::StringRef emulation;<br>
+ llvm::StringRef fini;<br>
+ llvm::StringRef init;<br>
+ llvm::StringRef ltoAAPipeline;<br>
+ llvm::StringRef ltoCSProfileFile;<br>
+ llvm::StringRef ltoNewPmPasses;<br>
+ llvm::StringRef ltoObjPath;<br>
+ llvm::StringRef ltoSampleProfile;<br>
+ llvm::StringRef mapFile;<br>
+ llvm::StringRef outputFile;<br>
+ llvm::StringRef optRemarksFilename;<br>
+ llvm::StringRef optRemarksPasses;<br>
+ llvm::StringRef optRemarksFormat;<br>
+ llvm::StringRef progName;<br>
+ llvm::StringRef printSymbolOrder;<br>
+ llvm::StringRef soName;<br>
+ llvm::StringRef sysroot;<br>
+ llvm::StringRef thinLTOCacheDir;<br>
+ llvm::StringRef thinLTOIndexOnlyArg;<br>
+ std::pair<llvm::StringRef, llvm::StringRef> thinLTOObjectSuffixReplace;<br>
+ std::pair<llvm::StringRef, llvm::StringRef> thinLTOPrefixReplace;<br>
+ std::string rpath;<br>
+ std::vector<VersionDefinition> versionDefinitions;<br>
+ std::vector<llvm::StringRef> auxiliaryList;<br>
+ std::vector<llvm::StringRef> filterList;<br>
+ std::vector<llvm::StringRef> searchPaths;<br>
+ std::vector<llvm::StringRef> symbolOrderingFile;<br>
+ std::vector<llvm::StringRef> undefined;<br>
+ std::vector<SymbolVersion> dynamicList;<br>
+ std::vector<SymbolVersion> versionScriptGlobals;<br>
+ std::vector<SymbolVersion> versionScriptLocals;<br>
+ std::vector<uint8_t> buildIdVector;<br>
llvm::MapVector<std::pair<const InputSectionBase *, const InputSectionBase *>,<br>
uint64_t><br>
- CallGraphProfile;<br>
- bool AllowMultipleDefinition;<br>
- bool AllowShlibUndefined;<br>
- bool AndroidPackDynRelocs;<br>
- bool ARMHasBlx = false;<br>
- bool ARMHasMovtMovw = false;<br>
- bool ARMJ1J2BranchEncoding = false;<br>
- bool AsNeeded = false;<br>
- bool Bsymbolic;<br>
- bool BsymbolicFunctions;<br>
- bool CallGraphProfileSort;<br>
- bool CheckSections;<br>
- bool CompressDebugSections;<br>
- bool Cref;<br>
- bool DefineCommon;<br>
- bool Demangle = true;<br>
- bool DependentLibraries;<br>
- bool DisableVerify;<br>
- bool EhFrameHdr;<br>
- bool EmitLLVM;<br>
- bool EmitRelocs;<br>
- bool EnableNewDtags;<br>
- bool ExecuteOnly;<br>
- bool ExportDynamic;<br>
- bool FixCortexA53Errata843419;<br>
- bool ForceBTI;<br>
- bool FormatBinary = false;<br>
- bool RequireCET;<br>
- bool GcSections;<br>
- bool GdbIndex;<br>
- bool GnuHash = false;<br>
- bool GnuUnique;<br>
- bool HasDynamicList = false;<br>
- bool HasDynSymTab;<br>
- bool IgnoreDataAddressEquality;<br>
- bool IgnoreFunctionAddressEquality;<br>
- bool LTOCSProfileGenerate;<br>
- bool LTODebugPassManager;<br>
- bool LTONewPassManager;<br>
- bool MergeArmExidx;<br>
- bool MipsN32Abi = false;<br>
- bool Nmagic;<br>
- bool NoinhibitExec;<br>
- bool Nostdlib;<br>
- bool OFormatBinary;<br>
- bool Omagic;<br>
- bool OptRemarksWithHotness;<br>
- bool PacPlt;<br>
- bool PicThunk;<br>
- bool Pie;<br>
- bool PrintGcSections;<br>
- bool PrintIcfSections;<br>
- bool Relocatable;<br>
- bool RelrPackDynRelocs;<br>
- bool SaveTemps;<br>
- bool SingleRoRx;<br>
- bool Shared;<br>
- bool Static = false;<br>
- bool SysvHash = false;<br>
- bool Target1Rel;<br>
- bool Trace;<br>
- bool ThinLTOEmitImportsFiles;<br>
- bool ThinLTOIndexOnly;<br>
- bool TocOptimize;<br>
- bool UndefinedVersion;<br>
- bool UseAndroidRelrTags = false;<br>
- bool WarnBackrefs;<br>
- bool WarnCommon;<br>
- bool WarnIfuncTextrel;<br>
- bool WarnMissingEntry;<br>
- bool WarnSymbolOrdering;<br>
- bool WriteAddends;<br>
- bool ZCombreloc;<br>
- bool ZCopyreloc;<br>
- bool ZExecstack;<br>
- bool ZGlobal;<br>
- bool ZHazardplt;<br>
- bool ZIfuncNoplt;<br>
- bool ZInitfirst;<br>
- bool ZInterpose;<br>
- bool ZKeepTextSectionPrefix;<br>
- bool ZNodefaultlib;<br>
- bool ZNodelete;<br>
- bool ZNodlopen;<br>
- bool ZNow;<br>
- bool ZOrigin;<br>
- bool ZRelro;<br>
- bool ZRodynamic;<br>
- bool ZText;<br>
- bool ZRetpolineplt;<br>
- bool ZWxneeded;<br>
- DiscardPolicy Discard;<br>
- ICFLevel ICF;<br>
- OrphanHandlingPolicy OrphanHandling;<br>
- SortSectionPolicy SortSection;<br>
- StripPolicy Strip;<br>
- UnresolvedPolicy UnresolvedSymbols;<br>
- Target2Policy Target2;<br>
- ARMVFPArgKind ARMVFPArgs = ARMVFPArgKind::Default;<br>
- BuildIdKind BuildId = BuildIdKind::None;<br>
- ELFKind EKind = ELFNoneKind;<br>
- uint16_t DefaultSymbolVersion = llvm::ELF::VER_NDX_GLOBAL;<br>
- uint16_t EMachine = llvm::ELF::EM_NONE;<br>
- llvm::Optional<uint64_t> ImageBase;<br>
- uint64_t CommonPageSize;<br>
- uint64_t MaxPageSize;<br>
- uint64_t MipsGotSize;<br>
- uint64_t ZStackSize;<br>
- unsigned LTOPartitions;<br>
- unsigned LTOO;<br>
- unsigned Optimize;<br>
- unsigned ThinLTOJobs;<br>
- int32_t SplitStackAdjustSize;<br>
+ callGraphProfile;<br>
+ bool allowMultipleDefinition;<br>
+ bool allowShlibUndefined;<br>
+ bool androidPackDynRelocs;<br>
+ bool armHasBlx = false;<br>
+ bool armHasMovtMovw = false;<br>
+ bool armJ1J2BranchEncoding = false;<br>
+ bool asNeeded = false;<br>
+ bool bsymbolic;<br>
+ bool bsymbolicFunctions;<br>
+ bool callGraphProfileSort;<br>
+ bool checkSections;<br>
+ bool compressDebugSections;<br>
+ bool cref;<br>
+ bool defineCommon;<br>
+ bool demangle = true;<br>
+ bool dependentLibraries;<br>
+ bool disableVerify;<br>
+ bool ehFrameHdr;<br>
+ bool emitLLVM;<br>
+ bool emitRelocs;<br>
+ bool enableNewDtags;<br>
+ bool executeOnly;<br>
+ bool exportDynamic;<br>
+ bool fixCortexA53Errata843419;<br>
+ bool forceBTI;<br>
+ bool formatBinary = false;<br>
+ bool requireCET;<br>
+ bool gcSections;<br>
+ bool gdbIndex;<br>
+ bool gnuHash = false;<br>
+ bool gnuUnique;<br>
+ bool hasDynamicList = false;<br>
+ bool hasDynSymTab;<br>
+ bool ignoreDataAddressEquality;<br>
+ bool ignoreFunctionAddressEquality;<br>
+ bool ltoCSProfileGenerate;<br>
+ bool ltoDebugPassManager;<br>
+ bool ltoNewPassManager;<br>
+ bool mergeArmExidx;<br>
+ bool mipsN32Abi = false;<br>
+ bool nmagic;<br>
+ bool noinhibitExec;<br>
+ bool nostdlib;<br>
+ bool oFormatBinary;<br>
+ bool omagic;<br>
+ bool optRemarksWithHotness;<br>
+ bool pacPlt;<br>
+ bool picThunk;<br>
+ bool pie;<br>
+ bool printGcSections;<br>
+ bool printIcfSections;<br>
+ bool relocatable;<br>
+ bool relrPackDynRelocs;<br>
+ bool saveTemps;<br>
+ bool singleRoRx;<br>
+ bool shared;<br>
+ bool isStatic = false;<br>
+ bool sysvHash = false;<br>
+ bool target1Rel;<br>
+ bool trace;<br>
+ bool thinLTOEmitImportsFiles;<br>
+ bool thinLTOIndexOnly;<br>
+ bool tocOptimize;<br>
+ bool undefinedVersion;<br>
+ bool useAndroidRelrTags = false;<br>
+ bool warnBackrefs;<br>
+ bool warnCommon;<br>
+ bool warnIfuncTextrel;<br>
+ bool warnMissingEntry;<br>
+ bool warnSymbolOrdering;<br>
+ bool writeAddends;<br>
+ bool zCombreloc;<br>
+ bool zCopyreloc;<br>
+ bool zExecstack;<br>
+ bool zGlobal;<br>
+ bool zHazardplt;<br>
+ bool zIfuncNoplt;<br>
+ bool zInitfirst;<br>
+ bool zInterpose;<br>
+ bool zKeepTextSectionPrefix;<br>
+ bool zNodefaultlib;<br>
+ bool zNodelete;<br>
+ bool zNodlopen;<br>
+ bool zNow;<br>
+ bool zOrigin;<br>
+ bool zRelro;<br>
+ bool zRodynamic;<br>
+ bool zText;<br>
+ bool zRetpolineplt;<br>
+ bool zWxneeded;<br>
+ DiscardPolicy discard;<br>
+ ICFLevel icf;<br>
+ OrphanHandlingPolicy orphanHandling;<br>
+ SortSectionPolicy sortSection;<br>
+ StripPolicy strip;<br>
+ UnresolvedPolicy unresolvedSymbols;<br>
+ Target2Policy target2;<br>
+ ARMVFPArgKind armVFPArgs = ARMVFPArgKind::Default;<br>
+ BuildIdKind buildId = BuildIdKind::None;<br>
+ ELFKind ekind = ELFNoneKind;<br>
+ uint16_t defaultSymbolVersion = llvm::ELF::VER_NDX_GLOBAL;<br>
+ uint16_t emachine = llvm::ELF::EM_NONE;<br>
+ llvm::Optional<uint64_t> imageBase;<br>
+ uint64_t commonPageSize;<br>
+ uint64_t maxPageSize;<br>
+ uint64_t mipsGotSize;<br>
+ uint64_t zStackSize;<br>
+ unsigned ltoPartitions;<br>
+ unsigned ltoo;<br>
+ unsigned optimize;<br>
+ unsigned thinLTOJobs;<br>
+ int32_t splitStackAdjustSize;<br>
<br>
// The following config options do not directly correspond to any<br>
// particualr command line options.<br>
<br>
// True if we need to pass through relocations in input files to the<br>
// output file. Usually false because we consume relocations.<br>
- bool CopyRelocs;<br>
+ bool copyRelocs;<br>
<br>
// True if the target is ELF64. False if ELF32.<br>
- bool Is64;<br>
+ bool is64;<br>
<br>
// True if the target is little-endian. False if big-endian.<br>
- bool IsLE;<br>
+ bool isLE;<br>
<br>
// endianness::little if IsLE is true. endianness::big otherwise.<br>
- llvm::support::endianness Endianness;<br>
+ llvm::support::endianness endianness;<br>
<br>
// True if the target is the little-endian MIPS64.<br>
//<br>
@@ -264,7 +264,7 @@ struct Configuration {<br>
// name whatever that means. A fun hypothesis is that "EL" is short for<br>
// little-endian written in the little-endian order, but I don't know<br>
// if that's true.)<br>
- bool IsMips64EL;<br>
+ bool isMips64EL;<br>
<br>
// True if we need to set the DF_STATIC_TLS flag to an output file,<br>
// which works as a hint to the dynamic loader that the file contains<br>
@@ -278,10 +278,10 @@ struct Configuration {<br>
// Since the flag is updated by multi-threaded code, we use std::atomic.<br>
// (Writing to a variable is not considered thread-safe even if the<br>
// variable is boolean and we always set the same value from all threads.)<br>
- std::atomic<bool> HasStaticTlsModel{false};<br>
+ std::atomic<bool> hasStaticTlsModel{false};<br>
<br>
// Holds set of ELF header flags for the target.<br>
- uint32_t EFlags = 0;<br>
+ uint32_t eflags = 0;<br>
<br>
// The ELF spec defines two types of relocation table entries, RELA and<br>
// REL. RELA is a triplet of (offset, info, addend) while REL is a<br>
@@ -297,23 +297,23 @@ struct Configuration {<br>
// Each ABI defines its relocation type. IsRela is true if target<br>
// uses RELA. As far as we know, all 64-bit ABIs are using RELA. A<br>
// few 32-bit ABIs are using RELA too.<br>
- bool IsRela;<br>
+ bool isRela;<br>
<br>
// True if we are creating position-independent code.<br>
- bool Pic;<br>
+ bool isPic;<br>
<br>
// 4 for ELF32, 8 for ELF64.<br>
- int Wordsize;<br>
+ int wordsize;<br>
};<br>
<br>
// The only instance of Configuration struct.<br>
-extern Configuration *Config;<br>
+extern Configuration *config;<br>
<br>
-static inline void errorOrWarn(const Twine &Msg) {<br>
- if (!Config->NoinhibitExec)<br>
- error(Msg);<br>
+static inline void errorOrWarn(const Twine &msg) {<br>
+ if (!config->noinhibitExec)<br>
+ error(msg);<br>
else<br>
- warn(Msg);<br>
+ warn(msg);<br>
}<br>
} // namespace elf<br>
} // namespace lld<br>
<br>
Modified: lld/trunk/ELF/DWARF.cpp<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_ELF_DWARF.cpp-3Frev-3D365595-26r1-3D365594-26r2-3D365595-26view-3Ddiff&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=rlGaKu-kFqT9Ka-bD6Qp8oLTFZNtYhNfbqNduXE6aVg&e=" rel="noreferrer" target="_blank">https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_ELF_DWARF.cpp-3Frev-3D365595-26r1-3D365594-26r2-3D365595-26view-3Ddiff&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=rlGaKu-kFqT9Ka-bD6Qp8oLTFZNtYhNfbqNduXE6aVg&e=</a> <br>
==============================================================================<br>
--- lld/trunk/ELF/DWARF.cpp (original)<br>
+++ lld/trunk/ELF/DWARF.cpp Tue Jul 9 22:00:37 2019<br>
@@ -25,32 +25,32 @@ using namespace llvm::object;<br>
using namespace lld;<br>
using namespace lld::elf;<br>
<br>
-template <class ELFT> LLDDwarfObj<ELFT>::LLDDwarfObj(ObjFile<ELFT> *Obj) {<br>
- for (InputSectionBase *Sec : Obj->getSections()) {<br>
- if (!Sec)<br>
+template <class ELFT> LLDDwarfObj<ELFT>::LLDDwarfObj(ObjFile<ELFT> *obj) {<br>
+ for (InputSectionBase *sec : obj->getSections()) {<br>
+ if (!sec)<br>
continue;<br>
<br>
- if (LLDDWARFSection *M =<br>
- StringSwitch<LLDDWARFSection *>(Sec->Name)<br>
- .Case(".debug_addr", &AddrSection)<br>
- .Case(".debug_gnu_pubnames", &GnuPubNamesSection)<br>
- .Case(".debug_gnu_pubtypes", &GnuPubTypesSection)<br>
- .Case(".debug_info", &InfoSection)<br>
- .Case(".debug_ranges", &RangeSection)<br>
- .Case(".debug_rnglists", &RngListsSection)<br>
- .Case(".debug_line", &LineSection)<br>
+ if (LLDDWARFSection *m =<br>
+ StringSwitch<LLDDWARFSection *>(sec->name)<br>
+ .Case(".debug_addr", &addrSection)<br>
+ .Case(".debug_gnu_pubnames", &gnuPubNamesSection)<br>
+ .Case(".debug_gnu_pubtypes", &gnuPubTypesSection)<br>
+ .Case(".debug_info", &infoSection)<br>
+ .Case(".debug_ranges", &rangeSection)<br>
+ .Case(".debug_rnglists", &rngListsSection)<br>
+ .Case(".debug_line", &lineSection)<br>
.Default(nullptr)) {<br>
- M->Data = toStringRef(Sec->data());<br>
- M->Sec = Sec;<br>
+ m->Data = toStringRef(sec->data());<br>
+ m->sec = sec;<br>
continue;<br>
}<br>
<br>
- if (Sec->Name == ".debug_abbrev")<br>
- AbbrevSection = toStringRef(Sec->data());<br>
- else if (Sec->Name == ".debug_str")<br>
- StrSection = toStringRef(Sec->data());<br>
- else if (Sec->Name == ".debug_line_str")<br>
- LineStringSection = toStringRef(Sec->data());<br>
+ if (sec->name == ".debug_abbrev")<br>
+ abbrevSection = toStringRef(sec->data());<br>
+ else if (sec->name == ".debug_str")<br>
+ strSection = toStringRef(sec->data());<br>
+ else if (sec->name == ".debug_line_str")<br>
+ lineStringSection = toStringRef(sec->data());<br>
}<br>
}<br>
<br>
@@ -58,17 +58,17 @@ namespace {<br>
template <class RelTy> struct LLDRelocationResolver {<br>
// In the ELF ABIs, S sepresents the value of the symbol in the relocation<br>
// entry. For Rela, the addend is stored as part of the relocation entry.<br>
- static uint64_t resolve(object::RelocationRef Ref, uint64_t S,<br>
+ static uint64_t resolve(object::RelocationRef ref, uint64_t s,<br>
uint64_t /* A */) {<br>
- return S + Ref.getRawDataRefImpl().p;<br>
+ return s + ref.getRawDataRefImpl().p;<br>
}<br>
};<br>
<br>
template <class ELFT> struct LLDRelocationResolver<Elf_Rel_Impl<ELFT, false>> {<br>
// For Rel, the addend A is supplied by the caller.<br>
- static uint64_t resolve(object::RelocationRef /*Ref*/, uint64_t S,<br>
- uint64_t A) {<br>
- return S + A;<br>
+ static uint64_t resolve(object::RelocationRef /*Ref*/, uint64_t s,<br>
+ uint64_t a) {<br>
+ return s + a;<br>
}<br>
};<br>
} // namespace<br>
@@ -79,47 +79,47 @@ template <class ELFT> struct LLDRelocati<br>
template <class ELFT><br>
template <class RelTy><br>
Optional<RelocAddrEntry><br>
-LLDDwarfObj<ELFT>::findAux(const InputSectionBase &Sec, uint64_t Pos,<br>
- ArrayRef<RelTy> Rels) const {<br>
- auto It =<br>
- partition_point(Rels, [=](const RelTy &A) { return A.r_offset < Pos; });<br>
- if (It == Rels.end() || It->r_offset != Pos)<br>
+LLDDwarfObj<ELFT>::findAux(const InputSectionBase &sec, uint64_t pos,<br>
+ ArrayRef<RelTy> rels) const {<br>
+ auto it =<br>
+ partition_point(rels, [=](const RelTy &a) { return a.r_offset < pos; });<br>
+ if (it == rels.end() || it->r_offset != pos)<br>
return None;<br>
- const RelTy &Rel = *It;<br>
+ const RelTy &rel = *it;<br>
<br>
- const ObjFile<ELFT> *File = Sec.getFile<ELFT>();<br>
- uint32_t SymIndex = Rel.getSymbol(Config->IsMips64EL);<br>
- const typename ELFT::Sym &Sym = File->template getELFSyms<ELFT>()[SymIndex];<br>
- uint32_t SecIndex = File->getSectionIndex(Sym);<br>
+ const ObjFile<ELFT> *file = sec.getFile<ELFT>();<br>
+ uint32_t symIndex = rel.getSymbol(config->isMips64EL);<br>
+ const typename ELFT::Sym &sym = file->template getELFSyms<ELFT>()[symIndex];<br>
+ uint32_t secIndex = file->getSectionIndex(sym);<br>
<br>
// An undefined symbol may be a symbol defined in a discarded section. We<br>
// shall still resolve it. This is important for --gdb-index: the end address<br>
// offset of an entry in .debug_ranges is relocated. If it is not resolved,<br>
// its zero value will terminate the decoding of .debug_ranges prematurely.<br>
- Symbol &S = File->getRelocTargetSym(Rel);<br>
- uint64_t Val = 0;<br>
- if (auto *DR = dyn_cast<Defined>(&S)) {<br>
- Val = DR->Value;<br>
+ Symbol &s = file->getRelocTargetSym(rel);<br>
+ uint64_t val = 0;<br>
+ if (auto *dr = dyn_cast<Defined>(&s)) {<br>
+ val = dr->value;<br>
<br>
// FIXME: We should be consistent about always adding the file<br>
// offset or not.<br>
- if (DR->Section->Flags & ELF::SHF_ALLOC)<br>
- Val += cast<InputSection>(DR->Section)->getOffsetInFile();<br>
+ if (dr->section->flags & ELF::SHF_ALLOC)<br>
+ val += cast<InputSection>(dr->section)->getOffsetInFile();<br>
}<br>
<br>
- DataRefImpl D;<br>
- D.p = getAddend<ELFT>(Rel);<br>
- return RelocAddrEntry{SecIndex, RelocationRef(D, nullptr),<br>
- LLDRelocationResolver<RelTy>::resolve, Val};<br>
+ DataRefImpl d;<br>
+ d.p = getAddend<ELFT>(rel);<br>
+ return RelocAddrEntry{secIndex, RelocationRef(d, nullptr),<br>
+ LLDRelocationResolver<RelTy>::resolve, val};<br>
}<br>
<br>
template <class ELFT><br>
-Optional<RelocAddrEntry> LLDDwarfObj<ELFT>::find(const llvm::DWARFSection &S,<br>
- uint64_t Pos) const {<br>
- auto &Sec = static_cast<const LLDDWARFSection &>(S);<br>
- if (Sec.Sec->AreRelocsRela)<br>
- return findAux(*Sec.Sec, Pos, Sec.Sec->template relas<ELFT>());<br>
- return findAux(*Sec.Sec, Pos, Sec.Sec->template rels<ELFT>());<br>
+Optional<RelocAddrEntry> LLDDwarfObj<ELFT>::find(const llvm::DWARFSection &s,<br>
+ uint64_t pos) const {<br>
+ auto &sec = static_cast<const LLDDWARFSection &>(s);<br>
+ if (sec.sec->areRelocsRela)<br>
+ return findAux(*sec.sec, pos, sec.sec->template relas<ELFT>());<br>
+ return findAux(*sec.sec, pos, sec.sec->template rels<ELFT>());<br>
}<br>
<br>
template class elf::LLDDwarfObj<ELF32LE>;<br>
<br>
Modified: lld/trunk/ELF/DWARF.h<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_ELF_DWARF.h-3Frev-3D365595-26r1-3D365594-26r2-3D365595-26view-3Ddiff&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=oLth6C4qGjs4FUrQumX_eKd43hYYrhPUAKfBbcddOE8&e=" rel="noreferrer" target="_blank">https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_ELF_DWARF.h-3Frev-3D365595-26r1-3D365594-26r2-3D365595-26view-3Ddiff&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=oLth6C4qGjs4FUrQumX_eKd43hYYrhPUAKfBbcddOE8&e=</a> <br>
==============================================================================<br>
--- lld/trunk/ELF/DWARF.h (original)<br>
+++ lld/trunk/ELF/DWARF.h Tue Jul 9 22:00:37 2019<br>
@@ -20,70 +20,70 @@ namespace elf {<br>
class InputSection;<br>
<br>
struct LLDDWARFSection final : public llvm::DWARFSection {<br>
- InputSectionBase *Sec = nullptr;<br>
+ InputSectionBase *sec = nullptr;<br>
};<br>
<br>
template <class ELFT> class LLDDwarfObj final : public llvm::DWARFObject {<br>
public:<br>
- explicit LLDDwarfObj(ObjFile<ELFT> *Obj);<br>
+ explicit LLDDwarfObj(ObjFile<ELFT> *obj);<br>
<br>
void forEachInfoSections(<br>
- llvm::function_ref<void(const llvm::DWARFSection &)> F) const override {<br>
- F(InfoSection);<br>
+ llvm::function_ref<void(const llvm::DWARFSection &)> f) const override {<br>
+ f(infoSection);<br>
}<br>
<br>
const llvm::DWARFSection &getRangeSection() const override {<br>
- return RangeSection;<br>
+ return rangeSection;<br>
}<br>
<br>
const llvm::DWARFSection &getRnglistsSection() const override {<br>
- return RngListsSection;<br>
+ return rngListsSection;<br>
}<br>
<br>
const llvm::DWARFSection &getLineSection() const override {<br>
- return LineSection;<br>
+ return lineSection;<br>
}<br>
<br>
const llvm::DWARFSection &getAddrSection() const override {<br>
- return AddrSection;<br>
+ return addrSection;<br>
}<br>
<br>
const llvm::DWARFSection &getGnuPubNamesSection() const override {<br>
- return GnuPubNamesSection;<br>
+ return gnuPubNamesSection;<br>
}<br>
<br>
const llvm::DWARFSection &getGnuPubTypesSection() const override {<br>
- return GnuPubTypesSection;<br>
+ return gnuPubTypesSection;<br>
}<br>
<br>
StringRef getFileName() const override { return ""; }<br>
- StringRef getAbbrevSection() const override { return AbbrevSection; }<br>
- StringRef getStringSection() const override { return StrSection; }<br>
- StringRef getLineStringSection() const override { return LineStringSection; }<br>
+ StringRef getAbbrevSection() const override { return abbrevSection; }<br>
+ StringRef getStringSection() const override { return strSection; }<br>
+ StringRef getLineStringSection() const override { return lineStringSection; }<br>
<br>
bool isLittleEndian() const override {<br>
return ELFT::TargetEndianness == llvm::support::little;<br>
}<br>
<br>
- llvm::Optional<llvm::RelocAddrEntry> find(const llvm::DWARFSection &Sec,<br>
- uint64_t Pos) const override;<br>
+ llvm::Optional<llvm::RelocAddrEntry> find(const llvm::DWARFSection &sec,<br>
+ uint64_t pos) const override;<br>
<br>
private:<br>
template <class RelTy><br>
- llvm::Optional<llvm::RelocAddrEntry> findAux(const InputSectionBase &Sec,<br>
- uint64_t Pos,<br>
- ArrayRef<RelTy> Rels) const;<br>
-<br>
- LLDDWARFSection GnuPubNamesSection;<br>
- LLDDWARFSection GnuPubTypesSection;<br>
- LLDDWARFSection InfoSection;<br>
- LLDDWARFSection RangeSection;<br>
- LLDDWARFSection RngListsSection;<br>
- LLDDWARFSection LineSection;<br>
- LLDDWARFSection AddrSection;<br>
- StringRef AbbrevSection;<br>
- StringRef StrSection;<br>
- StringRef LineStringSection;<br>
+ llvm::Optional<llvm::RelocAddrEntry> findAux(const InputSectionBase &sec,<br>
+ uint64_t pos,<br>
+ ArrayRef<RelTy> rels) const;<br>
+<br>
+ LLDDWARFSection gnuPubNamesSection;<br>
+ LLDDWARFSection gnuPubTypesSection;<br>
+ LLDDWARFSection infoSection;<br>
+ LLDDWARFSection rangeSection;<br>
+ LLDDWARFSection rngListsSection;<br>
+ LLDDWARFSection lineSection;<br>
+ LLDDWARFSection addrSection;<br>
+ StringRef abbrevSection;<br>
+ StringRef strSection;<br>
+ StringRef lineStringSection;<br>
};<br>
<br>
} // namespace elf<br>
<br>
Modified: lld/trunk/ELF/Driver.cpp<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_ELF_Driver.cpp-3Frev-3D365595-26r1-3D365594-26r2-3D365595-26view-3Ddiff&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=jW0pg-icPO3mlSQf6hex7bu71QIM2yEY0KCyEA9BsjY&e=" rel="noreferrer" target="_blank">https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_ELF_Driver.cpp-3Frev-3D365595-26r1-3D365594-26r2-3D365595-26view-3Ddiff&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=jW0pg-icPO3mlSQf6hex7bu71QIM2yEY0KCyEA9BsjY&e=</a> <br>
==============================================================================<br>
--- lld/trunk/ELF/Driver.cpp (original)<br>
+++ lld/trunk/ELF/Driver.cpp Tue Jul 9 22:00:37 2019<br>
@@ -68,49 +68,49 @@ using namespace llvm::support;<br>
using namespace lld;<br>
using namespace lld::elf;<br>
<br>
-Configuration *elf::Config;<br>
-LinkerDriver *elf::Driver;<br>
+Configuration *elf::config;<br>
+LinkerDriver *elf::driver;<br>
<br>
-static void setConfigs(opt::InputArgList &Args);<br>
-static void readConfigs(opt::InputArgList &Args);<br>
+static void setConfigs(opt::InputArgList &args);<br>
+static void readConfigs(opt::InputArgList &args);<br>
<br>
-bool elf::link(ArrayRef<const char *> Args, bool CanExitEarly,<br>
- raw_ostream &Error) {<br>
- errorHandler().LogName = args::getFilenameWithoutExe(Args[0]);<br>
+bool elf::link(ArrayRef<const char *> args, bool canExitEarly,<br>
+ raw_ostream &error) {<br>
+ errorHandler().LogName = args::getFilenameWithoutExe(args[0]);<br>
errorHandler().ErrorLimitExceededMsg =<br>
"too many errors emitted, stopping now (use "<br>
"-error-limit=0 to see all errors)";<br>
- errorHandler().ErrorOS = &Error;<br>
- errorHandler().ExitEarly = CanExitEarly;<br>
- errorHandler().ColorDiagnostics = Error.has_colors();<br>
+ errorHandler().ErrorOS = &error;<br>
+ errorHandler().ExitEarly = canExitEarly;<br>
+ errorHandler().ColorDiagnostics = error.has_colors();<br>
<br>
- InputSections.clear();<br>
- OutputSections.clear();<br>
- BinaryFiles.clear();<br>
- BitcodeFiles.clear();<br>
- ObjectFiles.clear();<br>
- SharedFiles.clear();<br>
+ inputSections.clear();<br>
+ outputSections.clear();<br>
+ binaryFiles.clear();<br>
+ bitcodeFiles.clear();<br>
+ objectFiles.clear();<br>
+ sharedFiles.clear();<br>
<br>
- Config = make<Configuration>();<br>
- Driver = make<LinkerDriver>();<br>
- Script = make<LinkerScript>();<br>
- Symtab = make<SymbolTable>();<br>
+ config = make<Configuration>();<br>
+ driver = make<LinkerDriver>();<br>
+ script = make<LinkerScript>();<br>
+ symtab = make<SymbolTable>();<br>
<br>
- Tar = nullptr;<br>
- memset(&In, 0, sizeof(In));<br>
+ tar = nullptr;<br>
+ memset(&in, 0, sizeof(in));<br>
<br>
- Partitions = {Partition()};<br>
+ partitions = {Partition()};<br>
<br>
- SharedFile::VernauxNum = 0;<br>
+ SharedFile::vernauxNum = 0;<br>
<br>
- Config->ProgName = Args[0];<br>
+ config->progName = args[0];<br>
<br>
- Driver->main(Args);<br>
+ driver->main(args);<br>
<br>
// Exit immediately if we don't need to return to the caller.<br>
// This saves time because the overhead of calling destructors<br>
// for all globally-allocated objects is not negligible.<br>
- if (CanExitEarly)<br>
+ if (canExitEarly)<br>
exitLld(errorCount() ? 1 : 0);<br>
<br>
freeArena();<br>
@@ -118,16 +118,16 @@ bool elf::link(ArrayRef<const char *> Ar<br>
}<br>
<br>
// Parses a linker -m option.<br>
-static std::tuple<ELFKind, uint16_t, uint8_t> parseEmulation(StringRef Emul) {<br>
- uint8_t OSABI = 0;<br>
- StringRef S = Emul;<br>
- if (S.endswith("_fbsd")) {<br>
- S = S.drop_back(5);<br>
- OSABI = ELFOSABI_FREEBSD;<br>
+static std::tuple<ELFKind, uint16_t, uint8_t> parseEmulation(StringRef emul) {<br>
+ uint8_t osabi = 0;<br>
+ StringRef s = emul;<br>
+ if (s.endswith("_fbsd")) {<br>
+ s = s.drop_back(5);<br>
+ osabi = ELFOSABI_FREEBSD;<br>
}<br>
<br>
- std::pair<ELFKind, uint16_t> Ret =<br>
- StringSwitch<std::pair<ELFKind, uint16_t>>(S)<br>
+ std::pair<ELFKind, uint16_t> ret =<br>
+ StringSwitch<std::pair<ELFKind, uint16_t>>(s)<br>
.Cases("aarch64elf", "aarch64linux", "aarch64_elf64_le_vec",<br>
{ELF64LEKind, EM_AARCH64})<br>
.Cases("armelf", "armelf_linux_eabi", {ELF32LEKind, EM_ARM})<br>
@@ -146,101 +146,101 @@ static std::tuple<ELFKind, uint16_t, uin<br>
.Case("elf_iamcu", {ELF32LEKind, EM_IAMCU})<br>
.Default({ELFNoneKind, EM_NONE});<br>
<br>
- if (Ret.first == ELFNoneKind)<br>
- error("unknown emulation: " + Emul);<br>
- return std::make_tuple(Ret.first, Ret.second, OSABI);<br>
+ if (ret.first == ELFNoneKind)<br>
+ error("unknown emulation: " + emul);<br>
+ return std::make_tuple(ret.first, ret.second, osabi);<br>
}<br>
<br>
// Returns slices of MB by parsing MB as an archive file.<br>
// Each slice consists of a member file in the archive.<br>
std::vector<std::pair<MemoryBufferRef, uint64_t>> static getArchiveMembers(<br>
- MemoryBufferRef MB) {<br>
- std::unique_ptr<Archive> File =<br>
- CHECK(Archive::create(MB),<br>
- MB.getBufferIdentifier() + ": failed to parse archive");<br>
-<br>
- std::vector<std::pair<MemoryBufferRef, uint64_t>> V;<br>
- Error Err = Error::success();<br>
- bool AddToTar = File->isThin() && Tar;<br>
- for (const ErrorOr<Archive::Child> &COrErr : File->children(Err)) {<br>
- Archive::Child C =<br>
- CHECK(COrErr, MB.getBufferIdentifier() +<br>
+ MemoryBufferRef mb) {<br>
+ std::unique_ptr<Archive> file =<br>
+ CHECK(Archive::create(mb),<br>
+ mb.getBufferIdentifier() + ": failed to parse archive");<br>
+<br>
+ std::vector<std::pair<MemoryBufferRef, uint64_t>> v;<br>
+ Error err = Error::success();<br>
+ bool addToTar = file->isThin() && tar;<br>
+ for (const ErrorOr<Archive::Child> &cOrErr : file->children(err)) {<br>
+ Archive::Child c =<br>
+ CHECK(cOrErr, mb.getBufferIdentifier() +<br>
": could not get the child of the archive");<br>
- MemoryBufferRef MBRef =<br>
- CHECK(C.getMemoryBufferRef(),<br>
- MB.getBufferIdentifier() +<br>
+ MemoryBufferRef mbref =<br>
+ CHECK(c.getMemoryBufferRef(),<br>
+ mb.getBufferIdentifier() +<br>
": could not get the buffer for a child of the archive");<br>
- if (AddToTar)<br>
- Tar->append(relativeToRoot(check(C.getFullName())), MBRef.getBuffer());<br>
- V.push_back(std::make_pair(MBRef, C.getChildOffset()));<br>
- }<br>
- if (Err)<br>
- fatal(MB.getBufferIdentifier() + ": Archive::children failed: " +<br>
- toString(std::move(Err)));<br>
+ if (addToTar)<br>
+ tar->append(relativeToRoot(check(c.getFullName())), mbref.getBuffer());<br>
+ v.push_back(std::make_pair(mbref, c.getChildOffset()));<br>
+ }<br>
+ if (err)<br>
+ fatal(mb.getBufferIdentifier() + ": Archive::children failed: " +<br>
+ toString(std::move(err)));<br>
<br>
// Take ownership of memory buffers created for members of thin archives.<br>
- for (std::unique_ptr<MemoryBuffer> &MB : File->takeThinBuffers())<br>
- make<std::unique_ptr<MemoryBuffer>>(std::move(MB));<br>
+ for (std::unique_ptr<MemoryBuffer> &mb : file->takeThinBuffers())<br>
+ make<std::unique_ptr<MemoryBuffer>>(std::move(mb));<br>
<br>
- return V;<br>
+ return v;<br>
}<br>
<br>
// Opens a file and create a file object. Path has to be resolved already.<br>
-void LinkerDriver::addFile(StringRef Path, bool WithLOption) {<br>
+void LinkerDriver::addFile(StringRef path, bool withLOption) {<br>
using namespace sys::fs;<br>
<br>
- Optional<MemoryBufferRef> Buffer = readFile(Path);<br>
- if (!Buffer.hasValue())<br>
+ Optional<MemoryBufferRef> buffer = readFile(path);<br>
+ if (!buffer.hasValue())<br>
return;<br>
- MemoryBufferRef MBRef = *Buffer;<br>
+ MemoryBufferRef mbref = *buffer;<br>
<br>
- if (Config->FormatBinary) {<br>
- Files.push_back(make<BinaryFile>(MBRef));<br>
+ if (config->formatBinary) {<br>
+ files.push_back(make<BinaryFile>(mbref));<br>
return;<br>
}<br>
<br>
- switch (identify_magic(MBRef.getBuffer())) {<br>
+ switch (identify_magic(mbref.getBuffer())) {<br>
case file_magic::unknown:<br>
- readLinkerScript(MBRef);<br>
+ readLinkerScript(mbref);<br>
return;<br>
case file_magic::archive: {<br>
// Handle -whole-archive.<br>
- if (InWholeArchive) {<br>
- for (const auto &P : getArchiveMembers(MBRef))<br>
- Files.push_back(createObjectFile(P.first, Path, P.second));<br>
+ if (inWholeArchive) {<br>
+ for (const auto &p : getArchiveMembers(mbref))<br>
+ files.push_back(createObjectFile(p.first, path, p.second));<br>
return;<br>
}<br>
<br>
- std::unique_ptr<Archive> File =<br>
- CHECK(Archive::create(MBRef), Path + ": failed to parse archive");<br>
+ std::unique_ptr<Archive> file =<br>
+ CHECK(Archive::create(mbref), path + ": failed to parse archive");<br>
<br>
// If an archive file has no symbol table, it is likely that a user<br>
// is attempting LTO and using a default ar command that doesn't<br>
// understand the LLVM bitcode file. It is a pretty common error, so<br>
// we'll handle it as if it had a symbol table.<br>
- if (!File->isEmpty() && !File->hasSymbolTable()) {<br>
+ if (!file->isEmpty() && !file->hasSymbolTable()) {<br>
// Check if all members are bitcode files. If not, ignore, which is the<br>
// default action without the LTO hack described above.<br>
- for (const std::pair<MemoryBufferRef, uint64_t> &P :<br>
- getArchiveMembers(MBRef))<br>
- if (identify_magic(P.first.getBuffer()) != file_magic::bitcode) {<br>
- error(Path + ": archive has no index; run ranlib to add one");<br>
+ for (const std::pair<MemoryBufferRef, uint64_t> &p :<br>
+ getArchiveMembers(mbref))<br>
+ if (identify_magic(p.first.getBuffer()) != file_magic::bitcode) {<br>
+ error(path + ": archive has no index; run ranlib to add one");<br>
return;<br>
}<br>
<br>
- for (const std::pair<MemoryBufferRef, uint64_t> &P :<br>
- getArchiveMembers(MBRef))<br>
- Files.push_back(make<LazyObjFile>(P.first, Path, P.second));<br>
+ for (const std::pair<MemoryBufferRef, uint64_t> &p :<br>
+ getArchiveMembers(mbref))<br>
+ files.push_back(make<LazyObjFile>(p.first, path, p.second));<br>
return;<br>
}<br>
<br>
// Handle the regular case.<br>
- Files.push_back(make<ArchiveFile>(std::move(File)));<br>
+ files.push_back(make<ArchiveFile>(std::move(file)));<br>
return;<br>
}<br>
case file_magic::elf_shared_object:<br>
- if (Config->Static || Config->Relocatable) {<br>
- error("attempted static link of dynamic object " + Path);<br>
+ if (config->isStatic || config->relocatable) {<br>
+ error("attempted static link of dynamic object " + path);<br>
return;<br>
}<br>
<br>
@@ -254,27 +254,27 @@ void LinkerDriver::addFile(StringRef Pat<br>
// If a file was specified by -lfoo, the directory part is not<br>
// significant, as a user did not specify it. This behavior is<br>
// compatible with GNU.<br>
- Files.push_back(<br>
- make<SharedFile>(MBRef, WithLOption ? path::filename(Path) : Path));<br>
+ files.push_back(<br>
+ make<SharedFile>(mbref, withLOption ? path::filename(path) : path));<br>
return;<br>
case file_magic::bitcode:<br>
case file_magic::elf_relocatable:<br>
- if (InLib)<br>
- Files.push_back(make<LazyObjFile>(MBRef, "", 0));<br>
+ if (inLib)<br>
+ files.push_back(make<LazyObjFile>(mbref, "", 0));<br>
else<br>
- Files.push_back(createObjectFile(MBRef));<br>
+ files.push_back(createObjectFile(mbref));<br>
break;<br>
default:<br>
- error(Path + ": unknown file type");<br>
+ error(path + ": unknown file type");<br>
}<br>
}<br>
<br>
// Add a given library by searching it from input search paths.<br>
-void LinkerDriver::addLibrary(StringRef Name) {<br>
- if (Optional<std::string> Path = searchLibrary(Name))<br>
- addFile(*Path, /*WithLOption=*/true);<br>
+void LinkerDriver::addLibrary(StringRef name) {<br>
+ if (Optional<std::string> path = searchLibrary(name))<br>
+ addFile(*path, /*WithLOption=*/true);<br>
else<br>
- error("unable to find library -l" + Name);<br>
+ error("unable to find library -l" + name);<br>
}<br>
<br>
// This function is called on startup. We need this for LTO since<br>
@@ -293,117 +293,117 @@ static void initLLVM() {<br>
static void checkOptions() {<br>
// The MIPS ABI as of 2016 does not support the GNU-style symbol lookup<br>
// table which is a relatively new feature.<br>
- if (Config->EMachine == EM_MIPS && Config->GnuHash)<br>
+ if (config->emachine == EM_MIPS && config->gnuHash)<br>
error("the .gnu.hash section is not compatible with the MIPS target");<br>
<br>
- if (Config->FixCortexA53Errata843419 && Config->EMachine != EM_AARCH64)<br>
+ if (config->fixCortexA53Errata843419 && config->emachine != EM_AARCH64)<br>
error("--fix-cortex-a53-843419 is only supported on AArch64 targets");<br>
<br>
- if (Config->TocOptimize && Config->EMachine != EM_PPC64)<br>
+ if (config->tocOptimize && config->emachine != EM_PPC64)<br>
error("--toc-optimize is only supported on the PowerPC64 target");<br>
<br>
- if (Config->Pie && Config->Shared)<br>
+ if (config->pie && config->shared)<br>
error("-shared and -pie may not be used together");<br>
<br>
- if (!Config->Shared && !Config->FilterList.empty())<br>
+ if (!config->shared && !config->filterList.empty())<br>
error("-F may not be used without -shared");<br>
<br>
- if (!Config->Shared && !Config->AuxiliaryList.empty())<br>
+ if (!config->shared && !config->auxiliaryList.empty())<br>
error("-f may not be used without -shared");<br>
<br>
- if (!Config->Relocatable && !Config->DefineCommon)<br>
+ if (!config->relocatable && !config->defineCommon)<br>
error("-no-define-common not supported in non relocatable output");<br>
<br>
- if (Config->ZText && Config->ZIfuncNoplt)<br>
+ if (config->zText && config->zIfuncNoplt)<br>
error("-z text and -z ifunc-noplt may not be used together");<br>
<br>
- if (Config->Relocatable) {<br>
- if (Config->Shared)<br>
+ if (config->relocatable) {<br>
+ if (config->shared)<br>
error("-r and -shared may not be used together");<br>
- if (Config->GcSections)<br>
+ if (config->gcSections)<br>
error("-r and --gc-sections may not be used together");<br>
- if (Config->GdbIndex)<br>
+ if (config->gdbIndex)<br>
error("-r and --gdb-index may not be used together");<br>
- if (Config->ICF != ICFLevel::None)<br>
+ if (config->icf != ICFLevel::None)<br>
error("-r and --icf may not be used together");<br>
- if (Config->Pie)<br>
+ if (config->pie)<br>
error("-r and -pie may not be used together");<br>
}<br>
<br>
- if (Config->ExecuteOnly) {<br>
- if (Config->EMachine != EM_AARCH64)<br>
+ if (config->executeOnly) {<br>
+ if (config->emachine != EM_AARCH64)<br>
error("-execute-only is only supported on AArch64 targets");<br>
<br>
- if (Config->SingleRoRx && !Script->HasSectionsCommand)<br>
+ if (config->singleRoRx && !script->hasSectionsCommand)<br>
error("-execute-only and -no-rosegment cannot be used together");<br>
}<br>
<br>
- if (Config->ZRetpolineplt && Config->RequireCET)<br>
+ if (config->zRetpolineplt && config->requireCET)<br>
error("--require-cet may not be used with -z retpolineplt");<br>
<br>
- if (Config->EMachine != EM_AARCH64) {<br>
- if (Config->PacPlt)<br>
+ if (config->emachine != EM_AARCH64) {<br>
+ if (config->pacPlt)<br>
error("--pac-plt only supported on AArch64");<br>
- if (Config->ForceBTI)<br>
+ if (config->forceBTI)<br>
error("--force-bti only supported on AArch64");<br>
}<br>
}<br>
<br>
-static const char *getReproduceOption(opt::InputArgList &Args) {<br>
- if (auto *Arg = Args.getLastArg(OPT_reproduce))<br>
- return Arg->getValue();<br>
+static const char *getReproduceOption(opt::InputArgList &args) {<br>
+ if (auto *arg = args.getLastArg(OPT_reproduce))<br>
+ return arg->getValue();<br>
return getenv("LLD_REPRODUCE");<br>
}<br>
<br>
-static bool hasZOption(opt::InputArgList &Args, StringRef Key) {<br>
- for (auto *Arg : Args.filtered(OPT_z))<br>
- if (Key == Arg->getValue())<br>
+static bool hasZOption(opt::InputArgList &args, StringRef key) {<br>
+ for (auto *arg : args.filtered(OPT_z))<br>
+ if (key == arg->getValue())<br>
return true;<br>
return false;<br>
}<br>
<br>
-static bool getZFlag(opt::InputArgList &Args, StringRef K1, StringRef K2,<br>
+static bool getZFlag(opt::InputArgList &args, StringRef k1, StringRef k2,<br>
bool Default) {<br>
- for (auto *Arg : Args.filtered_reverse(OPT_z)) {<br>
- if (K1 == Arg->getValue())<br>
+ for (auto *arg : args.filtered_reverse(OPT_z)) {<br>
+ if (k1 == arg->getValue())<br>
return true;<br>
- if (K2 == Arg->getValue())<br>
+ if (k2 == arg->getValue())<br>
return false;<br>
}<br>
return Default;<br>
}<br>
<br>
-static bool isKnownZFlag(StringRef S) {<br>
- return S == "combreloc" || S == "copyreloc" || S == "defs" ||<br>
- S == "execstack" || S == "global" || S == "hazardplt" ||<br>
- S == "ifunc-noplt" || S == "initfirst" || S == "interpose" ||<br>
- S == "keep-text-section-prefix" || S == "lazy" || S == "muldefs" ||<br>
- S == "nocombreloc" || S == "nocopyreloc" || S == "nodefaultlib" ||<br>
- S == "nodelete" || S == "nodlopen" || S == "noexecstack" ||<br>
- S == "nokeep-text-section-prefix" || S == "norelro" || S == "notext" ||<br>
- S == "now" || S == "origin" || S == "relro" || S == "retpolineplt" ||<br>
- S == "rodynamic" || S == "text" || S == "wxneeded" ||<br>
- S.startswith("common-page-size") || S.startswith("max-page-size=") ||<br>
- S.startswith("stack-size=");<br>
+static bool isKnownZFlag(StringRef s) {<br>
+ return s == "combreloc" || s == "copyreloc" || s == "defs" ||<br>
+ s == "execstack" || s == "global" || s == "hazardplt" ||<br>
+ s == "ifunc-noplt" || s == "initfirst" || s == "interpose" ||<br>
+ s == "keep-text-section-prefix" || s == "lazy" || s == "muldefs" ||<br>
+ s == "nocombreloc" || s == "nocopyreloc" || s == "nodefaultlib" ||<br>
+ s == "nodelete" || s == "nodlopen" || s == "noexecstack" ||<br>
+ s == "nokeep-text-section-prefix" || s == "norelro" || s == "notext" ||<br>
+ s == "now" || s == "origin" || s == "relro" || s == "retpolineplt" ||<br>
+ s == "rodynamic" || s == "text" || s == "wxneeded" ||<br>
+ s.startswith("common-page-size") || s.startswith("max-page-size=") ||<br>
+ s.startswith("stack-size=");<br>
}<br>
<br>
// Report an error for an unknown -z option.<br>
-static void checkZOptions(opt::InputArgList &Args) {<br>
- for (auto *Arg : Args.filtered(OPT_z))<br>
- if (!isKnownZFlag(Arg->getValue()))<br>
- error("unknown -z value: " + StringRef(Arg->getValue()));<br>
+static void checkZOptions(opt::InputArgList &args) {<br>
+ for (auto *arg : args.filtered(OPT_z))<br>
+ if (!isKnownZFlag(arg->getValue()))<br>
+ error("unknown -z value: " + StringRef(arg->getValue()));<br>
}<br>
<br>
-void LinkerDriver::main(ArrayRef<const char *> ArgsArr) {<br>
- ELFOptTable Parser;<br>
- opt::InputArgList Args = Parser.parse(ArgsArr.slice(1));<br>
+void LinkerDriver::main(ArrayRef<const char *> argsArr) {<br>
+ ELFOptTable parser;<br>
+ opt::InputArgList args = parser.parse(argsArr.slice(1));<br>
<br>
// Interpret this flag early because error() depends on them.<br>
- errorHandler().ErrorLimit = args::getInteger(Args, OPT_error_limit, 20);<br>
- checkZOptions(Args);<br>
+ errorHandler().ErrorLimit = args::getInteger(args, OPT_error_limit, 20);<br>
+ checkZOptions(args);<br>
<br>
// Handle -help<br>
- if (Args.hasArg(OPT_help)) {<br>
+ if (args.hasArg(OPT_help)) {<br>
printHelp();<br>
return;<br>
}<br>
@@ -423,39 +423,39 @@ void LinkerDriver::main(ArrayRef<const c<br>
// lot of "configure" scripts out there that are generated by old version<br>
// of Libtool. We cannot convince every software developer to migrate to<br>
// the latest version and re-generate scripts. So we have this hack.<br>
- if (Args.hasArg(OPT_v) || Args.hasArg(OPT_version))<br>
+ if (args.hasArg(OPT_v) || args.hasArg(OPT_version))<br>
message(getLLDVersion() + " (compatible with GNU linkers)");<br>
<br>
- if (const char *Path = getReproduceOption(Args)) {<br>
+ if (const char *path = getReproduceOption(args)) {<br>
// Note that --reproduce is a debug option so you can ignore it<br>
// if you are trying to understand the whole picture of the code.<br>
- Expected<std::unique_ptr<TarWriter>> ErrOrWriter =<br>
- TarWriter::create(Path, path::stem(Path));<br>
- if (ErrOrWriter) {<br>
- Tar = std::move(*ErrOrWriter);<br>
- Tar->append("response.txt", createResponseFile(Args));<br>
- Tar->append("version.txt", getLLDVersion() + "\n");<br>
+ Expected<std::unique_ptr<TarWriter>> errOrWriter =<br>
+ TarWriter::create(path, path::stem(path));<br>
+ if (errOrWriter) {<br>
+ tar = std::move(*errOrWriter);<br>
+ tar->append("response.txt", createResponseFile(args));<br>
+ tar->append("version.txt", getLLDVersion() + "\n");<br>
} else {<br>
- error("--reproduce: " + toString(ErrOrWriter.takeError()));<br>
+ error("--reproduce: " + toString(errOrWriter.takeError()));<br>
}<br>
}<br>
<br>
- readConfigs(Args);<br>
+ readConfigs(args);<br>
<br>
// The behavior of -v or --version is a bit strange, but this is<br>
// needed for compatibility with GNU linkers.<br>
- if (Args.hasArg(OPT_v) && !Args.hasArg(OPT_INPUT))<br>
+ if (args.hasArg(OPT_v) && !args.hasArg(OPT_INPUT))<br>
return;<br>
- if (Args.hasArg(OPT_version))<br>
+ if (args.hasArg(OPT_version))<br>
return;<br>
<br>
initLLVM();<br>
- createFiles(Args);<br>
+ createFiles(args);<br>
if (errorCount())<br>
return;<br>
<br>
inferMachineType();<br>
- setConfigs(Args);<br>
+ setConfigs(args);<br>
checkOptions();<br>
if (errorCount())<br>
return;<br>
@@ -463,178 +463,178 @@ void LinkerDriver::main(ArrayRef<const c<br>
// The Target instance handles target-specific stuff, such as applying<br>
// relocations or writing a PLT section. It also contains target-dependent<br>
// values such as a default image base address.<br>
- Target = getTarget();<br>
+ target = getTarget();<br>
<br>
- switch (Config->EKind) {<br>
+ switch (config->ekind) {<br>
case ELF32LEKind:<br>
- link<ELF32LE>(Args);<br>
+ link<ELF32LE>(args);<br>
return;<br>
case ELF32BEKind:<br>
- link<ELF32BE>(Args);<br>
+ link<ELF32BE>(args);<br>
return;<br>
case ELF64LEKind:<br>
- link<ELF64LE>(Args);<br>
+ link<ELF64LE>(args);<br>
return;<br>
case ELF64BEKind:<br>
- link<ELF64BE>(Args);<br>
+ link<ELF64BE>(args);<br>
return;<br>
default:<br>
llvm_unreachable("unknown Config->EKind");<br>
}<br>
}<br>
<br>
-static std::string getRpath(opt::InputArgList &Args) {<br>
- std::vector<StringRef> V = args::getStrings(Args, OPT_rpath);<br>
- return llvm::join(V.begin(), V.end(), ":");<br>
+static std::string getRpath(opt::InputArgList &args) {<br>
+ std::vector<StringRef> v = args::getStrings(args, OPT_rpath);<br>
+ return llvm::join(v.begin(), v.end(), ":");<br>
}<br>
<br>
// Determines what we should do if there are remaining unresolved<br>
// symbols after the name resolution.<br>
-static UnresolvedPolicy getUnresolvedSymbolPolicy(opt::InputArgList &Args) {<br>
- UnresolvedPolicy ErrorOrWarn = Args.hasFlag(OPT_error_unresolved_symbols,<br>
+static UnresolvedPolicy getUnresolvedSymbolPolicy(opt::InputArgList &args) {<br>
+ UnresolvedPolicy errorOrWarn = args.hasFlag(OPT_error_unresolved_symbols,<br>
OPT_warn_unresolved_symbols, true)<br>
? UnresolvedPolicy::ReportError<br>
: UnresolvedPolicy::Warn;<br>
<br>
// Process the last of -unresolved-symbols, -no-undefined or -z defs.<br>
- for (auto *Arg : llvm::reverse(Args)) {<br>
- switch (Arg->getOption().getID()) {<br>
+ for (auto *arg : llvm::reverse(args)) {<br>
+ switch (arg->getOption().getID()) {<br>
case OPT_unresolved_symbols: {<br>
- StringRef S = Arg->getValue();<br>
- if (S == "ignore-all" || S == "ignore-in-object-files")<br>
+ StringRef s = arg->getValue();<br>
+ if (s == "ignore-all" || s == "ignore-in-object-files")<br>
return UnresolvedPolicy::Ignore;<br>
- if (S == "ignore-in-shared-libs" || S == "report-all")<br>
- return ErrorOrWarn;<br>
- error("unknown --unresolved-symbols value: " + S);<br>
+ if (s == "ignore-in-shared-libs" || s == "report-all")<br>
+ return errorOrWarn;<br>
+ error("unknown --unresolved-symbols value: " + s);<br>
continue;<br>
}<br>
case OPT_no_undefined:<br>
- return ErrorOrWarn;<br>
+ return errorOrWarn;<br>
case OPT_z:<br>
- if (StringRef(Arg->getValue()) == "defs")<br>
- return ErrorOrWarn;<br>
+ if (StringRef(arg->getValue()) == "defs")<br>
+ return errorOrWarn;<br>
continue;<br>
}<br>
}<br>
<br>
// -shared implies -unresolved-symbols=ignore-all because missing<br>
// symbols are likely to be resolved at runtime using other DSOs.<br>
- if (Config->Shared)<br>
+ if (config->shared)<br>
return UnresolvedPolicy::Ignore;<br>
- return ErrorOrWarn;<br>
+ return errorOrWarn;<br>
}<br>
<br>
-static Target2Policy getTarget2(opt::InputArgList &Args) {<br>
- StringRef S = Args.getLastArgValue(OPT_target2, "got-rel");<br>
- if (S == "rel")<br>
+static Target2Policy getTarget2(opt::InputArgList &args) {<br>
+ StringRef s = args.getLastArgValue(OPT_target2, "got-rel");<br>
+ if (s == "rel")<br>
return Target2Policy::Rel;<br>
- if (S == "abs")<br>
+ if (s == "abs")<br>
return Target2Policy::Abs;<br>
- if (S == "got-rel")<br>
+ if (s == "got-rel")<br>
return Target2Policy::GotRel;<br>
- error("unknown --target2 option: " + S);<br>
+ error("unknown --target2 option: " + s);<br>
return Target2Policy::GotRel;<br>
}<br>
<br>
-static bool isOutputFormatBinary(opt::InputArgList &Args) {<br>
- StringRef S = Args.getLastArgValue(OPT_oformat, "elf");<br>
- if (S == "binary")<br>
+static bool isOutputFormatBinary(opt::InputArgList &args) {<br>
+ StringRef s = args.getLastArgValue(OPT_oformat, "elf");<br>
+ if (s == "binary")<br>
return true;<br>
- if (!S.startswith("elf"))<br>
- error("unknown --oformat value: " + S);<br>
+ if (!s.startswith("elf"))<br>
+ error("unknown --oformat value: " + s);<br>
return false;<br>
}<br>
<br>
-static DiscardPolicy getDiscard(opt::InputArgList &Args) {<br>
- if (Args.hasArg(OPT_relocatable))<br>
+static DiscardPolicy getDiscard(opt::InputArgList &args) {<br>
+ if (args.hasArg(OPT_relocatable))<br>
return DiscardPolicy::None;<br>
<br>
- auto *Arg =<br>
- Args.getLastArg(OPT_discard_all, OPT_discard_locals, OPT_discard_none);<br>
- if (!Arg)<br>
+ auto *arg =<br>
+ args.getLastArg(OPT_discard_all, OPT_discard_locals, OPT_discard_none);<br>
+ if (!arg)<br>
return DiscardPolicy::Default;<br>
- if (Arg->getOption().getID() == OPT_discard_all)<br>
+ if (arg->getOption().getID() == OPT_discard_all)<br>
return DiscardPolicy::All;<br>
- if (Arg->getOption().getID() == OPT_discard_locals)<br>
+ if (arg->getOption().getID() == OPT_discard_locals)<br>
return DiscardPolicy::Locals;<br>
return DiscardPolicy::None;<br>
}<br>
<br>
-static StringRef getDynamicLinker(opt::InputArgList &Args) {<br>
- auto *Arg = Args.getLastArg(OPT_dynamic_linker, OPT_no_dynamic_linker);<br>
- if (!Arg || Arg->getOption().getID() == OPT_no_dynamic_linker)<br>
+static StringRef getDynamicLinker(opt::InputArgList &args) {<br>
+ auto *arg = args.getLastArg(OPT_dynamic_linker, OPT_no_dynamic_linker);<br>
+ if (!arg || arg->getOption().getID() == OPT_no_dynamic_linker)<br>
return "";<br>
- return Arg->getValue();<br>
+ return arg->getValue();<br>
}<br>
<br>
-static ICFLevel getICF(opt::InputArgList &Args) {<br>
- auto *Arg = Args.getLastArg(OPT_icf_none, OPT_icf_safe, OPT_icf_all);<br>
- if (!Arg || Arg->getOption().getID() == OPT_icf_none)<br>
+static ICFLevel getICF(opt::InputArgList &args) {<br>
+ auto *arg = args.getLastArg(OPT_icf_none, OPT_icf_safe, OPT_icf_all);<br>
+ if (!arg || arg->getOption().getID() == OPT_icf_none)<br>
return ICFLevel::None;<br>
- if (Arg->getOption().getID() == OPT_icf_safe)<br>
+ if (arg->getOption().getID() == OPT_icf_safe)<br>
return ICFLevel::Safe;<br>
return ICFLevel::All;<br>
}<br>
<br>
-static StripPolicy getStrip(opt::InputArgList &Args) {<br>
- if (Args.hasArg(OPT_relocatable))<br>
+static StripPolicy getStrip(opt::InputArgList &args) {<br>
+ if (args.hasArg(OPT_relocatable))<br>
return StripPolicy::None;<br>
<br>
- auto *Arg = Args.getLastArg(OPT_strip_all, OPT_strip_debug);<br>
- if (!Arg)<br>
+ auto *arg = args.getLastArg(OPT_strip_all, OPT_strip_debug);<br>
+ if (!arg)<br>
return StripPolicy::None;<br>
- if (Arg->getOption().getID() == OPT_strip_all)<br>
+ if (arg->getOption().getID() == OPT_strip_all)<br>
return StripPolicy::All;<br>
return StripPolicy::Debug;<br>
}<br>
<br>
-static uint64_t parseSectionAddress(StringRef S, opt::InputArgList &Args,<br>
- const opt::Arg &Arg) {<br>
- uint64_t VA = 0;<br>
- if (S.startswith("0x"))<br>
- S = S.drop_front(2);<br>
- if (!to_integer(S, VA, 16))<br>
- error("invalid argument: " + Arg.getAsString(Args));<br>
- return VA;<br>
-}<br>
-<br>
-static StringMap<uint64_t> getSectionStartMap(opt::InputArgList &Args) {<br>
- StringMap<uint64_t> Ret;<br>
- for (auto *Arg : Args.filtered(OPT_section_start)) {<br>
- StringRef Name;<br>
- StringRef Addr;<br>
- std::tie(Name, Addr) = StringRef(Arg->getValue()).split('=');<br>
- Ret[Name] = parseSectionAddress(Addr, Args, *Arg);<br>
- }<br>
-<br>
- if (auto *Arg = Args.getLastArg(OPT_Ttext))<br>
- Ret[".text"] = parseSectionAddress(Arg->getValue(), Args, *Arg);<br>
- if (auto *Arg = Args.getLastArg(OPT_Tdata))<br>
- Ret[".data"] = parseSectionAddress(Arg->getValue(), Args, *Arg);<br>
- if (auto *Arg = Args.getLastArg(OPT_Tbss))<br>
- Ret[".bss"] = parseSectionAddress(Arg->getValue(), Args, *Arg);<br>
- return Ret;<br>
-}<br>
-<br>
-static SortSectionPolicy getSortSection(opt::InputArgList &Args) {<br>
- StringRef S = Args.getLastArgValue(OPT_sort_section);<br>
- if (S == "alignment")<br>
+static uint64_t parseSectionAddress(StringRef s, opt::InputArgList &args,<br>
+ const opt::Arg &arg) {<br>
+ uint64_t va = 0;<br>
+ if (s.startswith("0x"))<br>
+ s = s.drop_front(2);<br>
+ if (!to_integer(s, va, 16))<br>
+ error("invalid argument: " + arg.getAsString(args));<br>
+ return va;<br>
+}<br>
+<br>
+static StringMap<uint64_t> getSectionStartMap(opt::InputArgList &args) {<br>
+ StringMap<uint64_t> ret;<br>
+ for (auto *arg : args.filtered(OPT_section_start)) {<br>
+ StringRef name;<br>
+ StringRef addr;<br>
+ std::tie(name, addr) = StringRef(arg->getValue()).split('=');<br>
+ ret[name] = parseSectionAddress(addr, args, *arg);<br>
+ }<br>
+<br>
+ if (auto *arg = args.getLastArg(OPT_Ttext))<br>
+ ret[".text"] = parseSectionAddress(arg->getValue(), args, *arg);<br>
+ if (auto *arg = args.getLastArg(OPT_Tdata))<br>
+ ret[".data"] = parseSectionAddress(arg->getValue(), args, *arg);<br>
+ if (auto *arg = args.getLastArg(OPT_Tbss))<br>
+ ret[".bss"] = parseSectionAddress(arg->getValue(), args, *arg);<br>
+ return ret;<br>
+}<br>
+<br>
+static SortSectionPolicy getSortSection(opt::InputArgList &args) {<br>
+ StringRef s = args.getLastArgValue(OPT_sort_section);<br>
+ if (s == "alignment")<br>
return SortSectionPolicy::Alignment;<br>
- if (S == "name")<br>
+ if (s == "name")<br>
return SortSectionPolicy::Name;<br>
- if (!S.empty())<br>
- error("unknown --sort-section rule: " + S);<br>
+ if (!s.empty())<br>
+ error("unknown --sort-section rule: " + s);<br>
return SortSectionPolicy::Default;<br>
}<br>
<br>
-static OrphanHandlingPolicy getOrphanHandling(opt::InputArgList &Args) {<br>
- StringRef S = Args.getLastArgValue(OPT_orphan_handling, "place");<br>
- if (S == "warn")<br>
+static OrphanHandlingPolicy getOrphanHandling(opt::InputArgList &args) {<br>
+ StringRef s = args.getLastArgValue(OPT_orphan_handling, "place");<br>
+ if (s == "warn")<br>
return OrphanHandlingPolicy::Warn;<br>
- if (S == "error")<br>
+ if (s == "error")<br>
return OrphanHandlingPolicy::Error;<br>
- if (S != "place")<br>
- error("unknown --orphan-handling mode: " + S);<br>
+ if (s != "place")<br>
+ error("unknown --orphan-handling mode: " + s);<br>
return OrphanHandlingPolicy::Place;<br>
}<br>
<br>
@@ -642,410 +642,410 @@ static OrphanHandlingPolicy getOrphanHan<br>
// synonym for "sha1" because all our hash functions including<br>
// -build-id=sha1 are actually tree hashes for performance reasons.<br>
static std::pair<BuildIdKind, std::vector<uint8_t>><br>
-getBuildId(opt::InputArgList &Args) {<br>
- auto *Arg = Args.getLastArg(OPT_build_id, OPT_build_id_eq);<br>
- if (!Arg)<br>
+getBuildId(opt::InputArgList &args) {<br>
+ auto *arg = args.getLastArg(OPT_build_id, OPT_build_id_eq);<br>
+ if (!arg)<br>
return {BuildIdKind::None, {}};<br>
<br>
- if (Arg->getOption().getID() == OPT_build_id)<br>
+ if (arg->getOption().getID() == OPT_build_id)<br>
return {BuildIdKind::Fast, {}};<br>
<br>
- StringRef S = Arg->getValue();<br>
- if (S == "fast")<br>
+ StringRef s = arg->getValue();<br>
+ if (s == "fast")<br>
return {BuildIdKind::Fast, {}};<br>
- if (S == "md5")<br>
+ if (s == "md5")<br>
return {BuildIdKind::Md5, {}};<br>
- if (S == "sha1" || S == "tree")<br>
+ if (s == "sha1" || s == "tree")<br>
return {BuildIdKind::Sha1, {}};<br>
- if (S == "uuid")<br>
+ if (s == "uuid")<br>
return {BuildIdKind::Uuid, {}};<br>
- if (S.startswith("0x"))<br>
- return {BuildIdKind::Hexstring, parseHex(S.substr(2))};<br>
+ if (s.startswith("0x"))<br>
+ return {BuildIdKind::Hexstring, parseHex(s.substr(2))};<br>
<br>
- if (S != "none")<br>
- error("unknown --build-id style: " + S);<br>
+ if (s != "none")<br>
+ error("unknown --build-id style: " + s);<br>
return {BuildIdKind::None, {}};<br>
}<br>
<br>
-static std::pair<bool, bool> getPackDynRelocs(opt::InputArgList &Args) {<br>
- StringRef S = Args.getLastArgValue(OPT_pack_dyn_relocs, "none");<br>
- if (S == "android")<br>
+static std::pair<bool, bool> getPackDynRelocs(opt::InputArgList &args) {<br>
+ StringRef s = args.getLastArgValue(OPT_pack_dyn_relocs, "none");<br>
+ if (s == "android")<br>
return {true, false};<br>
- if (S == "relr")<br>
+ if (s == "relr")<br>
return {false, true};<br>
- if (S == "android+relr")<br>
+ if (s == "android+relr")<br>
return {true, true};<br>
<br>
- if (S != "none")<br>
- error("unknown -pack-dyn-relocs format: " + S);<br>
+ if (s != "none")<br>
+ error("unknown -pack-dyn-relocs format: " + s);<br>
return {false, false};<br>
}<br>
<br>
-static void readCallGraph(MemoryBufferRef MB) {<br>
+static void readCallGraph(MemoryBufferRef mb) {<br>
// Build a map from symbol name to section<br>
- DenseMap<StringRef, Symbol *> Map;<br>
- for (InputFile *File : ObjectFiles)<br>
- for (Symbol *Sym : File->getSymbols())<br>
- Map[Sym->getName()] = Sym;<br>
-<br>
- auto FindSection = [&](StringRef Name) -> InputSectionBase * {<br>
- Symbol *Sym = Map.lookup(Name);<br>
- if (!Sym) {<br>
- if (Config->WarnSymbolOrdering)<br>
- warn(MB.getBufferIdentifier() + ": no such symbol: " + Name);<br>
+ DenseMap<StringRef, Symbol *> map;<br>
+ for (InputFile *file : objectFiles)<br>
+ for (Symbol *sym : file->getSymbols())<br>
+ map[sym->getName()] = sym;<br>
+<br>
+ auto findSection = [&](StringRef name) -> InputSectionBase * {<br>
+ Symbol *sym = map.lookup(name);<br>
+ if (!sym) {<br>
+ if (config->warnSymbolOrdering)<br>
+ warn(mb.getBufferIdentifier() + ": no such symbol: " + name);<br>
return nullptr;<br>
}<br>
- maybeWarnUnorderableSymbol(Sym);<br>
+ maybeWarnUnorderableSymbol(sym);<br>
<br>
- if (Defined *DR = dyn_cast_or_null<Defined>(Sym))<br>
- return dyn_cast_or_null<InputSectionBase>(DR->Section);<br>
+ if (Defined *dr = dyn_cast_or_null<Defined>(sym))<br>
+ return dyn_cast_or_null<InputSectionBase>(dr->section);<br>
return nullptr;<br>
};<br>
<br>
- for (StringRef Line : args::getLines(MB)) {<br>
- SmallVector<StringRef, 3> Fields;<br>
- Line.split(Fields, ' ');<br>
- uint64_t Count;<br>
+ for (StringRef line : args::getLines(mb)) {<br>
+ SmallVector<StringRef, 3> fields;<br>
+ line.split(fields, ' ');<br>
+ uint64_t count;<br>
<br>
- if (Fields.size() != 3 || !to_integer(Fields[2], Count)) {<br>
- error(MB.getBufferIdentifier() + ": parse error");<br>
+ if (fields.size() != 3 || !to_integer(fields[2], count)) {<br>
+ error(mb.getBufferIdentifier() + ": parse error");<br>
return;<br>
}<br>
<br>
- if (InputSectionBase *From = FindSection(Fields[0]))<br>
- if (InputSectionBase *To = FindSection(Fields[1]))<br>
- Config->CallGraphProfile[std::make_pair(From, To)] += Count;<br>
+ if (InputSectionBase *from = findSection(fields[0]))<br>
+ if (InputSectionBase *to = findSection(fields[1]))<br>
+ config->callGraphProfile[std::make_pair(from, to)] += count;<br>
}<br>
}<br>
<br>
template <class ELFT> static void readCallGraphsFromObjectFiles() {<br>
- for (auto File : ObjectFiles) {<br>
- auto *Obj = cast<ObjFile<ELFT>>(File);<br>
+ for (auto file : objectFiles) {<br>
+ auto *obj = cast<ObjFile<ELFT>>(file);<br>
<br>
- for (const Elf_CGProfile_Impl<ELFT> &CGPE : Obj->CGProfile) {<br>
- auto *FromSym = dyn_cast<Defined>(&Obj->getSymbol(CGPE.cgp_from));<br>
- auto *ToSym = dyn_cast<Defined>(&Obj->getSymbol(CGPE.cgp_to));<br>
- if (!FromSym || !ToSym)<br>
+ for (const Elf_CGProfile_Impl<ELFT> &cgpe : obj->cgProfile) {<br>
+ auto *fromSym = dyn_cast<Defined>(&obj->getSymbol(cgpe.cgp_from));<br>
+ auto *toSym = dyn_cast<Defined>(&obj->getSymbol(cgpe.cgp_to));<br>
+ if (!fromSym || !toSym)<br>
continue;<br>
<br>
- auto *From = dyn_cast_or_null<InputSectionBase>(FromSym->Section);<br>
- auto *To = dyn_cast_or_null<InputSectionBase>(ToSym->Section);<br>
- if (From && To)<br>
- Config->CallGraphProfile[{From, To}] += CGPE.cgp_weight;<br>
+ auto *from = dyn_cast_or_null<InputSectionBase>(fromSym->section);<br>
+ auto *to = dyn_cast_or_null<InputSectionBase>(toSym->section);<br>
+ if (from && to)<br>
+ config->callGraphProfile[{from, to}] += cgpe.cgp_weight;<br>
}<br>
}<br>
}<br>
<br>
-static bool getCompressDebugSections(opt::InputArgList &Args) {<br>
- StringRef S = Args.getLastArgValue(OPT_compress_debug_sections, "none");<br>
- if (S == "none")<br>
+static bool getCompressDebugSections(opt::InputArgList &args) {<br>
+ StringRef s = args.getLastArgValue(OPT_compress_debug_sections, "none");<br>
+ if (s == "none")<br>
return false;<br>
- if (S != "zlib")<br>
- error("unknown --compress-debug-sections value: " + S);<br>
+ if (s != "zlib")<br>
+ error("unknown --compress-debug-sections value: " + s);<br>
if (!zlib::isAvailable())<br>
error("--compress-debug-sections: zlib is not available");<br>
return true;<br>
}<br>
<br>
-static std::pair<StringRef, StringRef> getOldNewOptions(opt::InputArgList &Args,<br>
- unsigned Id) {<br>
- auto *Arg = Args.getLastArg(Id);<br>
- if (!Arg)<br>
+static std::pair<StringRef, StringRef> getOldNewOptions(opt::InputArgList &args,<br>
+ unsigned id) {<br>
+ auto *arg = args.getLastArg(id);<br>
+ if (!arg)<br>
return {"", ""};<br>
<br>
- StringRef S = Arg->getValue();<br>
- std::pair<StringRef, StringRef> Ret = S.split(';');<br>
- if (Ret.second.empty())<br>
- error(Arg->getSpelling() + " expects 'old;new' format, but got " + S);<br>
- return Ret;<br>
+ StringRef s = arg->getValue();<br>
+ std::pair<StringRef, StringRef> ret = s.split(';');<br>
+ if (ret.second.empty())<br>
+ error(arg->getSpelling() + " expects 'old;new' format, but got " + s);<br>
+ return ret;<br>
}<br>
<br>
// Parse the symbol ordering file and warn for any duplicate entries.<br>
-static std::vector<StringRef> getSymbolOrderingFile(MemoryBufferRef MB) {<br>
- SetVector<StringRef> Names;<br>
- for (StringRef S : args::getLines(MB))<br>
- if (!Names.insert(S) && Config->WarnSymbolOrdering)<br>
- warn(MB.getBufferIdentifier() + ": duplicate ordered symbol: " + S);<br>
+static std::vector<StringRef> getSymbolOrderingFile(MemoryBufferRef mb) {<br>
+ SetVector<StringRef> names;<br>
+ for (StringRef s : args::getLines(mb))<br>
+ if (!names.insert(s) && config->warnSymbolOrdering)<br>
+ warn(mb.getBufferIdentifier() + ": duplicate ordered symbol: " + s);<br>
<br>
- return Names.takeVector();<br>
+ return names.takeVector();<br>
}<br>
<br>
-static void parseClangOption(StringRef Opt, const Twine &Msg) {<br>
- std::string Err;<br>
- raw_string_ostream OS(Err);<br>
+static void parseClangOption(StringRef opt, const Twine &msg) {<br>
+ std::string err;<br>
+ raw_string_ostream os(err);<br>
<br>
- const char *Argv[] = {Config->ProgName.data(), Opt.data()};<br>
- if (cl::ParseCommandLineOptions(2, Argv, "", &OS))<br>
+ const char *argv[] = {config->progName.data(), opt.data()};<br>
+ if (cl::ParseCommandLineOptions(2, argv, "", &os))<br>
return;<br>
- OS.flush();<br>
- error(Msg + ": " + StringRef(Err).trim());<br>
+ os.flush();<br>
+ error(msg + ": " + StringRef(err).trim());<br>
}<br>
<br>
// Initializes Config members by the command line options.<br>
-static void readConfigs(opt::InputArgList &Args) {<br>
- errorHandler().Verbose = Args.hasArg(OPT_verbose);<br>
+static void readConfigs(opt::InputArgList &args) {<br>
+ errorHandler().Verbose = args.hasArg(OPT_verbose);<br>
errorHandler().FatalWarnings =<br>
- Args.hasFlag(OPT_fatal_warnings, OPT_no_fatal_warnings, false);<br>
- ThreadsEnabled = Args.hasFlag(OPT_threads, OPT_no_threads, true);<br>
+ args.hasFlag(OPT_fatal_warnings, OPT_no_fatal_warnings, false);<br>
+ ThreadsEnabled = args.hasFlag(OPT_threads, OPT_no_threads, true);<br>
<br>
- Config->AllowMultipleDefinition =<br>
- Args.hasFlag(OPT_allow_multiple_definition,<br>
+ config->allowMultipleDefinition =<br>
+ args.hasFlag(OPT_allow_multiple_definition,<br>
OPT_no_allow_multiple_definition, false) ||<br>
- hasZOption(Args, "muldefs");<br>
- Config->AllowShlibUndefined =<br>
- Args.hasFlag(OPT_allow_shlib_undefined, OPT_no_allow_shlib_undefined,<br>
- Args.hasArg(OPT_shared));<br>
- Config->AuxiliaryList = args::getStrings(Args, OPT_auxiliary);<br>
- Config->Bsymbolic = Args.hasArg(OPT_Bsymbolic);<br>
- Config->BsymbolicFunctions = Args.hasArg(OPT_Bsymbolic_functions);<br>
- Config->CheckSections =<br>
- Args.hasFlag(OPT_check_sections, OPT_no_check_sections, true);<br>
- Config->Chroot = Args.getLastArgValue(OPT_chroot);<br>
- Config->CompressDebugSections = getCompressDebugSections(Args);<br>
- Config->Cref = Args.hasFlag(OPT_cref, OPT_no_cref, false);<br>
- Config->DefineCommon = Args.hasFlag(OPT_define_common, OPT_no_define_common,<br>
- !Args.hasArg(OPT_relocatable));<br>
- Config->Demangle = Args.hasFlag(OPT_demangle, OPT_no_demangle, true);<br>
- Config->DependentLibraries = Args.hasFlag(OPT_dependent_libraries, OPT_no_dependent_libraries, true);<br>
- Config->DisableVerify = Args.hasArg(OPT_disable_verify);<br>
- Config->Discard = getDiscard(Args);<br>
- Config->DwoDir = Args.getLastArgValue(OPT_plugin_opt_dwo_dir_eq);<br>
- Config->DynamicLinker = getDynamicLinker(Args);<br>
- Config->EhFrameHdr =<br>
- Args.hasFlag(OPT_eh_frame_hdr, OPT_no_eh_frame_hdr, false);<br>
- Config->EmitLLVM = Args.hasArg(OPT_plugin_opt_emit_llvm, false);<br>
- Config->EmitRelocs = Args.hasArg(OPT_emit_relocs);<br>
- Config->CallGraphProfileSort = Args.hasFlag(<br>
+ hasZOption(args, "muldefs");<br>
+ config->allowShlibUndefined =<br>
+ args.hasFlag(OPT_allow_shlib_undefined, OPT_no_allow_shlib_undefined,<br>
+ args.hasArg(OPT_shared));<br>
+ config->auxiliaryList = args::getStrings(args, OPT_auxiliary);<br>
+ config->bsymbolic = args.hasArg(OPT_Bsymbolic);<br>
+ config->bsymbolicFunctions = args.hasArg(OPT_Bsymbolic_functions);<br>
+ config->checkSections =<br>
+ args.hasFlag(OPT_check_sections, OPT_no_check_sections, true);<br>
+ config->chroot = args.getLastArgValue(OPT_chroot);<br>
+ config->compressDebugSections = getCompressDebugSections(args);<br>
+ config->cref = args.hasFlag(OPT_cref, OPT_no_cref, false);<br>
+ config->defineCommon = args.hasFlag(OPT_define_common, OPT_no_define_common,<br>
+ !args.hasArg(OPT_relocatable));<br>
+ config->demangle = args.hasFlag(OPT_demangle, OPT_no_demangle, true);<br>
+ config->dependentLibraries = args.hasFlag(OPT_dependent_libraries, OPT_no_dependent_libraries, true);<br>
+ config->disableVerify = args.hasArg(OPT_disable_verify);<br>
+ config->discard = getDiscard(args);<br>
+ config->dwoDir = args.getLastArgValue(OPT_plugin_opt_dwo_dir_eq);<br>
+ config->dynamicLinker = getDynamicLinker(args);<br>
+ config->ehFrameHdr =<br>
+ args.hasFlag(OPT_eh_frame_hdr, OPT_no_eh_frame_hdr, false);<br>
+ config->emitLLVM = args.hasArg(OPT_plugin_opt_emit_llvm, false);<br>
+ config->emitRelocs = args.hasArg(OPT_emit_relocs);<br>
+ config->callGraphProfileSort = args.hasFlag(<br>
OPT_call_graph_profile_sort, OPT_no_call_graph_profile_sort, true);<br>
- Config->EnableNewDtags =<br>
- Args.hasFlag(OPT_enable_new_dtags, OPT_disable_new_dtags, true);<br>
- Config->Entry = Args.getLastArgValue(OPT_entry);<br>
- Config->ExecuteOnly =<br>
- Args.hasFlag(OPT_execute_only, OPT_no_execute_only, false);<br>
- Config->ExportDynamic =<br>
- Args.hasFlag(OPT_export_dynamic, OPT_no_export_dynamic, false);<br>
- Config->FilterList = args::getStrings(Args, OPT_filter);<br>
- Config->Fini = Args.getLastArgValue(OPT_fini, "_fini");<br>
- Config->FixCortexA53Errata843419 = Args.hasArg(OPT_fix_cortex_a53_843419);<br>
- Config->ForceBTI = Args.hasArg(OPT_force_bti);<br>
- Config->RequireCET = Args.hasArg(OPT_require_cet);<br>
- Config->GcSections = Args.hasFlag(OPT_gc_sections, OPT_no_gc_sections, false);<br>
- Config->GnuUnique = Args.hasFlag(OPT_gnu_unique, OPT_no_gnu_unique, true);<br>
- Config->GdbIndex = Args.hasFlag(OPT_gdb_index, OPT_no_gdb_index, false);<br>
- Config->ICF = getICF(Args);<br>
- Config->IgnoreDataAddressEquality =<br>
- Args.hasArg(OPT_ignore_data_address_equality);<br>
- Config->IgnoreFunctionAddressEquality =<br>
- Args.hasArg(OPT_ignore_function_address_equality);<br>
- Config->Init = Args.getLastArgValue(OPT_init, "_init");<br>
- Config->LTOAAPipeline = Args.getLastArgValue(OPT_lto_aa_pipeline);<br>
- Config->LTOCSProfileGenerate = Args.hasArg(OPT_lto_cs_profile_generate);<br>
- Config->LTOCSProfileFile = Args.getLastArgValue(OPT_lto_cs_profile_file);<br>
- Config->LTODebugPassManager = Args.hasArg(OPT_lto_debug_pass_manager);<br>
- Config->LTONewPassManager = Args.hasArg(OPT_lto_new_pass_manager);<br>
- Config->LTONewPmPasses = Args.getLastArgValue(OPT_lto_newpm_passes);<br>
- Config->LTOO = args::getInteger(Args, OPT_lto_O, 2);<br>
- Config->LTOObjPath = Args.getLastArgValue(OPT_plugin_opt_obj_path_eq);<br>
- Config->LTOPartitions = args::getInteger(Args, OPT_lto_partitions, 1);<br>
- Config->LTOSampleProfile = Args.getLastArgValue(OPT_lto_sample_profile);<br>
- Config->MapFile = Args.getLastArgValue(OPT_Map);<br>
- Config->MipsGotSize = args::getInteger(Args, OPT_mips_got_size, 0xfff0);<br>
- Config->MergeArmExidx =<br>
- Args.hasFlag(OPT_merge_exidx_entries, OPT_no_merge_exidx_entries, true);<br>
- Config->Nmagic = Args.hasFlag(OPT_nmagic, OPT_no_nmagic, false);<br>
- Config->NoinhibitExec = Args.hasArg(OPT_noinhibit_exec);<br>
- Config->Nostdlib = Args.hasArg(OPT_nostdlib);<br>
- Config->OFormatBinary = isOutputFormatBinary(Args);<br>
- Config->Omagic = Args.hasFlag(OPT_omagic, OPT_no_omagic, false);<br>
- Config->OptRemarksFilename = Args.getLastArgValue(OPT_opt_remarks_filename);<br>
- Config->OptRemarksPasses = Args.getLastArgValue(OPT_opt_remarks_passes);<br>
- Config->OptRemarksWithHotness = Args.hasArg(OPT_opt_remarks_with_hotness);<br>
- Config->OptRemarksFormat = Args.getLastArgValue(OPT_opt_remarks_format);<br>
- Config->Optimize = args::getInteger(Args, OPT_O, 1);<br>
- Config->OrphanHandling = getOrphanHandling(Args);<br>
- Config->OutputFile = Args.getLastArgValue(OPT_o);<br>
- Config->PacPlt = Args.hasArg(OPT_pac_plt);<br>
- Config->Pie = Args.hasFlag(OPT_pie, OPT_no_pie, false);<br>
- Config->PrintIcfSections =<br>
- Args.hasFlag(OPT_print_icf_sections, OPT_no_print_icf_sections, false);<br>
- Config->PrintGcSections =<br>
- Args.hasFlag(OPT_print_gc_sections, OPT_no_print_gc_sections, false);<br>
- Config->PrintSymbolOrder =<br>
- Args.getLastArgValue(OPT_print_symbol_order);<br>
- Config->Rpath = getRpath(Args);<br>
- Config->Relocatable = Args.hasArg(OPT_relocatable);<br>
- Config->SaveTemps = Args.hasArg(OPT_save_temps);<br>
- Config->SearchPaths = args::getStrings(Args, OPT_library_path);<br>
- Config->SectionStartMap = getSectionStartMap(Args);<br>
- Config->Shared = Args.hasArg(OPT_shared);<br>
- Config->SingleRoRx = Args.hasArg(OPT_no_rosegment);<br>
- Config->SoName = Args.getLastArgValue(OPT_soname);<br>
- Config->SortSection = getSortSection(Args);<br>
- Config->SplitStackAdjustSize = args::getInteger(Args, OPT_split_stack_adjust_size, 16384);<br>
- Config->Strip = getStrip(Args);<br>
- Config->Sysroot = Args.getLastArgValue(OPT_sysroot);<br>
- Config->Target1Rel = Args.hasFlag(OPT_target1_rel, OPT_target1_abs, false);<br>
- Config->Target2 = getTarget2(Args);<br>
- Config->ThinLTOCacheDir = Args.getLastArgValue(OPT_thinlto_cache_dir);<br>
- Config->ThinLTOCachePolicy = CHECK(<br>
- parseCachePruningPolicy(Args.getLastArgValue(OPT_thinlto_cache_policy)),<br>
+ config->enableNewDtags =<br>
+ args.hasFlag(OPT_enable_new_dtags, OPT_disable_new_dtags, true);<br>
+ config->entry = args.getLastArgValue(OPT_entry);<br>
+ config->executeOnly =<br>
+ args.hasFlag(OPT_execute_only, OPT_no_execute_only, false);<br>
+ config->exportDynamic =<br>
+ args.hasFlag(OPT_export_dynamic, OPT_no_export_dynamic, false);<br>
+ config->filterList = args::getStrings(args, OPT_filter);<br>
+ config->fini = args.getLastArgValue(OPT_fini, "_fini");<br>
+ config->fixCortexA53Errata843419 = args.hasArg(OPT_fix_cortex_a53_843419);<br>
+ config->forceBTI = args.hasArg(OPT_force_bti);<br>
+ config->requireCET = args.hasArg(OPT_require_cet);<br>
+ config->gcSections = args.hasFlag(OPT_gc_sections, OPT_no_gc_sections, false);<br>
+ config->gnuUnique = args.hasFlag(OPT_gnu_unique, OPT_no_gnu_unique, true);<br>
+ config->gdbIndex = args.hasFlag(OPT_gdb_index, OPT_no_gdb_index, false);<br>
+ config->icf = getICF(args);<br>
+ config->ignoreDataAddressEquality =<br>
+ args.hasArg(OPT_ignore_data_address_equality);<br>
+ config->ignoreFunctionAddressEquality =<br>
+ args.hasArg(OPT_ignore_function_address_equality);<br>
+ config->init = args.getLastArgValue(OPT_init, "_init");<br>
+ config->ltoAAPipeline = args.getLastArgValue(OPT_lto_aa_pipeline);<br>
+ config->ltoCSProfileGenerate = args.hasArg(OPT_lto_cs_profile_generate);<br>
+ config->ltoCSProfileFile = args.getLastArgValue(OPT_lto_cs_profile_file);<br>
+ config->ltoDebugPassManager = args.hasArg(OPT_lto_debug_pass_manager);<br>
+ config->ltoNewPassManager = args.hasArg(OPT_lto_new_pass_manager);<br>
+ config->ltoNewPmPasses = args.getLastArgValue(OPT_lto_newpm_passes);<br>
+ config->ltoo = args::getInteger(args, OPT_lto_O, 2);<br>
+ config->ltoObjPath = args.getLastArgValue(OPT_plugin_opt_obj_path_eq);<br>
+ config->ltoPartitions = args::getInteger(args, OPT_lto_partitions, 1);<br>
+ config->ltoSampleProfile = args.getLastArgValue(OPT_lto_sample_profile);<br>
+ config->mapFile = args.getLastArgValue(OPT_Map);<br>
+ config->mipsGotSize = args::getInteger(args, OPT_mips_got_size, 0xfff0);<br>
+ config->mergeArmExidx =<br>
+ args.hasFlag(OPT_merge_exidx_entries, OPT_no_merge_exidx_entries, true);<br>
+ config->nmagic = args.hasFlag(OPT_nmagic, OPT_no_nmagic, false);<br>
+ config->noinhibitExec = args.hasArg(OPT_noinhibit_exec);<br>
+ config->nostdlib = args.hasArg(OPT_nostdlib);<br>
+ config->oFormatBinary = isOutputFormatBinary(args);<br>
+ config->omagic = args.hasFlag(OPT_omagic, OPT_no_omagic, false);<br>
+ config->optRemarksFilename = args.getLastArgValue(OPT_opt_remarks_filename);<br>
+ config->optRemarksPasses = args.getLastArgValue(OPT_opt_remarks_passes);<br>
+ config->optRemarksWithHotness = args.hasArg(OPT_opt_remarks_with_hotness);<br>
+ config->optRemarksFormat = args.getLastArgValue(OPT_opt_remarks_format);<br>
+ config->optimize = args::getInteger(args, OPT_O, 1);<br>
+ config->orphanHandling = getOrphanHandling(args);<br>
+ config->outputFile = args.getLastArgValue(OPT_o);<br>
+ config->pacPlt = args.hasArg(OPT_pac_plt);<br>
+ config->pie = args.hasFlag(OPT_pie, OPT_no_pie, false);<br>
+ config->printIcfSections =<br>
+ args.hasFlag(OPT_print_icf_sections, OPT_no_print_icf_sections, false);<br>
+ config->printGcSections =<br>
+ args.hasFlag(OPT_print_gc_sections, OPT_no_print_gc_sections, false);<br>
+ config->printSymbolOrder =<br>
+ args.getLastArgValue(OPT_print_symbol_order);<br>
+ config->rpath = getRpath(args);<br>
+ config->relocatable = args.hasArg(OPT_relocatable);<br>
+ config->saveTemps = args.hasArg(OPT_save_temps);<br>
+ config->searchPaths = args::getStrings(args, OPT_library_path);<br>
+ config->sectionStartMap = getSectionStartMap(args);<br>
+ config->shared = args.hasArg(OPT_shared);<br>
+ config->singleRoRx = args.hasArg(OPT_no_rosegment);<br>
+ config->soName = args.getLastArgValue(OPT_soname);<br>
+ config->sortSection = getSortSection(args);<br>
+ config->splitStackAdjustSize = args::getInteger(args, OPT_split_stack_adjust_size, 16384);<br>
+ config->strip = getStrip(args);<br>
+ config->sysroot = args.getLastArgValue(OPT_sysroot);<br>
+ config->target1Rel = args.hasFlag(OPT_target1_rel, OPT_target1_abs, false);<br>
+ config->target2 = getTarget2(args);<br>
+ config->thinLTOCacheDir = args.getLastArgValue(OPT_thinlto_cache_dir);<br>
+ config->thinLTOCachePolicy = CHECK(<br>
+ parseCachePruningPolicy(args.getLastArgValue(OPT_thinlto_cache_policy)),<br>
"--thinlto-cache-policy: invalid cache policy");<br>
- Config->ThinLTOEmitImportsFiles =<br>
- Args.hasArg(OPT_plugin_opt_thinlto_emit_imports_files);<br>
- Config->ThinLTOIndexOnly = Args.hasArg(OPT_plugin_opt_thinlto_index_only) ||<br>
- Args.hasArg(OPT_plugin_opt_thinlto_index_only_eq);<br>
- Config->ThinLTOIndexOnlyArg =<br>
- Args.getLastArgValue(OPT_plugin_opt_thinlto_index_only_eq);<br>
- Config->ThinLTOJobs = args::getInteger(Args, OPT_thinlto_jobs, -1u);<br>
- Config->ThinLTOObjectSuffixReplace =<br>
- getOldNewOptions(Args, OPT_plugin_opt_thinlto_object_suffix_replace_eq);<br>
- Config->ThinLTOPrefixReplace =<br>
- getOldNewOptions(Args, OPT_plugin_opt_thinlto_prefix_replace_eq);<br>
- Config->Trace = Args.hasArg(OPT_trace);<br>
- Config->Undefined = args::getStrings(Args, OPT_undefined);<br>
- Config->UndefinedVersion =<br>
- Args.hasFlag(OPT_undefined_version, OPT_no_undefined_version, true);<br>
- Config->UseAndroidRelrTags = Args.hasFlag(<br>
+ config->thinLTOEmitImportsFiles =<br>
+ args.hasArg(OPT_plugin_opt_thinlto_emit_imports_files);<br>
+ config->thinLTOIndexOnly = args.hasArg(OPT_plugin_opt_thinlto_index_only) ||<br>
+ args.hasArg(OPT_plugin_opt_thinlto_index_only_eq);<br>
+ config->thinLTOIndexOnlyArg =<br>
+ args.getLastArgValue(OPT_plugin_opt_thinlto_index_only_eq);<br>
+ config->thinLTOJobs = args::getInteger(args, OPT_thinlto_jobs, -1u);<br>
+ config->thinLTOObjectSuffixReplace =<br>
+ getOldNewOptions(args, OPT_plugin_opt_thinlto_object_suffix_replace_eq);<br>
+ config->thinLTOPrefixReplace =<br>
+ getOldNewOptions(args, OPT_plugin_opt_thinlto_prefix_replace_eq);<br>
+ config->trace = args.hasArg(OPT_trace);<br>
+ config->undefined = args::getStrings(args, OPT_undefined);<br>
+ config->undefinedVersion =<br>
+ args.hasFlag(OPT_undefined_version, OPT_no_undefined_version, true);<br>
+ config->useAndroidRelrTags = args.hasFlag(<br>
OPT_use_android_relr_tags, OPT_no_use_android_relr_tags, false);<br>
- Config->UnresolvedSymbols = getUnresolvedSymbolPolicy(Args);<br>
- Config->WarnBackrefs =<br>
- Args.hasFlag(OPT_warn_backrefs, OPT_no_warn_backrefs, false);<br>
- Config->WarnCommon = Args.hasFlag(OPT_warn_common, OPT_no_warn_common, false);<br>
- Config->WarnIfuncTextrel =<br>
- Args.hasFlag(OPT_warn_ifunc_textrel, OPT_no_warn_ifunc_textrel, false);<br>
- Config->WarnSymbolOrdering =<br>
- Args.hasFlag(OPT_warn_symbol_ordering, OPT_no_warn_symbol_ordering, true);<br>
- Config->ZCombreloc = getZFlag(Args, "combreloc", "nocombreloc", true);<br>
- Config->ZCopyreloc = getZFlag(Args, "copyreloc", "nocopyreloc", true);<br>
- Config->ZExecstack = getZFlag(Args, "execstack", "noexecstack", false);<br>
- Config->ZGlobal = hasZOption(Args, "global");<br>
- Config->ZHazardplt = hasZOption(Args, "hazardplt");<br>
- Config->ZIfuncNoplt = hasZOption(Args, "ifunc-noplt");<br>
- Config->ZInitfirst = hasZOption(Args, "initfirst");<br>
- Config->ZInterpose = hasZOption(Args, "interpose");<br>
- Config->ZKeepTextSectionPrefix = getZFlag(<br>
- Args, "keep-text-section-prefix", "nokeep-text-section-prefix", false);<br>
- Config->ZNodefaultlib = hasZOption(Args, "nodefaultlib");<br>
- Config->ZNodelete = hasZOption(Args, "nodelete");<br>
- Config->ZNodlopen = hasZOption(Args, "nodlopen");<br>
- Config->ZNow = getZFlag(Args, "now", "lazy", false);<br>
- Config->ZOrigin = hasZOption(Args, "origin");<br>
- Config->ZRelro = getZFlag(Args, "relro", "norelro", true);<br>
- Config->ZRetpolineplt = hasZOption(Args, "retpolineplt");<br>
- Config->ZRodynamic = hasZOption(Args, "rodynamic");<br>
- Config->ZStackSize = args::getZOptionValue(Args, OPT_z, "stack-size", 0);<br>
- Config->ZText = getZFlag(Args, "text", "notext", true);<br>
- Config->ZWxneeded = hasZOption(Args, "wxneeded");<br>
+ config->unresolvedSymbols = getUnresolvedSymbolPolicy(args);<br>
+ config->warnBackrefs =<br>
+ args.hasFlag(OPT_warn_backrefs, OPT_no_warn_backrefs, false);<br>
+ config->warnCommon = args.hasFlag(OPT_warn_common, OPT_no_warn_common, false);<br>
+ config->warnIfuncTextrel =<br>
+ args.hasFlag(OPT_warn_ifunc_textrel, OPT_no_warn_ifunc_textrel, false);<br>
+ config->warnSymbolOrdering =<br>
+ args.hasFlag(OPT_warn_symbol_ordering, OPT_no_warn_symbol_ordering, true);<br>
+ config->zCombreloc = getZFlag(args, "combreloc", "nocombreloc", true);<br>
+ config->zCopyreloc = getZFlag(args, "copyreloc", "nocopyreloc", true);<br>
+ config->zExecstack = getZFlag(args, "execstack", "noexecstack", false);<br>
+ config->zGlobal = hasZOption(args, "global");<br>
+ config->zHazardplt = hasZOption(args, "hazardplt");<br>
+ config->zIfuncNoplt = hasZOption(args, "ifunc-noplt");<br>
+ config->zInitfirst = hasZOption(args, "initfirst");<br>
+ config->zInterpose = hasZOption(args, "interpose");<br>
+ config->zKeepTextSectionPrefix = getZFlag(<br>
+ args, "keep-text-section-prefix", "nokeep-text-section-prefix", false);<br>
+ config->zNodefaultlib = hasZOption(args, "nodefaultlib");<br>
+ config->zNodelete = hasZOption(args, "nodelete");<br>
+ config->zNodlopen = hasZOption(args, "nodlopen");<br>
+ config->zNow = getZFlag(args, "now", "lazy", false);<br>
+ config->zOrigin = hasZOption(args, "origin");<br>
+ config->zRelro = getZFlag(args, "relro", "norelro", true);<br>
+ config->zRetpolineplt = hasZOption(args, "retpolineplt");<br>
+ config->zRodynamic = hasZOption(args, "rodynamic");<br>
+ config->zStackSize = args::getZOptionValue(args, OPT_z, "stack-size", 0);<br>
+ config->zText = getZFlag(args, "text", "notext", true);<br>
+ config->zWxneeded = hasZOption(args, "wxneeded");<br>
<br>
// Parse LTO options.<br>
- if (auto *Arg = Args.getLastArg(OPT_plugin_opt_mcpu_eq))<br>
- parseClangOption(Saver.save("-mcpu=" + StringRef(Arg->getValue())),<br>
- Arg->getSpelling());<br>
+ if (auto *arg = args.getLastArg(OPT_plugin_opt_mcpu_eq))<br>
+ parseClangOption(Saver.save("-mcpu=" + StringRef(arg->getValue())),<br>
+ arg->getSpelling());<br>
<br>
- for (auto *Arg : Args.filtered(OPT_plugin_opt))<br>
- parseClangOption(Arg->getValue(), Arg->getSpelling());<br>
+ for (auto *arg : args.filtered(OPT_plugin_opt))<br>
+ parseClangOption(arg->getValue(), arg->getSpelling());<br>
<br>
// Parse -mllvm options.<br>
- for (auto *Arg : Args.filtered(OPT_mllvm))<br>
- parseClangOption(Arg->getValue(), Arg->getSpelling());<br>
+ for (auto *arg : args.filtered(OPT_mllvm))<br>
+ parseClangOption(arg->getValue(), arg->getSpelling());<br>
<br>
- if (Config->LTOO > 3)<br>
- error("invalid optimization level for LTO: " + Twine(Config->LTOO));<br>
- if (Config->LTOPartitions == 0)<br>
+ if (config->ltoo > 3)<br>
+ error("invalid optimization level for LTO: " + Twine(config->ltoo));<br>
+ if (config->ltoPartitions == 0)<br>
error("--lto-partitions: number of threads must be > 0");<br>
- if (Config->ThinLTOJobs == 0)<br>
+ if (config->thinLTOJobs == 0)<br>
error("--thinlto-jobs: number of threads must be > 0");<br>
<br>
- if (Config->SplitStackAdjustSize < 0)<br>
+ if (config->splitStackAdjustSize < 0)<br>
error("--split-stack-adjust-size: size must be >= 0");<br>
<br>
// Parse ELF{32,64}{LE,BE} and CPU type.<br>
- if (auto *Arg = Args.getLastArg(OPT_m)) {<br>
- StringRef S = Arg->getValue();<br>
- std::tie(Config->EKind, Config->EMachine, Config->OSABI) =<br>
- parseEmulation(S);<br>
- Config->MipsN32Abi = (S == "elf32btsmipn32" || S == "elf32ltsmipn32");<br>
- Config->Emulation = S;<br>
+ if (auto *arg = args.getLastArg(OPT_m)) {<br>
+ StringRef s = arg->getValue();<br>
+ std::tie(config->ekind, config->emachine, config->osabi) =<br>
+ parseEmulation(s);<br>
+ config->mipsN32Abi = (s == "elf32btsmipn32" || s == "elf32ltsmipn32");<br>
+ config->emulation = s;<br>
}<br>
<br>
// Parse -hash-style={sysv,gnu,both}.<br>
- if (auto *Arg = Args.getLastArg(OPT_hash_style)) {<br>
- StringRef S = Arg->getValue();<br>
- if (S == "sysv")<br>
- Config->SysvHash = true;<br>
- else if (S == "gnu")<br>
- Config->GnuHash = true;<br>
- else if (S == "both")<br>
- Config->SysvHash = Config->GnuHash = true;<br>
+ if (auto *arg = args.getLastArg(OPT_hash_style)) {<br>
+ StringRef s = arg->getValue();<br>
+ if (s == "sysv")<br>
+ config->sysvHash = true;<br>
+ else if (s == "gnu")<br>
+ config->gnuHash = true;<br>
+ else if (s == "both")<br>
+ config->sysvHash = config->gnuHash = true;<br>
else<br>
- error("unknown -hash-style: " + S);<br>
+ error("unknown -hash-style: " + s);<br>
}<br>
<br>
- if (Args.hasArg(OPT_print_map))<br>
- Config->MapFile = "-";<br>
+ if (args.hasArg(OPT_print_map))<br>
+ config->mapFile = "-";<br>
<br>
// Page alignment can be disabled by the -n (--nmagic) and -N (--omagic).<br>
// As PT_GNU_RELRO relies on Paging, do not create it when we have disabled<br>
// it.<br>
- if (Config->Nmagic || Config->Omagic)<br>
- Config->ZRelro = false;<br>
+ if (config->nmagic || config->omagic)<br>
+ config->zRelro = false;<br>
<br>
- std::tie(Config->BuildId, Config->BuildIdVector) = getBuildId(Args);<br>
+ std::tie(config->buildId, config->buildIdVector) = getBuildId(args);<br>
<br>
- std::tie(Config->AndroidPackDynRelocs, Config->RelrPackDynRelocs) =<br>
- getPackDynRelocs(Args);<br>
+ std::tie(config->androidPackDynRelocs, config->relrPackDynRelocs) =<br>
+ getPackDynRelocs(args);<br>
<br>
- if (auto *Arg = Args.getLastArg(OPT_symbol_ordering_file)){<br>
- if (Args.hasArg(OPT_call_graph_ordering_file))<br>
+ if (auto *arg = args.getLastArg(OPT_symbol_ordering_file)){<br>
+ if (args.hasArg(OPT_call_graph_ordering_file))<br>
error("--symbol-ordering-file and --call-graph-order-file "<br>
"may not be used together");<br>
- if (Optional<MemoryBufferRef> Buffer = readFile(Arg->getValue())){<br>
- Config->SymbolOrderingFile = getSymbolOrderingFile(*Buffer);<br>
+ if (Optional<MemoryBufferRef> buffer = readFile(arg->getValue())){<br>
+ config->symbolOrderingFile = getSymbolOrderingFile(*buffer);<br>
// Also need to disable CallGraphProfileSort to prevent<br>
// LLD order symbols with CGProfile<br>
- Config->CallGraphProfileSort = false;<br>
+ config->callGraphProfileSort = false;<br>
}<br>
}<br>
<br>
// If --retain-symbol-file is used, we'll keep only the symbols listed in<br>
// the file and discard all others.<br>
- if (auto *Arg = Args.getLastArg(OPT_retain_symbols_file)) {<br>
- Config->DefaultSymbolVersion = VER_NDX_LOCAL;<br>
- if (Optional<MemoryBufferRef> Buffer = readFile(Arg->getValue()))<br>
- for (StringRef S : args::getLines(*Buffer))<br>
- Config->VersionScriptGlobals.push_back(<br>
- {S, /*IsExternCpp*/ false, /*HasWildcard*/ false});<br>
+ if (auto *arg = args.getLastArg(OPT_retain_symbols_file)) {<br>
+ config->defaultSymbolVersion = VER_NDX_LOCAL;<br>
+ if (Optional<MemoryBufferRef> buffer = readFile(arg->getValue()))<br>
+ for (StringRef s : args::getLines(*buffer))<br>
+ config->versionScriptGlobals.push_back(<br>
+ {s, /*IsExternCpp*/ false, /*HasWildcard*/ false});<br>
}<br>
<br>
- bool HasExportDynamic =<br>
- Args.hasFlag(OPT_export_dynamic, OPT_no_export_dynamic, false);<br>
+ bool hasExportDynamic =<br>
+ args.hasFlag(OPT_export_dynamic, OPT_no_export_dynamic, false);<br>
<br>
// Parses -dynamic-list and -export-dynamic-symbol. They make some<br>
// symbols private. Note that -export-dynamic takes precedence over them<br>
// as it says all symbols should be exported.<br>
- if (!HasExportDynamic) {<br>
- for (auto *Arg : Args.filtered(OPT_dynamic_list))<br>
- if (Optional<MemoryBufferRef> Buffer = readFile(Arg->getValue()))<br>
- readDynamicList(*Buffer);<br>
-<br>
- for (auto *Arg : Args.filtered(OPT_export_dynamic_symbol))<br>
- Config->DynamicList.push_back(<br>
- {Arg->getValue(), /*IsExternCpp*/ false, /*HasWildcard*/ false});<br>
+ if (!hasExportDynamic) {<br>
+ for (auto *arg : args.filtered(OPT_dynamic_list))<br>
+ if (Optional<MemoryBufferRef> buffer = readFile(arg->getValue()))<br>
+ readDynamicList(*buffer);<br>
+<br>
+ for (auto *arg : args.filtered(OPT_export_dynamic_symbol))<br>
+ config->dynamicList.push_back(<br>
+ {arg->getValue(), /*IsExternCpp*/ false, /*HasWildcard*/ false});<br>
}<br>
<br>
// If --export-dynamic-symbol=foo is given and symbol foo is defined in<br>
// an object file in an archive file, that object file should be pulled<br>
// out and linked. (It doesn't have to behave like that from technical<br>
// point of view, but this is needed for compatibility with GNU.)<br>
- for (auto *Arg : Args.filtered(OPT_export_dynamic_symbol))<br>
- Config->Undefined.push_back(Arg->getValue());<br>
+ for (auto *arg : args.filtered(OPT_export_dynamic_symbol))<br>
+ config->undefined.push_back(arg->getValue());<br>
<br>
- for (auto *Arg : Args.filtered(OPT_version_script))<br>
- if (Optional<std::string> Path = searchScript(Arg->getValue())) {<br>
- if (Optional<MemoryBufferRef> Buffer = readFile(*Path))<br>
- readVersionScript(*Buffer);<br>
+ for (auto *arg : args.filtered(OPT_version_script))<br>
+ if (Optional<std::string> path = searchScript(arg->getValue())) {<br>
+ if (Optional<MemoryBufferRef> buffer = readFile(*path))<br>
+ readVersionScript(*buffer);<br>
} else {<br>
- error(Twine("cannot find version script ") + Arg->getValue());<br>
+ error(Twine("cannot find version script ") + arg->getValue());<br>
}<br>
}<br>
<br>
@@ -1053,18 +1053,18 @@ static void readConfigs(opt::InputArgLis<br>
// command line options, but computed based on other Config values.<br>
// This function initialize such members. See Config.h for the details<br>
// of these values.<br>
-static void setConfigs(opt::InputArgList &Args) {<br>
- ELFKind K = Config->EKind;<br>
- uint16_t M = Config->EMachine;<br>
-<br>
- Config->CopyRelocs = (Config->Relocatable || Config->EmitRelocs);<br>
- Config->Is64 = (K == ELF64LEKind || K == ELF64BEKind);<br>
- Config->IsLE = (K == ELF32LEKind || K == ELF64LEKind);<br>
- Config->Endianness = Config->IsLE ? endianness::little : endianness::big;<br>
- Config->IsMips64EL = (K == ELF64LEKind && M == EM_MIPS);<br>
- Config->Pic = Config->Pie || Config->Shared;<br>
- Config->PicThunk = Args.hasArg(OPT_pic_veneer, Config->Pic);<br>
- Config->Wordsize = Config->Is64 ? 8 : 4;<br>
+static void setConfigs(opt::InputArgList &args) {<br>
+ ELFKind k = config->ekind;<br>
+ uint16_t m = config->emachine;<br>
+<br>
+ config->copyRelocs = (config->relocatable || config->emitRelocs);<br>
+ config->is64 = (k == ELF64LEKind || k == ELF64BEKind);<br>
+ config->isLE = (k == ELF32LEKind || k == ELF64LEKind);<br>
+ config->endianness = config->isLE ? endianness::little : endianness::big;<br>
+ config->isMips64EL = (k == ELF64LEKind && m == EM_MIPS);<br>
+ config->isPic = config->pie || config->shared;<br>
+ config->picThunk = args.hasArg(OPT_pic_veneer, config->isPic);<br>
+ config->wordsize = config->is64 ? 8 : 4;<br>
<br>
// ELF defines two different ways to store relocation addends as shown below:<br>
//<br>
@@ -1079,150 +1079,150 @@ static void setConfigs(opt::InputArgList<br>
// You cannot choose which one, Rel or Rela, you want to use. Instead each<br>
// ABI defines which one you need to use. The following expression expresses<br>
// that.<br>
- Config->IsRela = M == EM_AARCH64 || M == EM_AMDGPU || M == EM_HEXAGON ||<br>
- M == EM_PPC || M == EM_PPC64 || M == EM_RISCV ||<br>
- M == EM_X86_64;<br>
+ config->isRela = m == EM_AARCH64 || m == EM_AMDGPU || m == EM_HEXAGON ||<br>
+ m == EM_PPC || m == EM_PPC64 || m == EM_RISCV ||<br>
+ m == EM_X86_64;<br>
<br>
// If the output uses REL relocations we must store the dynamic relocation<br>
// addends to the output sections. We also store addends for RELA relocations<br>
// if --apply-dynamic-relocs is used.<br>
// We default to not writing the addends when using RELA relocations since<br>
// any standard conforming tool can find it in r_addend.<br>
- Config->WriteAddends = Args.hasFlag(OPT_apply_dynamic_relocs,<br>
+ config->writeAddends = args.hasFlag(OPT_apply_dynamic_relocs,<br>
OPT_no_apply_dynamic_relocs, false) ||<br>
- !Config->IsRela;<br>
+ !config->isRela;<br>
<br>
- Config->TocOptimize =<br>
- Args.hasFlag(OPT_toc_optimize, OPT_no_toc_optimize, M == EM_PPC64);<br>
+ config->tocOptimize =<br>
+ args.hasFlag(OPT_toc_optimize, OPT_no_toc_optimize, m == EM_PPC64);<br>
}<br>
<br>
// Returns a value of "-format" option.<br>
-static bool isFormatBinary(StringRef S) {<br>
- if (S == "binary")<br>
+static bool isFormatBinary(StringRef s) {<br>
+ if (s == "binary")<br>
return true;<br>
- if (S == "elf" || S == "default")<br>
+ if (s == "elf" || s == "default")<br>
return false;<br>
- error("unknown -format value: " + S +<br>
+ error("unknown -format value: " + s +<br>
" (supported formats: elf, default, binary)");<br>
return false;<br>
}<br>
<br>
-void LinkerDriver::createFiles(opt::InputArgList &Args) {<br>
+void LinkerDriver::createFiles(opt::InputArgList &args) {<br>
// For --{push,pop}-state.<br>
- std::vector<std::tuple<bool, bool, bool>> Stack;<br>
+ std::vector<std::tuple<bool, bool, bool>> stack;<br>
<br>
// Iterate over argv to process input files and positional arguments.<br>
- for (auto *Arg : Args) {<br>
- switch (Arg->getOption().getID()) {<br>
+ for (auto *arg : args) {<br>
+ switch (arg->getOption().getID()) {<br>
case OPT_library:<br>
- addLibrary(Arg->getValue());<br>
+ addLibrary(arg->getValue());<br>
break;<br>
case OPT_INPUT:<br>
- addFile(Arg->getValue(), /*WithLOption=*/false);<br>
+ addFile(arg->getValue(), /*WithLOption=*/false);<br>
break;<br>
case OPT_defsym: {<br>
- StringRef From;<br>
- StringRef To;<br>
- std::tie(From, To) = StringRef(Arg->getValue()).split('=');<br>
- if (From.empty() || To.empty())<br>
- error("-defsym: syntax error: " + StringRef(Arg->getValue()));<br>
+ StringRef from;<br>
+ StringRef to;<br>
+ std::tie(from, to) = StringRef(arg->getValue()).split('=');<br>
+ if (from.empty() || to.empty())<br>
+ error("-defsym: syntax error: " + StringRef(arg->getValue()));<br>
else<br>
- readDefsym(From, MemoryBufferRef(To, "-defsym"));<br>
+ readDefsym(from, MemoryBufferRef(to, "-defsym"));<br>
break;<br>
}<br>
case OPT_script:<br>
- if (Optional<std::string> Path = searchScript(Arg->getValue())) {<br>
- if (Optional<MemoryBufferRef> MB = readFile(*Path))<br>
- readLinkerScript(*MB);<br>
+ if (Optional<std::string> path = searchScript(arg->getValue())) {<br>
+ if (Optional<MemoryBufferRef> mb = readFile(*path))<br>
+ readLinkerScript(*mb);<br>
break;<br>
}<br>
- error(Twine("cannot find linker script ") + Arg->getValue());<br>
+ error(Twine("cannot find linker script ") + arg->getValue());<br>
break;<br>
case OPT_as_needed:<br>
- Config->AsNeeded = true;<br>
+ config->asNeeded = true;<br>
break;<br>
case OPT_format:<br>
- Config->FormatBinary = isFormatBinary(Arg->getValue());<br>
+ config->formatBinary = isFormatBinary(arg->getValue());<br>
break;<br>
case OPT_no_as_needed:<br>
- Config->AsNeeded = false;<br>
+ config->asNeeded = false;<br>
break;<br>
case OPT_Bstatic:<br>
case OPT_omagic:<br>
case OPT_nmagic:<br>
- Config->Static = true;<br>
+ config->isStatic = true;<br>
break;<br>
case OPT_Bdynamic:<br>
- Config->Static = false;<br>
+ config->isStatic = false;<br>
break;<br>
case OPT_whole_archive:<br>
- InWholeArchive = true;<br>
+ inWholeArchive = true;<br>
break;<br>
case OPT_no_whole_archive:<br>
- InWholeArchive = false;<br>
+ inWholeArchive = false;<br>
break;<br>
case OPT_just_symbols:<br>
- if (Optional<MemoryBufferRef> MB = readFile(Arg->getValue())) {<br>
- Files.push_back(createObjectFile(*MB));<br>
- Files.back()->JustSymbols = true;<br>
+ if (Optional<MemoryBufferRef> mb = readFile(arg->getValue())) {<br>
+ files.push_back(createObjectFile(*mb));<br>
+ files.back()->justSymbols = true;<br>
}<br>
break;<br>
case OPT_start_group:<br>
- if (InputFile::IsInGroup)<br>
+ if (InputFile::isInGroup)<br>
error("nested --start-group");<br>
- InputFile::IsInGroup = true;<br>
+ InputFile::isInGroup = true;<br>
break;<br>
case OPT_end_group:<br>
- if (!InputFile::IsInGroup)<br>
+ if (!InputFile::isInGroup)<br>
error("stray --end-group");<br>
- InputFile::IsInGroup = false;<br>
- ++InputFile::NextGroupId;<br>
+ InputFile::isInGroup = false;<br>
+ ++InputFile::nextGroupId;<br>
break;<br>
case OPT_start_lib:<br>
- if (InLib)<br>
+ if (inLib)<br>
error("nested --start-lib");<br>
- if (InputFile::IsInGroup)<br>
+ if (InputFile::isInGroup)<br>
error("may not nest --start-lib in --start-group");<br>
- InLib = true;<br>
- InputFile::IsInGroup = true;<br>
+ inLib = true;<br>
+ InputFile::isInGroup = true;<br>
break;<br>
case OPT_end_lib:<br>
- if (!InLib)<br>
+ if (!inLib)<br>
error("stray --end-lib");<br>
- InLib = false;<br>
- InputFile::IsInGroup = false;<br>
- ++InputFile::NextGroupId;<br>
+ inLib = false;<br>
+ InputFile::isInGroup = false;<br>
+ ++InputFile::nextGroupId;<br>
break;<br>
case OPT_push_state:<br>
- Stack.emplace_back(Config->AsNeeded, Config->Static, InWholeArchive);<br>
+ stack.emplace_back(config->asNeeded, config->isStatic, inWholeArchive);<br>
break;<br>
case OPT_pop_state:<br>
- if (Stack.empty()) {<br>
+ if (stack.empty()) {<br>
error("unbalanced --push-state/--pop-state");<br>
break;<br>
}<br>
- std::tie(Config->AsNeeded, Config->Static, InWholeArchive) = Stack.back();<br>
- Stack.pop_back();<br>
+ std::tie(config->asNeeded, config->isStatic, inWholeArchive) = stack.back();<br>
+ stack.pop_back();<br>
break;<br>
}<br>
}<br>
<br>
- if (Files.empty() && errorCount() == 0)<br>
+ if (files.empty() && errorCount() == 0)<br>
error("no input files");<br>
}<br>
<br>
// If -m <machine_type> was not given, infer it from object files.<br>
void LinkerDriver::inferMachineType() {<br>
- if (Config->EKind != ELFNoneKind)<br>
+ if (config->ekind != ELFNoneKind)<br>
return;<br>
<br>
- for (InputFile *F : Files) {<br>
- if (F->EKind == ELFNoneKind)<br>
+ for (InputFile *f : files) {<br>
+ if (f->ekind == ELFNoneKind)<br>
continue;<br>
- Config->EKind = F->EKind;<br>
- Config->EMachine = F->EMachine;<br>
- Config->OSABI = F->OSABI;<br>
- Config->MipsN32Abi = Config->EMachine == EM_MIPS && isMipsN32Abi(F);<br>
+ config->ekind = f->ekind;<br>
+ config->emachine = f->emachine;<br>
+ config->osabi = f->osabi;<br>
+ config->mipsN32Abi = config->emachine == EM_MIPS && isMipsN32Abi(f);<br>
return;<br>
}<br>
error("target emulation unknown: -m or at least one .o file required");<br>
@@ -1230,72 +1230,72 @@ void LinkerDriver::inferMachineType() {<br>
<br>
// Parse -z max-page-size=<value>. The default value is defined by<br>
// each target.<br>
-static uint64_t getMaxPageSize(opt::InputArgList &Args) {<br>
- uint64_t Val = args::getZOptionValue(Args, OPT_z, "max-page-size",<br>
- Target->DefaultMaxPageSize);<br>
- if (!isPowerOf2_64(Val))<br>
+static uint64_t getMaxPageSize(opt::InputArgList &args) {<br>
+ uint64_t val = args::getZOptionValue(args, OPT_z, "max-page-size",<br>
+ target->defaultMaxPageSize);<br>
+ if (!isPowerOf2_64(val))<br>
error("max-page-size: value isn't a power of 2");<br>
- if (Config->Nmagic || Config->Omagic) {<br>
- if (Val != Target->DefaultMaxPageSize)<br>
+ if (config->nmagic || config->omagic) {<br>
+ if (val != target->defaultMaxPageSize)<br>
warn("-z max-page-size set, but paging disabled by omagic or nmagic");<br>
return 1;<br>
}<br>
- return Val;<br>
+ return val;<br>
}<br>
<br>
// Parse -z common-page-size=<value>. The default value is defined by<br>
// each target.<br>
-static uint64_t getCommonPageSize(opt::InputArgList &Args) {<br>
- uint64_t Val = args::getZOptionValue(Args, OPT_z, "common-page-size",<br>
- Target->DefaultCommonPageSize);<br>
- if (!isPowerOf2_64(Val))<br>
+static uint64_t getCommonPageSize(opt::InputArgList &args) {<br>
+ uint64_t val = args::getZOptionValue(args, OPT_z, "common-page-size",<br>
+ target->defaultCommonPageSize);<br>
+ if (!isPowerOf2_64(val))<br>
error("common-page-size: value isn't a power of 2");<br>
- if (Config->Nmagic || Config->Omagic) {<br>
- if (Val != Target->DefaultCommonPageSize)<br>
+ if (config->nmagic || config->omagic) {<br>
+ if (val != target->defaultCommonPageSize)<br>
warn("-z common-page-size set, but paging disabled by omagic or nmagic");<br>
return 1;<br>
}<br>
// CommonPageSize can't be larger than MaxPageSize.<br>
- if (Val > Config->MaxPageSize)<br>
- Val = Config->MaxPageSize;<br>
- return Val;<br>
+ if (val > config->maxPageSize)<br>
+ val = config->maxPageSize;<br>
+ return val;<br>
}<br>
<br>
// Parses -image-base option.<br>
-static Optional<uint64_t> getImageBase(opt::InputArgList &Args) {<br>
+static Optional<uint64_t> getImageBase(opt::InputArgList &args) {<br>
// Because we are using "Config->MaxPageSize" here, this function has to be<br>
// called after the variable is initialized.<br>
- auto *Arg = Args.getLastArg(OPT_image_base);<br>
- if (!Arg)<br>
+ auto *arg = args.getLastArg(OPT_image_base);<br>
+ if (!arg)<br>
return None;<br>
<br>
- StringRef S = Arg->getValue();<br>
- uint64_t V;<br>
- if (!to_integer(S, V)) {<br>
- error("-image-base: number expected, but got " + S);<br>
+ StringRef s = arg->getValue();<br>
+ uint64_t v;<br>
+ if (!to_integer(s, v)) {<br>
+ error("-image-base: number expected, but got " + s);<br>
return 0;<br>
}<br>
- if ((V % Config->MaxPageSize) != 0)<br>
- warn("-image-base: address isn't multiple of page size: " + S);<br>
- return V;<br>
+ if ((v % config->maxPageSize) != 0)<br>
+ warn("-image-base: address isn't multiple of page size: " + s);<br>
+ return v;<br>
}<br>
<br>
// Parses `--exclude-libs=lib,lib,...`.<br>
// The library names may be delimited by commas or colons.<br>
-static DenseSet<StringRef> getExcludeLibs(opt::InputArgList &Args) {<br>
- DenseSet<StringRef> Ret;<br>
- for (auto *Arg : Args.filtered(OPT_exclude_libs)) {<br>
- StringRef S = Arg->getValue();<br>
+static DenseSet<StringRef> getExcludeLibs(opt::InputArgList &args) {<br>
+ DenseSet<StringRef> ret;<br>
+ for (auto *arg : args.filtered(OPT_exclude_libs)) {<br>
+ StringRef s = arg->getValue();<br>
for (;;) {<br>
- size_t Pos = S.find_first_of(",:");<br>
- if (Pos == StringRef::npos)<br>
+ size_t pos = s.find_first_of(",:");<br>
+ if (pos == StringRef::npos)<br>
break;<br>
- Ret.insert(S.substr(0, Pos));<br>
- S = S.substr(Pos + 1);<br>
+ ret.insert(s.substr(0, pos));<br>
+ s = s.substr(pos + 1);<br>
}<br>
- Ret.insert(S);<br>
+ ret.insert(s);<br>
}<br>
- return Ret;<br>
+ return ret;<br>
}<br>
<br>
// Handles the -exclude-libs option. If a static library file is specified<br>
@@ -1304,71 +1304,71 @@ static DenseSet<StringRef> getExcludeLib<br>
// A special library name "ALL" means all archive files.<br>
//<br>
// This is not a popular option, but some programs such as bionic libc use it.<br>
-static void excludeLibs(opt::InputArgList &Args) {<br>
- DenseSet<StringRef> Libs = getExcludeLibs(Args);<br>
- bool All = Libs.count("ALL");<br>
-<br>
- auto Visit = [&](InputFile *File) {<br>
- if (!File->ArchiveName.empty())<br>
- if (All || Libs.count(path::filename(File->ArchiveName)))<br>
- for (Symbol *Sym : File->getSymbols())<br>
- if (!Sym->isLocal() && Sym->File == File)<br>
- Sym->VersionId = VER_NDX_LOCAL;<br>
+static void excludeLibs(opt::InputArgList &args) {<br>
+ DenseSet<StringRef> libs = getExcludeLibs(args);<br>
+ bool all = libs.count("ALL");<br>
+<br>
+ auto visit = [&](InputFile *file) {<br>
+ if (!file->archiveName.empty())<br>
+ if (all || libs.count(path::filename(file->archiveName)))<br>
+ for (Symbol *sym : file->getSymbols())<br>
+ if (!sym->isLocal() && sym->file == file)<br>
+ sym->versionId = VER_NDX_LOCAL;<br>
};<br>
<br>
- for (InputFile *File : ObjectFiles)<br>
- Visit(File);<br>
+ for (InputFile *file : objectFiles)<br>
+ visit(file);<br>
<br>
- for (BitcodeFile *File : BitcodeFiles)<br>
- Visit(File);<br>
+ for (BitcodeFile *file : bitcodeFiles)<br>
+ visit(file);<br>
}<br>
<br>
// Force Sym to be entered in the output. Used for -u or equivalent.<br>
-static void handleUndefined(Symbol *Sym) {<br>
+static void handleUndefined(Symbol *sym) {<br>
// Since a symbol may not be used inside the program, LTO may<br>
// eliminate it. Mark the symbol as "used" to prevent it.<br>
- Sym->IsUsedInRegularObj = true;<br>
+ sym->isUsedInRegularObj = true;<br>
<br>
- if (Sym->isLazy())<br>
- Sym->fetch();<br>
+ if (sym->isLazy())<br>
+ sym->fetch();<br>
}<br>
<br>
// As an extention to GNU linkers, lld supports a variant of `-u`<br>
// which accepts wildcard patterns. All symbols that match a given<br>
// pattern are handled as if they were given by `-u`.<br>
-static void handleUndefinedGlob(StringRef Arg) {<br>
- Expected<GlobPattern> Pat = GlobPattern::create(Arg);<br>
- if (!Pat) {<br>
- error("--undefined-glob: " + toString(Pat.takeError()));<br>
+static void handleUndefinedGlob(StringRef arg) {<br>
+ Expected<GlobPattern> pat = GlobPattern::create(arg);<br>
+ if (!pat) {<br>
+ error("--undefined-glob: " + toString(pat.takeError()));<br>
return;<br>
}<br>
<br>
- std::vector<Symbol *> Syms;<br>
- Symtab->forEachSymbol([&](Symbol *Sym) {<br>
+ std::vector<Symbol *> syms;<br>
+ symtab->forEachSymbol([&](Symbol *sym) {<br>
// Calling Sym->fetch() from here is not safe because it may<br>
// add new symbols to the symbol table, invalidating the<br>
// current iterator. So we just keep a note.<br>
- if (Pat->match(Sym->getName()))<br>
- Syms.push_back(Sym);<br>
+ if (pat->match(sym->getName()))<br>
+ syms.push_back(sym);<br>
});<br>
<br>
- for (Symbol *Sym : Syms)<br>
- handleUndefined(Sym);<br>
+ for (Symbol *sym : syms)<br>
+ handleUndefined(sym);<br>
}<br>
<br>
-static void handleLibcall(StringRef Name) {<br>
- Symbol *Sym = Symtab->find(Name);<br>
- if (!Sym || !Sym->isLazy())<br>
+static void handleLibcall(StringRef name) {<br>
+ Symbol *sym = symtab->find(name);<br>
+ if (!sym || !sym->isLazy())<br>
return;<br>
<br>
- MemoryBufferRef MB;<br>
- if (auto *LO = dyn_cast<LazyObject>(Sym))<br>
- MB = LO->File->MB;<br>
+ MemoryBufferRef mb;<br>
+ if (auto *lo = dyn_cast<LazyObject>(sym))<br>
+ mb = lo->file->mb;<br>
else<br>
- MB = cast<LazyArchive>(Sym)->getMemberBuffer();<br>
+ mb = cast<LazyArchive>(sym)->getMemberBuffer();<br>
<br>
- if (isBitcode(MB))<br>
- Sym->fetch();<br>
+ if (isBitcode(mb))<br>
+ sym->fetch();<br>
}<br>
<br>
// Replaces common symbols with defined symbols reside in .bss sections.<br>
@@ -1376,17 +1376,17 @@ static void handleLibcall(StringRef Name<br>
// result, the passes after the symbol resolution won't see any<br>
// symbols of type CommonSymbol.<br>
static void replaceCommonSymbols() {<br>
- Symtab->forEachSymbol([](Symbol *Sym) {<br>
- auto *S = dyn_cast<CommonSymbol>(Sym);<br>
- if (!S)<br>
+ symtab->forEachSymbol([](Symbol *sym) {<br>
+ auto *s = dyn_cast<CommonSymbol>(sym);<br>
+ if (!s)<br>
return;<br>
<br>
- auto *Bss = make<BssSection>("COMMON", S->Size, S->Alignment);<br>
- Bss->File = S->File;<br>
- Bss->markDead();<br>
- InputSections.push_back(Bss);<br>
- S->replace(Defined{S->File, S->getName(), S->Binding, S->StOther, S->Type,<br>
- /*Value=*/0, S->Size, Bss});<br>
+ auto *bss = make<BssSection>("COMMON", s->size, s->alignment);<br>
+ bss->file = s->file;<br>
+ bss->markDead();<br>
+ inputSections.push_back(bss);<br>
+ s->replace(Defined{s->file, s->getName(), s->binding, s->stOther, s->type,<br>
+ /*Value=*/0, s->size, bss});<br>
});<br>
}<br>
<br>
@@ -1395,78 +1395,78 @@ static void replaceCommonSymbols() {<br>
// created from the DSO. Otherwise, they become dangling references<br>
// that point to a non-existent DSO.<br>
static void demoteSharedSymbols() {<br>
- Symtab->forEachSymbol([](Symbol *Sym) {<br>
- auto *S = dyn_cast<SharedSymbol>(Sym);<br>
- if (!S || S->getFile().IsNeeded)<br>
+ symtab->forEachSymbol([](Symbol *sym) {<br>
+ auto *s = dyn_cast<SharedSymbol>(sym);<br>
+ if (!s || s->getFile().isNeeded)<br>
return;<br>
<br>
- bool Used = S->Used;<br>
- S->replace(Undefined{nullptr, S->getName(), STB_WEAK, S->StOther, S->Type});<br>
- S->Used = Used;<br>
+ bool used = s->used;<br>
+ s->replace(Undefined{nullptr, s->getName(), STB_WEAK, s->stOther, s->type});<br>
+ s->used = used;<br>
});<br>
}<br>
<br>
// The section referred to by S is considered address-significant. Set the<br>
// KeepUnique flag on the section if appropriate.<br>
-static void markAddrsig(Symbol *S) {<br>
- if (auto *D = dyn_cast_or_null<Defined>(S))<br>
- if (D->Section)<br>
+static void markAddrsig(Symbol *s) {<br>
+ if (auto *d = dyn_cast_or_null<Defined>(s))<br>
+ if (d->section)<br>
// We don't need to keep text sections unique under --icf=all even if they<br>
// are address-significant.<br>
- if (Config->ICF == ICFLevel::Safe || !(D->Section->Flags & SHF_EXECINSTR))<br>
- D->Section->KeepUnique = true;<br>
+ if (config->icf == ICFLevel::Safe || !(d->section->flags & SHF_EXECINSTR))<br>
+ d->section->keepUnique = true;<br>
}<br>
<br>
// Record sections that define symbols mentioned in --keep-unique <symbol><br>
// and symbols referred to by address-significance tables. These sections are<br>
// ineligible for ICF.<br>
template <class ELFT><br>
-static void findKeepUniqueSections(opt::InputArgList &Args) {<br>
- for (auto *Arg : Args.filtered(OPT_keep_unique)) {<br>
- StringRef Name = Arg->getValue();<br>
- auto *D = dyn_cast_or_null<Defined>(Symtab->find(Name));<br>
- if (!D || !D->Section) {<br>
- warn("could not find symbol " + Name + " to keep unique");<br>
+static void findKeepUniqueSections(opt::InputArgList &args) {<br>
+ for (auto *arg : args.filtered(OPT_keep_unique)) {<br>
+ StringRef name = arg->getValue();<br>
+ auto *d = dyn_cast_or_null<Defined>(symtab->find(name));<br>
+ if (!d || !d->section) {<br>
+ warn("could not find symbol " + name + " to keep unique");<br>
continue;<br>
}<br>
- D->Section->KeepUnique = true;<br>
+ d->section->keepUnique = true;<br>
}<br>
<br>
// --icf=all --ignore-data-address-equality means that we can ignore<br>
// the dynsym and address-significance tables entirely.<br>
- if (Config->ICF == ICFLevel::All && Config->IgnoreDataAddressEquality)<br>
+ if (config->icf == ICFLevel::All && config->ignoreDataAddressEquality)<br>
return;<br>
<br>
// Symbols in the dynsym could be address-significant in other executables<br>
// or DSOs, so we conservatively mark them as address-significant.<br>
- Symtab->forEachSymbol([&](Symbol *Sym) {<br>
- if (Sym->includeInDynsym())<br>
- markAddrsig(Sym);<br>
+ symtab->forEachSymbol([&](Symbol *sym) {<br>
+ if (sym->includeInDynsym())<br>
+ markAddrsig(sym);<br>
});<br>
<br>
// Visit the address-significance table in each object file and mark each<br>
// referenced symbol as address-significant.<br>
- for (InputFile *F : ObjectFiles) {<br>
- auto *Obj = cast<ObjFile<ELFT>>(F);<br>
- ArrayRef<Symbol *> Syms = Obj->getSymbols();<br>
- if (Obj->AddrsigSec) {<br>
- ArrayRef<uint8_t> Contents =<br>
- check(Obj->getObj().getSectionContents(Obj->AddrsigSec));<br>
- const uint8_t *Cur = Contents.begin();<br>
- while (Cur != Contents.end()) {<br>
- unsigned Size;<br>
- const char *Err;<br>
- uint64_t SymIndex = decodeULEB128(Cur, &Size, Contents.end(), &Err);<br>
- if (Err)<br>
- fatal(toString(F) + ": could not decode addrsig section: " + Err);<br>
- markAddrsig(Syms[SymIndex]);<br>
- Cur += Size;<br>
+ for (InputFile *f : objectFiles) {<br>
+ auto *obj = cast<ObjFile<ELFT>>(f);<br>
+ ArrayRef<Symbol *> syms = obj->getSymbols();<br>
+ if (obj->addrsigSec) {<br>
+ ArrayRef<uint8_t> contents =<br>
+ check(obj->getObj().getSectionContents(obj->addrsigSec));<br>
+ const uint8_t *cur = contents.begin();<br>
+ while (cur != contents.end()) {<br>
+ unsigned size;<br>
+ const char *err;<br>
+ uint64_t symIndex = decodeULEB128(cur, &size, contents.end(), &err);<br>
+ if (err)<br>
+ fatal(toString(f) + ": could not decode addrsig section: " + err);<br>
+ markAddrsig(syms[symIndex]);<br>
+ cur += size;<br>
}<br>
} else {<br>
// If an object file does not have an address-significance table,<br>
// conservatively mark all of its symbols as address-significant.<br>
- for (Symbol *S : Syms)<br>
- markAddrsig(S);<br>
+ for (Symbol *s : syms)<br>
+ markAddrsig(s);<br>
}<br>
}<br>
}<br>
@@ -1475,20 +1475,20 @@ static void findKeepUniqueSections(opt::<br>
// are used to control which partition a symbol is allocated to. See<br>
// <a href="https://urldefense.proofpoint.com/v2/url?u=https-3A__lld.llvm.org_Partitions.html&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=xehk92--dowqd4Is0R_S0eI2s9rLRkmcxAQgihwuQW8&e=" rel="noreferrer" target="_blank">https://urldefense.proofpoint.com/v2/url?u=https-3A__lld.llvm.org_Partitions.html&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=xehk92--dowqd4Is0R_S0eI2s9rLRkmcxAQgihwuQW8&e=</a> for more details on partitions.<br>
template <typename ELFT><br>
-static void readSymbolPartitionSection(InputSectionBase *S) {<br>
+static void readSymbolPartitionSection(InputSectionBase *s) {<br>
// Read the relocation that refers to the partition's entry point symbol.<br>
- Symbol *Sym;<br>
- if (S->AreRelocsRela)<br>
- Sym = &S->getFile<ELFT>()->getRelocTargetSym(S->template relas<ELFT>()[0]);<br>
+ Symbol *sym;<br>
+ if (s->areRelocsRela)<br>
+ sym = &s->getFile<ELFT>()->getRelocTargetSym(s->template relas<ELFT>()[0]);<br>
else<br>
- Sym = &S->getFile<ELFT>()->getRelocTargetSym(S->template rels<ELFT>()[0]);<br>
- if (!isa<Defined>(Sym) || !Sym->includeInDynsym())<br>
+ sym = &s->getFile<ELFT>()->getRelocTargetSym(s->template rels<ELFT>()[0]);<br>
+ if (!isa<Defined>(sym) || !sym->includeInDynsym())<br>
return;<br>
<br>
- StringRef PartName = reinterpret_cast<const char *>(S->data().data());<br>
- for (Partition &Part : Partitions) {<br>
- if (Part.Name == PartName) {<br>
- Sym->Partition = Part.getNumber();<br>
+ StringRef partName = reinterpret_cast<const char *>(s->data().data());<br>
+ for (Partition &part : partitions) {<br>
+ if (<a href="http://part.name" rel="noreferrer" target="_blank">part.name</a> == partName) {<br>
+ sym->partition = part.getNumber();<br>
return;<br>
}<br>
}<br>
@@ -1496,33 +1496,33 @@ static void readSymbolPartitionSection(I<br>
// Forbid partitions from being used on incompatible targets, and forbid them<br>
// from being used together with various linker features that assume a single<br>
// set of output sections.<br>
- if (Script->HasSectionsCommand)<br>
- error(toString(S->File) +<br>
+ if (script->hasSectionsCommand)<br>
+ error(toString(s->file) +<br>
": partitions cannot be used with the SECTIONS command");<br>
- if (Script->hasPhdrsCommands())<br>
- error(toString(S->File) +<br>
+ if (script->hasPhdrsCommands())<br>
+ error(toString(s->file) +<br>
": partitions cannot be used with the PHDRS command");<br>
- if (!Config->SectionStartMap.empty())<br>
- error(toString(S->File) + ": partitions cannot be used with "<br>
+ if (!config->sectionStartMap.empty())<br>
+ error(toString(s->file) + ": partitions cannot be used with "<br>
"--section-start, -Ttext, -Tdata or -Tbss");<br>
- if (Config->EMachine == EM_MIPS)<br>
- error(toString(S->File) + ": partitions cannot be used on this target");<br>
+ if (config->emachine == EM_MIPS)<br>
+ error(toString(s->file) + ": partitions cannot be used on this target");<br>
<br>
// Impose a limit of no more than 254 partitions. This limit comes from the<br>
// sizes of the Partition fields in InputSectionBase and Symbol, as well as<br>
// the amount of space devoted to the partition number in RankFlags.<br>
- if (Partitions.size() == 254)<br>
+ if (partitions.size() == 254)<br>
fatal("may not have more than 254 partitions");<br>
<br>
- Partitions.emplace_back();<br>
- Partition &NewPart = Partitions.back();<br>
- NewPart.Name = PartName;<br>
- Sym->Partition = NewPart.getNumber();<br>
+ partitions.emplace_back();<br>
+ Partition &newPart = partitions.back();<br>
+ newPart.name = partName;<br>
+ sym->partition = newPart.getNumber();<br>
}<br>
<br>
-static Symbol *addUndefined(StringRef Name) {<br>
- return Symtab->addSymbol(<br>
- Undefined{nullptr, Name, STB_GLOBAL, STV_DEFAULT, 0});<br>
+static Symbol *addUndefined(StringRef name) {<br>
+ return symtab->addSymbol(<br>
+ Undefined{nullptr, name, STB_GLOBAL, STV_DEFAULT, 0});<br>
}<br>
<br>
// This function is where all the optimizations of link-time<br>
@@ -1534,16 +1534,16 @@ static Symbol *addUndefined(StringRef Na<br>
// the compiler at once, it can do a whole-program optimization.<br>
template <class ELFT> void LinkerDriver::compileBitcodeFiles() {<br>
// Compile bitcode files and replace bitcode symbols.<br>
- LTO.reset(new BitcodeCompiler);<br>
- for (BitcodeFile *File : BitcodeFiles)<br>
- LTO->add(*File);<br>
-<br>
- for (InputFile *File : LTO->compile()) {<br>
- auto *Obj = cast<ObjFile<ELFT>>(File);<br>
- Obj->parse(/*IgnoreComdats=*/true);<br>
- for (Symbol *Sym : Obj->getGlobalSymbols())<br>
- Sym->parseSymbolVersion();<br>
- ObjectFiles.push_back(File);<br>
+ lto.reset(new BitcodeCompiler);<br>
+ for (BitcodeFile *file : bitcodeFiles)<br>
+ lto->add(*file);<br>
+<br>
+ for (InputFile *file : lto->compile()) {<br>
+ auto *obj = cast<ObjFile<ELFT>>(file);<br>
+ obj->parse(/*IgnoreComdats=*/true);<br>
+ for (Symbol *sym : obj->getGlobalSymbols())<br>
+ sym->parseSymbolVersion();<br>
+ objectFiles.push_back(file);<br>
}<br>
}<br>
<br>
@@ -1556,9 +1556,9 @@ template <class ELFT> void LinkerDriver:<br>
//<br>
// This data structure is instantiated for each -wrap option.<br>
struct WrappedSymbol {<br>
- Symbol *Sym;<br>
- Symbol *Real;<br>
- Symbol *Wrap;<br>
+ Symbol *sym;<br>
+ Symbol *real;<br>
+ Symbol *wrap;<br>
};<br>
<br>
// Handles -wrap option.<br>
@@ -1566,33 +1566,33 @@ struct WrappedSymbol {<br>
// This function instantiates wrapper symbols. At this point, they seem<br>
// like they are not being used at all, so we explicitly set some flags so<br>
// that LTO won't eliminate them.<br>
-static std::vector<WrappedSymbol> addWrappedSymbols(opt::InputArgList &Args) {<br>
- std::vector<WrappedSymbol> V;<br>
- DenseSet<StringRef> Seen;<br>
-<br>
- for (auto *Arg : Args.filtered(OPT_wrap)) {<br>
- StringRef Name = Arg->getValue();<br>
- if (!Seen.insert(Name).second)<br>
+static std::vector<WrappedSymbol> addWrappedSymbols(opt::InputArgList &args) {<br>
+ std::vector<WrappedSymbol> v;<br>
+ DenseSet<StringRef> seen;<br>
+<br>
+ for (auto *arg : args.filtered(OPT_wrap)) {<br>
+ StringRef name = arg->getValue();<br>
+ if (!seen.insert(name).second)<br>
continue;<br>
<br>
- Symbol *Sym = Symtab->find(Name);<br>
- if (!Sym)<br>
+ Symbol *sym = symtab->find(name);<br>
+ if (!sym)<br>
continue;<br>
<br>
- Symbol *Real = addUndefined(Saver.save("__real_" + Name));<br>
- Symbol *Wrap = addUndefined(Saver.save("__wrap_" + Name));<br>
- V.push_back({Sym, Real, Wrap});<br>
+ Symbol *real = addUndefined(Saver.save("__real_" + name));<br>
+ Symbol *wrap = addUndefined(Saver.save("__wrap_" + name));<br>
+ v.push_back({sym, real, wrap});<br>
<br>
// We want to tell LTO not to inline symbols to be overwritten<br>
// because LTO doesn't know the final symbol contents after renaming.<br>
- Real->CanInline = false;<br>
- Sym->CanInline = false;<br>
+ real->canInline = false;<br>
+ sym->canInline = false;<br>
<br>
// Tell LTO not to eliminate these symbols.<br>
- Sym->IsUsedInRegularObj = true;<br>
- Wrap->IsUsedInRegularObj = true;<br>
+ sym->isUsedInRegularObj = true;<br>
+ wrap->isUsedInRegularObj = true;<br>
}<br>
- return V;<br>
+ return v;<br>
}<br>
<br>
// Do renaming for -wrap by updating pointers to symbols.<br>
@@ -1600,24 +1600,24 @@ static std::vector<WrappedSymbol> addWra<br>
// When this function is executed, only InputFiles and symbol table<br>
// contain pointers to symbol objects. We visit them to replace pointers,<br>
// so that wrapped symbols are swapped as instructed by the command line.<br>
-static void wrapSymbols(ArrayRef<WrappedSymbol> Wrapped) {<br>
- DenseMap<Symbol *, Symbol *> Map;<br>
- for (const WrappedSymbol &W : Wrapped) {<br>
- Map[W.Sym] = W.Wrap;<br>
- Map[W.Real] = W.Sym;<br>
+static void wrapSymbols(ArrayRef<WrappedSymbol> wrapped) {<br>
+ DenseMap<Symbol *, Symbol *> map;<br>
+ for (const WrappedSymbol &w : wrapped) {<br>
+ map[w.sym] = w.wrap;<br>
+ map[w.real] = w.sym;<br>
}<br>
<br>
// Update pointers in input files.<br>
- parallelForEach(ObjectFiles, [&](InputFile *File) {<br>
- MutableArrayRef<Symbol *> Syms = File->getMutableSymbols();<br>
- for (size_t I = 0, E = Syms.size(); I != E; ++I)<br>
- if (Symbol *S = Map.lookup(Syms[I]))<br>
- Syms[I] = S;<br>
+ parallelForEach(objectFiles, [&](InputFile *file) {<br>
+ MutableArrayRef<Symbol *> syms = file->getMutableSymbols();<br>
+ for (size_t i = 0, e = syms.size(); i != e; ++i)<br>
+ if (Symbol *s = map.lookup(syms[i]))<br>
+ syms[i] = s;<br>
});<br>
<br>
// Update pointers in the symbol table.<br>
- for (const WrappedSymbol &W : Wrapped)<br>
- Symtab->wrap(W.Sym, W.Real, W.Wrap);<br>
+ for (const WrappedSymbol &w : wrapped)<br>
+ symtab->wrap(w.sym, w.real, w.wrap);<br>
}<br>
<br>
// To enable CET (x86's hardware-assited control flow enforcement), each<br>
@@ -1633,30 +1633,30 @@ static void wrapSymbols(ArrayRef<Wrapped<br>
// Note that the CET-aware PLT is not implemented yet. We do error<br>
// check only.<br>
template <class ELFT> static uint32_t getAndFeatures() {<br>
- if (Config->EMachine != EM_386 && Config->EMachine != EM_X86_64 &&<br>
- Config->EMachine != EM_AARCH64)<br>
+ if (config->emachine != EM_386 && config->emachine != EM_X86_64 &&<br>
+ config->emachine != EM_AARCH64)<br>
return 0;<br>
<br>
- uint32_t Ret = -1;<br>
- for (InputFile *F : ObjectFiles) {<br>
- uint32_t Features = cast<ObjFile<ELFT>>(F)->AndFeatures;<br>
- if (Config->ForceBTI && !(Features & GNU_PROPERTY_AARCH64_FEATURE_1_BTI)) {<br>
- warn(toString(F) + ": --force-bti: file does not have BTI property");<br>
- Features |= GNU_PROPERTY_AARCH64_FEATURE_1_BTI;<br>
- } else if (!Features && Config->RequireCET)<br>
- error(toString(F) + ": --require-cet: file is not compatible with CET");<br>
- Ret &= Features;<br>
+ uint32_t ret = -1;<br>
+ for (InputFile *f : objectFiles) {<br>
+ uint32_t features = cast<ObjFile<ELFT>>(f)->andFeatures;<br>
+ if (config->forceBTI && !(features & GNU_PROPERTY_AARCH64_FEATURE_1_BTI)) {<br>
+ warn(toString(f) + ": --force-bti: file does not have BTI property");<br>
+ features |= GNU_PROPERTY_AARCH64_FEATURE_1_BTI;<br>
+ } else if (!features && config->requireCET)<br>
+ error(toString(f) + ": --require-cet: file is not compatible with CET");<br>
+ ret &= features;<br>
}<br>
<br>
// Force enable pointer authentication Plt, we don't warn in this case as<br>
// this does not require support in the object for correctness.<br>
- if (Config->PacPlt)<br>
- Ret |= GNU_PROPERTY_AARCH64_FEATURE_1_PAC;<br>
+ if (config->pacPlt)<br>
+ ret |= GNU_PROPERTY_AARCH64_FEATURE_1_PAC;<br>
<br>
- return Ret;<br>
+ return ret;<br>
}<br>
<br>
-static const char *LibcallRoutineNames[] = {<br>
+static const char *libcallRoutineNames[] = {<br>
#define HANDLE_LIBCALL(code, name) name,<br>
#include "llvm/IR/RuntimeLibcalls.def"<br>
#undef HANDLE_LIBCALL<br>
@@ -1664,48 +1664,48 @@ static const char *LibcallRoutineNames[]<br>
<br>
// Do actual linking. Note that when this function is called,<br>
// all linker scripts have already been parsed.<br>
-template <class ELFT> void LinkerDriver::link(opt::InputArgList &Args) {<br>
+template <class ELFT> void LinkerDriver::link(opt::InputArgList &args) {<br>
// If a -hash-style option was not given, set to a default value,<br>
// which varies depending on the target.<br>
- if (!Args.hasArg(OPT_hash_style)) {<br>
- if (Config->EMachine == EM_MIPS)<br>
- Config->SysvHash = true;<br>
+ if (!args.hasArg(OPT_hash_style)) {<br>
+ if (config->emachine == EM_MIPS)<br>
+ config->sysvHash = true;<br>
else<br>
- Config->SysvHash = Config->GnuHash = true;<br>
+ config->sysvHash = config->gnuHash = true;<br>
}<br>
<br>
// Default output filename is "a.out" by the Unix tradition.<br>
- if (Config->OutputFile.empty())<br>
- Config->OutputFile = "a.out";<br>
+ if (config->outputFile.empty())<br>
+ config->outputFile = "a.out";<br>
<br>
// Fail early if the output file or map file is not writable. If a user has a<br>
// long link, e.g. due to a large LTO link, they do not wish to run it and<br>
// find that it failed because there was a mistake in their command-line.<br>
- if (auto E = tryCreateFile(Config->OutputFile))<br>
- error("cannot open output file " + Config->OutputFile + ": " + E.message());<br>
- if (auto E = tryCreateFile(Config->MapFile))<br>
- error("cannot open map file " + Config->MapFile + ": " + E.message());<br>
+ if (auto e = tryCreateFile(config->outputFile))<br>
+ error("cannot open output file " + config->outputFile + ": " + e.message());<br>
+ if (auto e = tryCreateFile(config->mapFile))<br>
+ error("cannot open map file " + config->mapFile + ": " + e.message());<br>
if (errorCount())<br>
return;<br>
<br>
// Use default entry point name if no name was given via the command<br>
// line nor linker scripts. For some reason, MIPS entry point name is<br>
// different from others.<br>
- Config->WarnMissingEntry =<br>
- (!Config->Entry.empty() || (!Config->Shared && !Config->Relocatable));<br>
- if (Config->Entry.empty() && !Config->Relocatable)<br>
- Config->Entry = (Config->EMachine == EM_MIPS) ? "__start" : "_start";<br>
+ config->warnMissingEntry =<br>
+ (!config->entry.empty() || (!config->shared && !config->relocatable));<br>
+ if (config->entry.empty() && !config->relocatable)<br>
+ config->entry = (config->emachine == EM_MIPS) ? "__start" : "_start";<br>
<br>
// Handle --trace-symbol.<br>
- for (auto *Arg : Args.filtered(OPT_trace_symbol))<br>
- Symtab->insert(Arg->getValue())->Traced = true;<br>
+ for (auto *arg : args.filtered(OPT_trace_symbol))<br>
+ symtab->insert(arg->getValue())->traced = true;<br>
<br>
// Add all files to the symbol table. This will add almost all<br>
// symbols that we need to the symbol table. This process might<br>
// add files to the link, via autolinking, these files are always<br>
// appended to the Files vector.<br>
- for (size_t I = 0; I < Files.size(); ++I)<br>
- parseFile(Files[I]);<br>
+ for (size_t i = 0; i < files.size(); ++i)<br>
+ parseFile(files[i]);<br>
<br>
// Now that we have every file, we can decide if we will need a<br>
// dynamic symbol table.<br>
@@ -1713,26 +1713,26 @@ template <class ELFT> void LinkerDriver:<br>
// producing a shared library.<br>
// We also need one if any shared libraries are used and for pie executables<br>
// (probably because the dynamic linker needs it).<br>
- Config->HasDynSymTab =<br>
- !SharedFiles.empty() || Config->Pic || Config->ExportDynamic;<br>
+ config->hasDynSymTab =<br>
+ !sharedFiles.empty() || config->isPic || config->exportDynamic;<br>
<br>
// Some symbols (such as __ehdr_start) are defined lazily only when there<br>
// are undefined symbols for them, so we add these to trigger that logic.<br>
- for (StringRef Name : Script->ReferencedSymbols)<br>
- addUndefined(Name);<br>
+ for (StringRef name : script->referencedSymbols)<br>
+ addUndefined(name);<br>
<br>
// Handle the `--undefined <sym>` options.<br>
- for (StringRef Arg : Config->Undefined)<br>
- if (Symbol *Sym = Symtab->find(Arg))<br>
- handleUndefined(Sym);<br>
+ for (StringRef arg : config->undefined)<br>
+ if (Symbol *sym = symtab->find(arg))<br>
+ handleUndefined(sym);<br>
<br>
// If an entry symbol is in a static archive, pull out that file now.<br>
- if (Symbol *Sym = Symtab->find(Config->Entry))<br>
- handleUndefined(Sym);<br>
+ if (Symbol *sym = symtab->find(config->entry))<br>
+ handleUndefined(sym);<br>
<br>
// Handle the `--undefined-glob <pattern>` options.<br>
- for (StringRef Pat : args::getStrings(Args, OPT_undefined_glob))<br>
- handleUndefinedGlob(Pat);<br>
+ for (StringRef pat : args::getStrings(args, OPT_undefined_glob))<br>
+ handleUndefinedGlob(pat);<br>
<br>
// If any of our inputs are bitcode files, the LTO code generator may create<br>
// references to certain library functions that might not be explicit in the<br>
@@ -1751,9 +1751,9 @@ template <class ELFT> void LinkerDriver:<br>
// to, i.e. if the symbol's definition is in bitcode. Any other required<br>
// libcall symbols will be added to the link after LTO when we add the LTO<br>
// object file to the link.<br>
- if (!BitcodeFiles.empty())<br>
- for (const char *S : LibcallRoutineNames)<br>
- handleLibcall(S);<br>
+ if (!bitcodeFiles.empty())<br>
+ for (const char *s : libcallRoutineNames)<br>
+ handleLibcall(s);<br>
<br>
// Return if there were name resolution errors.<br>
if (errorCount())<br>
@@ -1761,27 +1761,27 @@ template <class ELFT> void LinkerDriver:<br>
<br>
// Now when we read all script files, we want to finalize order of linker<br>
// script commands, which can be not yet final because of INSERT commands.<br>
- Script->processInsertCommands();<br>
+ script->processInsertCommands();<br>
<br>
// We want to declare linker script's symbols early,<br>
// so that we can version them.<br>
// They also might be exported if referenced by DSOs.<br>
- Script->declareSymbols();<br>
+ script->declareSymbols();<br>
<br>
// Handle the -exclude-libs option.<br>
- if (Args.hasArg(OPT_exclude_libs))<br>
- excludeLibs(Args);<br>
+ if (args.hasArg(OPT_exclude_libs))<br>
+ excludeLibs(args);<br>
<br>
// Create ElfHeader early. We need a dummy section in<br>
// addReservedSymbols to mark the created symbols as not absolute.<br>
- Out::ElfHeader = make<OutputSection>("", 0, SHF_ALLOC);<br>
- Out::ElfHeader->Size = sizeof(typename ELFT::Ehdr);<br>
+ Out::elfHeader = make<OutputSection>("", 0, SHF_ALLOC);<br>
+ Out::elfHeader->size = sizeof(typename ELFT::Ehdr);<br>
<br>
// Create wrapped symbols for -wrap option.<br>
- std::vector<WrappedSymbol> Wrapped = addWrappedSymbols(Args);<br>
+ std::vector<WrappedSymbol> wrapped = addWrappedSymbols(args);<br>
<br>
// We need to create some reserved symbols such as _end. Create them.<br>
- if (!Config->Relocatable)<br>
+ if (!config->relocatable)<br>
addReservedSymbols();<br>
<br>
// Apply version scripts.<br>
@@ -1789,8 +1789,8 @@ template <class ELFT> void LinkerDriver:<br>
// For a relocatable output, version scripts don't make sense, and<br>
// parsing a symbol version string (e.g. dropping "@ver1" from a symbol<br>
// name "foo@ver1") rather do harm, so we don't call this if -r is given.<br>
- if (!Config->Relocatable)<br>
- Symtab->scanVersionScript();<br>
+ if (!config->relocatable)<br>
+ symtab->scanVersionScript();<br>
<br>
// Do link-time optimization if given files are LLVM bitcode files.<br>
// This compiles bitcode files into real object files.<br>
@@ -1804,83 +1804,83 @@ template <class ELFT> void LinkerDriver:<br>
// If -thinlto-index-only is given, we should create only "index<br>
// files" and not object files. Index file creation is already done<br>
// in addCombinedLTOObject, so we are done if that's the case.<br>
- if (Config->ThinLTOIndexOnly)<br>
+ if (config->thinLTOIndexOnly)<br>
return;<br>
<br>
// Likewise, --plugin-opt=emit-llvm is an option to make LTO create<br>
// an output file in bitcode and exit, so that you can just get a<br>
// combined bitcode file.<br>
- if (Config->EmitLLVM)<br>
+ if (config->emitLLVM)<br>
return;<br>
<br>
// Apply symbol renames for -wrap.<br>
- if (!Wrapped.empty())<br>
- wrapSymbols(Wrapped);<br>
+ if (!wrapped.empty())<br>
+ wrapSymbols(wrapped);<br>
<br>
// Now that we have a complete list of input files.<br>
// Beyond this point, no new files are added.<br>
// Aggregate all input sections into one place.<br>
- for (InputFile *F : ObjectFiles)<br>
- for (InputSectionBase *S : F->getSections())<br>
- if (S && S != &InputSection::Discarded)<br>
- InputSections.push_back(S);<br>
- for (BinaryFile *F : BinaryFiles)<br>
- for (InputSectionBase *S : F->getSections())<br>
- InputSections.push_back(cast<InputSection>(S));<br>
-<br>
- llvm::erase_if(InputSections, [](InputSectionBase *S) {<br>
- if (S->Type == SHT_LLVM_SYMPART) {<br>
- readSymbolPartitionSection<ELFT>(S);<br>
+ for (InputFile *f : objectFiles)<br>
+ for (InputSectionBase *s : f->getSections())<br>
+ if (s && s != &InputSection::discarded)<br>
+ inputSections.push_back(s);<br>
+ for (BinaryFile *f : binaryFiles)<br>
+ for (InputSectionBase *s : f->getSections())<br>
+ inputSections.push_back(cast<InputSection>(s));<br>
+<br>
+ llvm::erase_if(inputSections, [](InputSectionBase *s) {<br>
+ if (s->type == SHT_LLVM_SYMPART) {<br>
+ readSymbolPartitionSection<ELFT>(s);<br>
return true;<br>
}<br>
<br>
// We do not want to emit debug sections if --strip-all<br>
// or -strip-debug are given.<br>
- return Config->Strip != StripPolicy::None &&<br>
- (S->Name.startswith(".debug") || S->Name.startswith(".zdebug"));<br>
+ return config->strip != StripPolicy::None &&<br>
+ (s->name.startswith(".debug") || s->name.startswith(".zdebug"));<br>
});<br>
<br>
// Now that the number of partitions is fixed, save a pointer to the main<br>
// partition.<br>
- Main = &Partitions[0];<br>
+ mainPart = &partitions[0];<br>
<br>
// Read .note.gnu.property sections from input object files which<br>
// contain a hint to tweak linker's and loader's behaviors.<br>
- Config->AndFeatures = getAndFeatures<ELFT>();<br>
+ config->andFeatures = getAndFeatures<ELFT>();<br>
<br>
// The Target instance handles target-specific stuff, such as applying<br>
// relocations or writing a PLT section. It also contains target-dependent<br>
// values such as a default image base address.<br>
- Target = getTarget();<br>
+ target = getTarget();<br>
<br>
- Config->EFlags = Target->calcEFlags();<br>
+ config->eflags = target->calcEFlags();<br>
// MaxPageSize (sometimes called abi page size) is the maximum page size that<br>
// the output can be run on. For example if the OS can use 4k or 64k page<br>
// sizes then MaxPageSize must be 64 for the output to be useable on both.<br>
// All important alignment decisions must use this value.<br>
- Config->MaxPageSize = getMaxPageSize(Args);<br>
+ config->maxPageSize = getMaxPageSize(args);<br>
// CommonPageSize is the most common page size that the output will be run on.<br>
// For example if an OS can use 4k or 64k page sizes and 4k is more common<br>
// than 64k then CommonPageSize is set to 4k. CommonPageSize can be used for<br>
// optimizations such as DATA_SEGMENT_ALIGN in linker scripts. LLD's use of it<br>
// is limited to writing trap instructions on the last executable segment.<br>
- Config->CommonPageSize = getCommonPageSize(Args);<br>
+ config->commonPageSize = getCommonPageSize(args);<br>
<br>
- Config->ImageBase = getImageBase(Args);<br>
+ config->imageBase = getImageBase(args);<br>
<br>
- if (Config->EMachine == EM_ARM) {<br>
+ if (config->emachine == EM_ARM) {<br>
// FIXME: These warnings can be removed when lld only uses these features<br>
// when the input objects have been compiled with an architecture that<br>
// supports them.<br>
- if (Config->ARMHasBlx == false)<br>
+ if (config->armHasBlx == false)<br>
warn("lld uses blx instruction, no object with architecture supporting "<br>
"feature detected");<br>
}<br>
<br>
// This adds a .comment section containing a version string. We have to add it<br>
// before mergeSections because the .comment section is a mergeable section.<br>
- if (!Config->Relocatable)<br>
- InputSections.push_back(createCommentSection());<br>
+ if (!config->relocatable)<br>
+ inputSections.push_back(createCommentSection());<br>
<br>
// Replace common symbols with regular symbols.<br>
replaceCommonSymbols();<br>
@@ -1891,16 +1891,16 @@ template <class ELFT> void LinkerDriver:<br>
markLive<ELFT>();<br>
demoteSharedSymbols();<br>
mergeSections();<br>
- if (Config->ICF != ICFLevel::None) {<br>
- findKeepUniqueSections<ELFT>(Args);<br>
+ if (config->icf != ICFLevel::None) {<br>
+ findKeepUniqueSections<ELFT>(args);<br>
doIcf<ELFT>();<br>
}<br>
<br>
// Read the callgraph now that we know what was gced or icfed<br>
- if (Config->CallGraphProfileSort) {<br>
- if (auto *Arg = Args.getLastArg(OPT_call_graph_ordering_file))<br>
- if (Optional<MemoryBufferRef> Buffer = readFile(Arg->getValue()))<br>
- readCallGraph(*Buffer);<br>
+ if (config->callGraphProfileSort) {<br>
+ if (auto *arg = args.getLastArg(OPT_call_graph_ordering_file))<br>
+ if (Optional<MemoryBufferRef> buffer = readFile(arg->getValue()))<br>
+ readCallGraph(*buffer);<br>
readCallGraphsFromObjectFiles<ELFT>();<br>
}<br>
<br>
<br>
Modified: lld/trunk/ELF/Driver.h<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_ELF_Driver.h-3Frev-3D365595-26r1-3D365594-26r2-3D365595-26view-3Ddiff&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=RXrjISEjbookXEDBy-41jCLzxsvs6zHub7bqtTnT4T4&e=" rel="noreferrer" target="_blank">https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_ELF_Driver.h-3Frev-3D365595-26r1-3D365594-26r2-3D365595-26view-3Ddiff&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=RXrjISEjbookXEDBy-41jCLzxsvs6zHub7bqtTnT4T4&e=</a> <br>
==============================================================================<br>
--- lld/trunk/ELF/Driver.h (original)<br>
+++ lld/trunk/ELF/Driver.h Tue Jul 9 22:00:37 2019<br>
@@ -22,37 +22,37 @@<br>
namespace lld {<br>
namespace elf {<br>
<br>
-extern class LinkerDriver *Driver;<br>
+extern class LinkerDriver *driver;<br>
<br>
class LinkerDriver {<br>
public:<br>
- void main(ArrayRef<const char *> Args);<br>
- void addFile(StringRef Path, bool WithLOption);<br>
- void addLibrary(StringRef Name);<br>
+ void main(ArrayRef<const char *> args);<br>
+ void addFile(StringRef path, bool withLOption);<br>
+ void addLibrary(StringRef name);<br>
<br>
private:<br>
- void createFiles(llvm::opt::InputArgList &Args);<br>
+ void createFiles(llvm::opt::InputArgList &args);<br>
void inferMachineType();<br>
- template <class ELFT> void link(llvm::opt::InputArgList &Args);<br>
+ template <class ELFT> void link(llvm::opt::InputArgList &args);<br>
template <class ELFT> void compileBitcodeFiles();<br>
<br>
// True if we are in --whole-archive and --no-whole-archive.<br>
- bool InWholeArchive = false;<br>
+ bool inWholeArchive = false;<br>
<br>
// True if we are in --start-lib and --end-lib.<br>
- bool InLib = false;<br>
+ bool inLib = false;<br>
<br>
// For LTO.<br>
- std::unique_ptr<BitcodeCompiler> LTO;<br>
+ std::unique_ptr<BitcodeCompiler> lto;<br>
<br>
- std::vector<InputFile *> Files;<br>
+ std::vector<InputFile *> files;<br>
};<br>
<br>
// Parses command line options.<br>
class ELFOptTable : public llvm::opt::OptTable {<br>
public:<br>
ELFOptTable();<br>
- llvm::opt::InputArgList parse(ArrayRef<const char *> Argv);<br>
+ llvm::opt::InputArgList parse(ArrayRef<const char *> argv);<br>
};<br>
<br>
// Create enum with OPT_xxx values for each option in Options.td<br>
@@ -64,12 +64,12 @@ enum {<br>
};<br>
<br>
void printHelp();<br>
-std::string createResponseFile(const llvm::opt::InputArgList &Args);<br>
+std::string createResponseFile(const llvm::opt::InputArgList &args);<br>
<br>
-llvm::Optional<std::string> findFromSearchPaths(StringRef Path);<br>
-llvm::Optional<std::string> searchScript(StringRef Path);<br>
-llvm::Optional<std::string> searchLibraryBaseName(StringRef Path);<br>
-llvm::Optional<std::string> searchLibrary(StringRef Path);<br>
+llvm::Optional<std::string> findFromSearchPaths(StringRef path);<br>
+llvm::Optional<std::string> searchScript(StringRef path);<br>
+llvm::Optional<std::string> searchLibraryBaseName(StringRef path);<br>
+llvm::Optional<std::string> searchLibrary(StringRef path);<br>
<br>
} // namespace elf<br>
} // namespace lld<br>
<br>
Modified: lld/trunk/ELF/DriverUtils.cpp<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_ELF_DriverUtils.cpp-3Frev-3D365595-26r1-3D365594-26r2-3D365595-26view-3Ddiff&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=K6kanVOY89mNNSdtO10a0wHsh5m5K33hBtDNKIYMC-M&e=" rel="noreferrer" target="_blank">https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_ELF_DriverUtils.cpp-3Frev-3D365595-26r1-3D365594-26r2-3D365595-26view-3Ddiff&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=K6kanVOY89mNNSdtO10a0wHsh5m5K33hBtDNKIYMC-M&e=</a> <br>
==============================================================================<br>
--- lld/trunk/ELF/DriverUtils.cpp (original)<br>
+++ lld/trunk/ELF/DriverUtils.cpp Tue Jul 9 22:00:37 2019<br>
@@ -41,7 +41,7 @@ using namespace lld::elf;<br>
#undef PREFIX<br>
<br>
// Create table mapping all options defined in Options.td<br>
-static const opt::OptTable::Info OptInfo[] = {<br>
+static const opt::OptTable::Info optInfo[] = {<br>
#define OPTION(X1, X2, ID, KIND, GROUP, ALIAS, X7, X8, X9, X10, X11, X12) \<br>
{X1, X2, X10, X11, OPT_##ID, opt::Option::KIND##Class, \<br>
X9, X8, OPT_##GROUP, OPT_##ALIAS, X7, X12},<br>
@@ -49,36 +49,36 @@ static const opt::OptTable::Info OptInfo<br>
#undef OPTION<br>
};<br>
<br>
-ELFOptTable::ELFOptTable() : OptTable(OptInfo) {}<br>
+ELFOptTable::ELFOptTable() : OptTable(optInfo) {}<br>
<br>
// Set color diagnostics according to -color-diagnostics={auto,always,never}<br>
// or -no-color-diagnostics flags.<br>
-static void handleColorDiagnostics(opt::InputArgList &Args) {<br>
- auto *Arg = Args.getLastArg(OPT_color_diagnostics, OPT_color_diagnostics_eq,<br>
+static void handleColorDiagnostics(opt::InputArgList &args) {<br>
+ auto *arg = args.getLastArg(OPT_color_diagnostics, OPT_color_diagnostics_eq,<br>
OPT_no_color_diagnostics);<br>
- if (!Arg)<br>
+ if (!arg)<br>
return;<br>
- if (Arg->getOption().getID() == OPT_color_diagnostics) {<br>
+ if (arg->getOption().getID() == OPT_color_diagnostics) {<br>
errorHandler().ColorDiagnostics = true;<br>
- } else if (Arg->getOption().getID() == OPT_no_color_diagnostics) {<br>
+ } else if (arg->getOption().getID() == OPT_no_color_diagnostics) {<br>
errorHandler().ColorDiagnostics = false;<br>
} else {<br>
- StringRef S = Arg->getValue();<br>
- if (S == "always")<br>
+ StringRef s = arg->getValue();<br>
+ if (s == "always")<br>
errorHandler().ColorDiagnostics = true;<br>
- else if (S == "never")<br>
+ else if (s == "never")<br>
errorHandler().ColorDiagnostics = false;<br>
- else if (S != "auto")<br>
- error("unknown option: --color-diagnostics=" + S);<br>
+ else if (s != "auto")<br>
+ error("unknown option: --color-diagnostics=" + s);<br>
}<br>
}<br>
<br>
-static cl::TokenizerCallback getQuotingStyle(opt::InputArgList &Args) {<br>
- if (auto *Arg = Args.getLastArg(OPT_rsp_quoting)) {<br>
- StringRef S = Arg->getValue();<br>
- if (S != "windows" && S != "posix")<br>
- error("invalid response file quoting: " + S);<br>
- if (S == "windows")<br>
+static cl::TokenizerCallback getQuotingStyle(opt::InputArgList &args) {<br>
+ if (auto *arg = args.getLastArg(OPT_rsp_quoting)) {<br>
+ StringRef s = arg->getValue();<br>
+ if (s != "windows" && s != "posix")<br>
+ error("invalid response file quoting: " + s);<br>
+ if (s == "windows")<br>
return cl::TokenizeWindowsCommandLine;<br>
return cl::TokenizeGNUCommandLine;<br>
}<br>
@@ -96,56 +96,56 @@ static cl::TokenizerCallback getQuotingS<br>
// `--plugin-opt <foo>` is converted to `--plugin-opt=<foo>`. This is a<br>
// bit hacky, but looks like it is still better than handling --plugin-opt<br>
// options by hand.<br>
-static void concatLTOPluginOptions(SmallVectorImpl<const char *> &Args) {<br>
- SmallVector<const char *, 256> V;<br>
- for (size_t I = 0, E = Args.size(); I != E; ++I) {<br>
- StringRef S = Args[I];<br>
- if ((S == "-plugin-opt" || S == "--plugin-opt") && I + 1 != E) {<br>
- V.push_back(Saver.save(S + "=" + Args[I + 1]).data());<br>
- ++I;<br>
+static void concatLTOPluginOptions(SmallVectorImpl<const char *> &args) {<br>
+ SmallVector<const char *, 256> v;<br>
+ for (size_t i = 0, e = args.size(); i != e; ++i) {<br>
+ StringRef s = args[i];<br>
+ if ((s == "-plugin-opt" || s == "--plugin-opt") && i + 1 != e) {<br>
+ v.push_back(Saver.save(s + "=" + args[i + 1]).data());<br>
+ ++i;<br>
} else {<br>
- V.push_back(Args[I]);<br>
+ v.push_back(args[i]);<br>
}<br>
}<br>
- Args = std::move(V);<br>
+ args = std::move(v);<br>
}<br>
<br>
// Parses a given list of options.<br>
-opt::InputArgList ELFOptTable::parse(ArrayRef<const char *> Argv) {<br>
+opt::InputArgList ELFOptTable::parse(ArrayRef<const char *> argv) {<br>
// Make InputArgList from string vectors.<br>
- unsigned MissingIndex;<br>
- unsigned MissingCount;<br>
- SmallVector<const char *, 256> Vec(Argv.data(), Argv.data() + Argv.size());<br>
+ unsigned missingIndex;<br>
+ unsigned missingCount;<br>
+ SmallVector<const char *, 256> vec(argv.data(), argv.data() + argv.size());<br>
<br>
// We need to get the quoting style for response files before parsing all<br>
// options so we parse here before and ignore all the options but<br>
// --rsp-quoting.<br>
- opt::InputArgList Args = this->ParseArgs(Vec, MissingIndex, MissingCount);<br>
+ opt::InputArgList args = this->ParseArgs(vec, missingIndex, missingCount);<br>
<br>
// Expand response files (arguments in the form of @<filename>)<br>
// and then parse the argument again.<br>
- cl::ExpandResponseFiles(Saver, getQuotingStyle(Args), Vec);<br>
- concatLTOPluginOptions(Vec);<br>
- Args = this->ParseArgs(Vec, MissingIndex, MissingCount);<br>
-<br>
- handleColorDiagnostics(Args);<br>
- if (MissingCount)<br>
- error(Twine(Args.getArgString(MissingIndex)) + ": missing argument");<br>
-<br>
- for (auto *Arg : Args.filtered(OPT_UNKNOWN)) {<br>
- std::string Nearest;<br>
- if (findNearest(Arg->getAsString(Args), Nearest) > 1)<br>
- error("unknown argument '" + Arg->getAsString(Args) + "'");<br>
+ cl::ExpandResponseFiles(Saver, getQuotingStyle(args), vec);<br>
+ concatLTOPluginOptions(vec);<br>
+ args = this->ParseArgs(vec, missingIndex, missingCount);<br>
+<br>
+ handleColorDiagnostics(args);<br>
+ if (missingCount)<br>
+ error(Twine(args.getArgString(missingIndex)) + ": missing argument");<br>
+<br>
+ for (auto *arg : args.filtered(OPT_UNKNOWN)) {<br>
+ std::string nearest;<br>
+ if (findNearest(arg->getAsString(args), nearest) > 1)<br>
+ error("unknown argument '" + arg->getAsString(args) + "'");<br>
else<br>
- error("unknown argument '" + Arg->getAsString(Args) +<br>
- "', did you mean '" + Nearest + "'");<br>
+ error("unknown argument '" + arg->getAsString(args) +<br>
+ "', did you mean '" + nearest + "'");<br>
}<br>
- return Args;<br>
+ return args;<br>
}<br>
<br>
void elf::printHelp() {<br>
ELFOptTable().PrintHelp(<br>
- outs(), (Config->ProgName + " [options] file...").str().c_str(), "lld",<br>
+ outs(), (config->progName + " [options] file...").str().c_str(), "lld",<br>
false /*ShowHidden*/, true /*ShowAllAliases*/);<br>
outs() << "\n";<br>
<br>
@@ -154,36 +154,36 @@ void elf::printHelp() {<br>
// in a message for the -help option. If it doesn't match, the scripts<br>
// assume that the linker doesn't support very basic features such as<br>
// shared libraries. Therefore, we need to print out at least "elf".<br>
- outs() << Config->ProgName << ": supported targets: elf\n";<br>
+ outs() << config->progName << ": supported targets: elf\n";<br>
}<br>
<br>
-static std::string rewritePath(StringRef S) {<br>
- if (fs::exists(S))<br>
- return relativeToRoot(S);<br>
- return S;<br>
+static std::string rewritePath(StringRef s) {<br>
+ if (fs::exists(s))<br>
+ return relativeToRoot(s);<br>
+ return s;<br>
}<br>
<br>
// Reconstructs command line arguments so that so that you can re-run<br>
// the same command with the same inputs. This is for --reproduce.<br>
-std::string elf::createResponseFile(const opt::InputArgList &Args) {<br>
- SmallString<0> Data;<br>
- raw_svector_ostream OS(Data);<br>
- OS << "--chroot .\n";<br>
+std::string elf::createResponseFile(const opt::InputArgList &args) {<br>
+ SmallString<0> data;<br>
+ raw_svector_ostream os(data);<br>
+ os << "--chroot .\n";<br>
<br>
// Copy the command line to the output while rewriting paths.<br>
- for (auto *Arg : Args) {<br>
- switch (Arg->getOption().getID()) {<br>
+ for (auto *arg : args) {<br>
+ switch (arg->getOption().getID()) {<br>
case OPT_reproduce:<br>
break;<br>
case OPT_INPUT:<br>
- OS << quote(rewritePath(Arg->getValue())) << "\n";<br>
+ os << quote(rewritePath(arg->getValue())) << "\n";<br>
break;<br>
case OPT_o:<br>
// If -o path contains directories, "lld @response.txt" will likely<br>
// fail because the archive we are creating doesn't contain empty<br>
// directories for the output path (-o doesn't create directories).<br>
// Strip directories to prevent the issue.<br>
- OS << "-o " << quote(sys::path::filename(Arg->getValue())) << "\n";<br>
+ os << "-o " << quote(sys::path::filename(arg->getValue())) << "\n";<br>
break;<br>
case OPT_dynamic_list:<br>
case OPT_library_path:<br>
@@ -192,62 +192,62 @@ std::string elf::createResponseFile(cons<br>
case OPT_symbol_ordering_file:<br>
case OPT_sysroot:<br>
case OPT_version_script:<br>
- OS << Arg->getSpelling() << " " << quote(rewritePath(Arg->getValue()))<br>
+ os << arg->getSpelling() << " " << quote(rewritePath(arg->getValue()))<br>
<< "\n";<br>
break;<br>
default:<br>
- OS << toString(*Arg) << "\n";<br>
+ os << toString(*arg) << "\n";<br>
}<br>
}<br>
- return Data.str();<br>
+ return data.str();<br>
}<br>
<br>
// Find a file by concatenating given paths. If a resulting path<br>
// starts with "=", the character is replaced with a --sysroot value.<br>
-static Optional<std::string> findFile(StringRef Path1, const Twine &Path2) {<br>
- SmallString<128> S;<br>
- if (Path1.startswith("="))<br>
- path::append(S, Config->Sysroot, Path1.substr(1), Path2);<br>
+static Optional<std::string> findFile(StringRef path1, const Twine &path2) {<br>
+ SmallString<128> s;<br>
+ if (path1.startswith("="))<br>
+ path::append(s, config->sysroot, path1.substr(1), path2);<br>
else<br>
- path::append(S, Path1, Path2);<br>
+ path::append(s, path1, path2);<br>
<br>
- if (fs::exists(S))<br>
- return S.str().str();<br>
+ if (fs::exists(s))<br>
+ return s.str().str();<br>
return None;<br>
}<br>
<br>
-Optional<std::string> elf::findFromSearchPaths(StringRef Path) {<br>
- for (StringRef Dir : Config->SearchPaths)<br>
- if (Optional<std::string> S = findFile(Dir, Path))<br>
- return S;<br>
+Optional<std::string> elf::findFromSearchPaths(StringRef path) {<br>
+ for (StringRef dir : config->searchPaths)<br>
+ if (Optional<std::string> s = findFile(dir, path))<br>
+ return s;<br>
return None;<br>
}<br>
<br>
// This is for -l<basename>. We'll look for lib<basename>.so or lib<basename>.a from<br>
// search paths.<br>
-Optional<std::string> elf::searchLibraryBaseName(StringRef Name) {<br>
- for (StringRef Dir : Config->SearchPaths) {<br>
- if (!Config->Static)<br>
- if (Optional<std::string> S = findFile(Dir, "lib" + Name + ".so"))<br>
- return S;<br>
- if (Optional<std::string> S = findFile(Dir, "lib" + Name + ".a"))<br>
- return S;<br>
+Optional<std::string> elf::searchLibraryBaseName(StringRef name) {<br>
+ for (StringRef dir : config->searchPaths) {<br>
+ if (!config->isStatic)<br>
+ if (Optional<std::string> s = findFile(dir, "lib" + name + ".so"))<br>
+ return s;<br>
+ if (Optional<std::string> s = findFile(dir, "lib" + name + ".a"))<br>
+ return s;<br>
}<br>
return None;<br>
}<br>
<br>
// This is for -l<namespec>.<br>
-Optional<std::string> elf::searchLibrary(StringRef Name) {<br>
- if (Name.startswith(":"))<br>
- return findFromSearchPaths(Name.substr(1));<br>
- return searchLibraryBaseName (Name);<br>
+Optional<std::string> elf::searchLibrary(StringRef name) {<br>
+ if (name.startswith(":"))<br>
+ return findFromSearchPaths(name.substr(1));<br>
+ return searchLibraryBaseName (name);<br>
}<br>
<br>
// If a linker/version script doesn't exist in the current directory, we also<br>
// look for the script in the '-L' search paths. This matches the behaviour of<br>
// '-T', --version-script=, and linker script INPUT() command in ld.bfd.<br>
-Optional<std::string> elf::searchScript(StringRef Name) {<br>
- if (fs::exists(Name))<br>
- return Name.str();<br>
- return findFromSearchPaths(Name);<br>
+Optional<std::string> elf::searchScript(StringRef name) {<br>
+ if (fs::exists(name))<br>
+ return name.str();<br>
+ return findFromSearchPaths(name);<br>
}<br>
<br>
Modified: lld/trunk/ELF/EhFrame.cpp<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_ELF_EhFrame.cpp-3Frev-3D365595-26r1-3D365594-26r2-3D365595-26view-3Ddiff&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=tu1Izf7mytTMTFPsGwmIk_IewcMS9WESLFOMMDaYtmM&e=" rel="noreferrer" target="_blank">https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_ELF_EhFrame.cpp-3Frev-3D365595-26r1-3D365594-26r2-3D365595-26view-3Ddiff&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=tu1Izf7mytTMTFPsGwmIk_IewcMS9WESLFOMMDaYtmM&e=</a> <br>
==============================================================================<br>
--- lld/trunk/ELF/EhFrame.cpp (original)<br>
+++ lld/trunk/ELF/EhFrame.cpp Tue Jul 9 22:00:37 2019<br>
@@ -36,72 +36,72 @@ using namespace lld::elf;<br>
namespace {<br>
class EhReader {<br>
public:<br>
- EhReader(InputSectionBase *S, ArrayRef<uint8_t> D) : IS(S), D(D) {}<br>
+ EhReader(InputSectionBase *s, ArrayRef<uint8_t> d) : isec(s), d(d) {}<br>
size_t readEhRecordSize();<br>
uint8_t getFdeEncoding();<br>
<br>
private:<br>
- template <class P> void failOn(const P *Loc, const Twine &Msg) {<br>
- fatal("corrupted .eh_frame: " + Msg + "\n>>> defined in " +<br>
- IS->getObjMsg((const uint8_t *)Loc - IS->data().data()));<br>
+ template <class P> void failOn(const P *loc, const Twine &msg) {<br>
+ fatal("corrupted .eh_frame: " + msg + "\n>>> defined in " +<br>
+ isec->getObjMsg((const uint8_t *)loc - isec->data().data()));<br>
}<br>
<br>
uint8_t readByte();<br>
- void skipBytes(size_t Count);<br>
+ void skipBytes(size_t count);<br>
StringRef readString();<br>
void skipLeb128();<br>
void skipAugP();<br>
<br>
- InputSectionBase *IS;<br>
- ArrayRef<uint8_t> D;<br>
+ InputSectionBase *isec;<br>
+ ArrayRef<uint8_t> d;<br>
};<br>
}<br>
<br>
-size_t elf::readEhRecordSize(InputSectionBase *S, size_t Off) {<br>
- return EhReader(S, S->data().slice(Off)).readEhRecordSize();<br>
+size_t elf::readEhRecordSize(InputSectionBase *s, size_t off) {<br>
+ return EhReader(s, s->data().slice(off)).readEhRecordSize();<br>
}<br>
<br>
// .eh_frame section is a sequence of records. Each record starts with<br>
// a 4 byte length field. This function reads the length.<br>
size_t EhReader::readEhRecordSize() {<br>
- if (D.size() < 4)<br>
- failOn(D.data(), "CIE/FDE too small");<br>
+ if (d.size() < 4)<br>
+ failOn(d.data(), "CIE/FDE too small");<br>
<br>
// First 4 bytes of CIE/FDE is the size of the record.<br>
// If it is 0xFFFFFFFF, the next 8 bytes contain the size instead,<br>
// but we do not support that format yet.<br>
- uint64_t V = read32(D.data());<br>
- if (V == UINT32_MAX)<br>
- failOn(D.data(), "CIE/FDE too large");<br>
- uint64_t Size = V + 4;<br>
- if (Size > D.size())<br>
- failOn(D.data(), "CIE/FDE ends past the end of the section");<br>
- return Size;<br>
+ uint64_t v = read32(d.data());<br>
+ if (v == UINT32_MAX)<br>
+ failOn(d.data(), "CIE/FDE too large");<br>
+ uint64_t size = v + 4;<br>
+ if (size > d.size())<br>
+ failOn(d.data(), "CIE/FDE ends past the end of the section");<br>
+ return size;<br>
}<br>
<br>
// Read a byte and advance D by one byte.<br>
uint8_t EhReader::readByte() {<br>
- if (D.empty())<br>
- failOn(D.data(), "unexpected end of CIE");<br>
- uint8_t B = D.front();<br>
- D = D.slice(1);<br>
- return B;<br>
+ if (d.empty())<br>
+ failOn(d.data(), "unexpected end of CIE");<br>
+ uint8_t b = d.front();<br>
+ d = d.slice(1);<br>
+ return b;<br>
}<br>
<br>
-void EhReader::skipBytes(size_t Count) {<br>
- if (D.size() < Count)<br>
- failOn(D.data(), "CIE is too small");<br>
- D = D.slice(Count);<br>
+void EhReader::skipBytes(size_t count) {<br>
+ if (d.size() < count)<br>
+ failOn(d.data(), "CIE is too small");<br>
+ d = d.slice(count);<br>
}<br>
<br>
// Read a null-terminated string.<br>
StringRef EhReader::readString() {<br>
- const uint8_t *End = llvm::find(D, '\0');<br>
- if (End == D.end())<br>
- failOn(D.data(), "corrupted CIE (failed to read string)");<br>
- StringRef S = toStringRef(D.slice(0, End - D.begin()));<br>
- D = D.slice(S.size() + 1);<br>
- return S;<br>
+ const uint8_t *end = llvm::find(d, '\0');<br>
+ if (end == d.end())<br>
+ failOn(d.data(), "corrupted CIE (failed to read string)");<br>
+ StringRef s = toStringRef(d.slice(0, end - d.begin()));<br>
+ d = d.slice(s.size() + 1);<br>
+ return s;<br>
}<br>
<br>
// Skip an integer encoded in the LEB128 format.<br>
@@ -109,21 +109,21 @@ StringRef EhReader::readString() {<br>
// But we need to be at least able to skip it so that we can read<br>
// the field that follows a LEB128 number.<br>
void EhReader::skipLeb128() {<br>
- const uint8_t *ErrPos = D.data();<br>
- while (!D.empty()) {<br>
- uint8_t Val = D.front();<br>
- D = D.slice(1);<br>
- if ((Val & 0x80) == 0)<br>
+ const uint8_t *errPos = d.data();<br>
+ while (!d.empty()) {<br>
+ uint8_t val = d.front();<br>
+ d = d.slice(1);<br>
+ if ((val & 0x80) == 0)<br>
return;<br>
}<br>
- failOn(ErrPos, "corrupted CIE (failed to read LEB128)");<br>
+ failOn(errPos, "corrupted CIE (failed to read LEB128)");<br>
}<br>
<br>
-static size_t getAugPSize(unsigned Enc) {<br>
- switch (Enc & 0x0f) {<br>
+static size_t getAugPSize(unsigned enc) {<br>
+ switch (enc & 0x0f) {<br>
case DW_EH_PE_absptr:<br>
case DW_EH_PE_signed:<br>
- return Config->Wordsize;<br>
+ return config->wordsize;<br>
case DW_EH_PE_udata2:<br>
case DW_EH_PE_sdata2:<br>
return 2;<br>
@@ -138,29 +138,29 @@ static size_t getAugPSize(unsigned Enc)<br>
}<br>
<br>
void EhReader::skipAugP() {<br>
- uint8_t Enc = readByte();<br>
- if ((Enc & 0xf0) == DW_EH_PE_aligned)<br>
- failOn(D.data() - 1, "DW_EH_PE_aligned encoding is not supported");<br>
- size_t Size = getAugPSize(Enc);<br>
- if (Size == 0)<br>
- failOn(D.data() - 1, "unknown FDE encoding");<br>
- if (Size >= D.size())<br>
- failOn(D.data() - 1, "corrupted CIE");<br>
- D = D.slice(Size);<br>
+ uint8_t enc = readByte();<br>
+ if ((enc & 0xf0) == DW_EH_PE_aligned)<br>
+ failOn(d.data() - 1, "DW_EH_PE_aligned encoding is not supported");<br>
+ size_t size = getAugPSize(enc);<br>
+ if (size == 0)<br>
+ failOn(d.data() - 1, "unknown FDE encoding");<br>
+ if (size >= d.size())<br>
+ failOn(d.data() - 1, "corrupted CIE");<br>
+ d = d.slice(size);<br>
}<br>
<br>
-uint8_t elf::getFdeEncoding(EhSectionPiece *P) {<br>
- return EhReader(P->Sec, P->data()).getFdeEncoding();<br>
+uint8_t elf::getFdeEncoding(EhSectionPiece *p) {<br>
+ return EhReader(p->sec, p->data()).getFdeEncoding();<br>
}<br>
<br>
uint8_t EhReader::getFdeEncoding() {<br>
skipBytes(8);<br>
- int Version = readByte();<br>
- if (Version != 1 && Version != 3)<br>
- failOn(D.data() - 1,<br>
- "FDE version 1 or 3 expected, but got " + Twine(Version));<br>
+ int version = readByte();<br>
+ if (version != 1 && version != 3)<br>
+ failOn(d.data() - 1,<br>
+ "FDE version 1 or 3 expected, but got " + Twine(version));<br>
<br>
- StringRef Aug = readString();<br>
+ StringRef aug = readString();<br>
<br>
// Skip code and data alignment factors.<br>
skipLeb128();<br>
@@ -168,7 +168,7 @@ uint8_t EhReader::getFdeEncoding() {<br>
<br>
// Skip the return address register. In CIE version 1 this is a single<br>
// byte. In CIE version 3 this is an unsigned LEB128.<br>
- if (Version == 1)<br>
+ if (version == 1)<br>
readByte();<br>
else<br>
skipLeb128();<br>
@@ -176,22 +176,22 @@ uint8_t EhReader::getFdeEncoding() {<br>
// We only care about an 'R' value, but other records may precede an 'R'<br>
// record. Unfortunately records are not in TLV (type-length-value) format,<br>
// so we need to teach the linker how to skip records for each type.<br>
- for (char C : Aug) {<br>
- if (C == 'R')<br>
+ for (char c : aug) {<br>
+ if (c == 'R')<br>
return readByte();<br>
- if (C == 'z') {<br>
+ if (c == 'z') {<br>
skipLeb128();<br>
continue;<br>
}<br>
- if (C == 'P') {<br>
+ if (c == 'P') {<br>
skipAugP();<br>
continue;<br>
}<br>
- if (C == 'L') {<br>
+ if (c == 'L') {<br>
readByte();<br>
continue;<br>
}<br>
- failOn(Aug.data(), "unknown .eh_frame augmentation string: " + Aug);<br>
+ failOn(aug.data(), "unknown .eh_frame augmentation string: " + aug);<br>
}<br>
return DW_EH_PE_absptr;<br>
}<br>
<br>
Modified: lld/trunk/ELF/EhFrame.h<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_ELF_EhFrame.h-3Frev-3D365595-26r1-3D365594-26r2-3D365595-26view-3Ddiff&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=ikA4Ib5mN9J3VxvOLj2BhBgFcyFS7xJ7vkH6F5UsrNk&e=" rel="noreferrer" target="_blank">https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_ELF_EhFrame.h-3Frev-3D365595-26r1-3D365594-26r2-3D365595-26view-3Ddiff&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=ikA4Ib5mN9J3VxvOLj2BhBgFcyFS7xJ7vkH6F5UsrNk&e=</a> <br>
==============================================================================<br>
--- lld/trunk/ELF/EhFrame.h (original)<br>
+++ lld/trunk/ELF/EhFrame.h Tue Jul 9 22:00:37 2019<br>
@@ -16,8 +16,8 @@ namespace elf {<br>
class InputSectionBase;<br>
struct EhSectionPiece;<br>
<br>
-size_t readEhRecordSize(InputSectionBase *S, size_t Off);<br>
-uint8_t getFdeEncoding(EhSectionPiece *P);<br>
+size_t readEhRecordSize(InputSectionBase *s, size_t off);<br>
+uint8_t getFdeEncoding(EhSectionPiece *p);<br>
} // namespace elf<br>
} // namespace lld<br>
<br>
<br>
Modified: lld/trunk/ELF/ICF.cpp<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_ELF_ICF.cpp-3Frev-3D365595-26r1-3D365594-26r2-3D365595-26view-3Ddiff&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=VdBTn61QFQBmmrVKz1lRruHyOGT-WqnBYOUr6Yr9vMY&e=" rel="noreferrer" target="_blank">https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_ELF_ICF.cpp-3Frev-3D365595-26r1-3D365594-26r2-3D365595-26view-3Ddiff&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=VdBTn61QFQBmmrVKz1lRruHyOGT-WqnBYOUr6Yr9vMY&e=</a> <br>
==============================================================================<br>
--- lld/trunk/ELF/ICF.cpp (original)<br>
+++ lld/trunk/ELF/ICF.cpp Tue Jul 9 22:00:37 2019<br>
@@ -98,33 +98,33 @@ public:<br>
void run();<br>
<br>
private:<br>
- void segregate(size_t Begin, size_t End, bool Constant);<br>
+ void segregate(size_t begin, size_t end, bool constant);<br>
<br>
template <class RelTy><br>
- bool constantEq(const InputSection *A, ArrayRef<RelTy> RelsA,<br>
- const InputSection *B, ArrayRef<RelTy> RelsB);<br>
+ bool constantEq(const InputSection *a, ArrayRef<RelTy> relsA,<br>
+ const InputSection *b, ArrayRef<RelTy> relsB);<br>
<br>
template <class RelTy><br>
- bool variableEq(const InputSection *A, ArrayRef<RelTy> RelsA,<br>
- const InputSection *B, ArrayRef<RelTy> RelsB);<br>
+ bool variableEq(const InputSection *a, ArrayRef<RelTy> relsA,<br>
+ const InputSection *b, ArrayRef<RelTy> relsB);<br>
<br>
- bool equalsConstant(const InputSection *A, const InputSection *B);<br>
- bool equalsVariable(const InputSection *A, const InputSection *B);<br>
+ bool equalsConstant(const InputSection *a, const InputSection *b);<br>
+ bool equalsVariable(const InputSection *a, const InputSection *b);<br>
<br>
- size_t findBoundary(size_t Begin, size_t End);<br>
+ size_t findBoundary(size_t begin, size_t end);<br>
<br>
- void forEachClassRange(size_t Begin, size_t End,<br>
- llvm::function_ref<void(size_t, size_t)> Fn);<br>
+ void forEachClassRange(size_t begin, size_t end,<br>
+ llvm::function_ref<void(size_t, size_t)> fn);<br>
<br>
- void forEachClass(llvm::function_ref<void(size_t, size_t)> Fn);<br>
+ void forEachClass(llvm::function_ref<void(size_t, size_t)> fn);<br>
<br>
- std::vector<InputSection *> Sections;<br>
+ std::vector<InputSection *> sections;<br>
<br>
// We repeat the main loop while `Repeat` is true.<br>
- std::atomic<bool> Repeat;<br>
+ std::atomic<bool> repeat;<br>
<br>
// The main loop counter.<br>
- int Cnt = 0;<br>
+ int cnt = 0;<br>
<br>
// We have two locations for equivalence classes. On the first iteration<br>
// of the main loop, Class[0] has a valid value, and Class[1] contains<br>
@@ -150,42 +150,42 @@ private:<br>
// because we can safely read the next class without worrying about race<br>
// conditions. Using the same location makes this algorithm converge<br>
// faster because it uses results of the same iteration earlier.<br>
- int Current = 0;<br>
- int Next = 0;<br>
+ int current = 0;<br>
+ int next = 0;<br>
};<br>
}<br>
<br>
// Returns true if section S is subject of ICF.<br>
-static bool isEligible(InputSection *S) {<br>
- if (!S->isLive() || S->KeepUnique || !(S->Flags & SHF_ALLOC))<br>
+static bool isEligible(InputSection *s) {<br>
+ if (!s->isLive() || s->keepUnique || !(s->flags & SHF_ALLOC))<br>
return false;<br>
<br>
// Don't merge writable sections. .<a href="http://data.rel.ro" rel="noreferrer" target="_blank">data.rel.ro</a> sections are marked as writable<br>
// but are semantically read-only.<br>
- if ((S->Flags & SHF_WRITE) && S->Name != ".<a href="http://data.rel.ro" rel="noreferrer" target="_blank">data.rel.ro</a>" &&<br>
- !S->Name.startswith(".<a href="http://data.rel.ro" rel="noreferrer" target="_blank">data.rel.ro</a>."))<br>
+ if ((s->flags & SHF_WRITE) && s->name != ".<a href="http://data.rel.ro" rel="noreferrer" target="_blank">data.rel.ro</a>" &&<br>
+ !s->name.startswith(".<a href="http://data.rel.ro" rel="noreferrer" target="_blank">data.rel.ro</a>."))<br>
return false;<br>
<br>
// SHF_LINK_ORDER sections are ICF'd as a unit with their dependent sections,<br>
// so we don't consider them for ICF individually.<br>
- if (S->Flags & SHF_LINK_ORDER)<br>
+ if (s->flags & SHF_LINK_ORDER)<br>
return false;<br>
<br>
// Don't merge synthetic sections as their Data member is not valid and empty.<br>
// The Data member needs to be valid for ICF as it is used by ICF to determine<br>
// the equality of section contents.<br>
- if (isa<SyntheticSection>(S))<br>
+ if (isa<SyntheticSection>(s))<br>
return false;<br>
<br>
// .init and .fini contains instructions that must be executed to initialize<br>
// and finalize the process. They cannot and should not be merged.<br>
- if (S->Name == ".init" || S->Name == ".fini")<br>
+ if (s->name == ".init" || s->name == ".fini")<br>
return false;<br>
<br>
// A user program may enumerate sections named with a C identifier using<br>
// __start_* and __stop_* symbols. We cannot ICF any such sections because<br>
// that could change program semantics.<br>
- if (isValidCIdentifier(S->Name))<br>
+ if (isValidCIdentifier(s->name))<br>
return false;<br>
<br>
return true;<br>
@@ -193,7 +193,7 @@ static bool isEligible(InputSection *S)<br>
<br>
// Split an equivalence class into smaller classes.<br>
template <class ELFT><br>
-void ICF<ELFT>::segregate(size_t Begin, size_t End, bool Constant) {<br>
+void ICF<ELFT>::segregate(size_t begin, size_t end, bool constant) {<br>
// This loop rearranges sections in [Begin, End) so that all sections<br>
// that are equal in terms of equals{Constant,Variable} are contiguous<br>
// in [Begin, End).<br>
@@ -202,93 +202,93 @@ void ICF<ELFT>::segregate(size_t Begin,<br>
// issue in practice because the number of the distinct sections in<br>
// each range is usually very small.<br>
<br>
- while (Begin < End) {<br>
+ while (begin < end) {<br>
// Divide [Begin, End) into two. Let Mid be the start index of the<br>
// second group.<br>
- auto Bound =<br>
- std::stable_partition(Sections.begin() + Begin + 1,<br>
- Sections.begin() + End, [&](InputSection *S) {<br>
- if (Constant)<br>
- return equalsConstant(Sections[Begin], S);<br>
- return equalsVariable(Sections[Begin], S);<br>
+ auto bound =<br>
+ std::stable_partition(sections.begin() + begin + 1,<br>
+ sections.begin() + end, [&](InputSection *s) {<br>
+ if (constant)<br>
+ return equalsConstant(sections[begin], s);<br>
+ return equalsVariable(sections[begin], s);<br>
});<br>
- size_t Mid = Bound - Sections.begin();<br>
+ size_t mid = bound - sections.begin();<br>
<br>
// Now we split [Begin, End) into [Begin, Mid) and [Mid, End) by<br>
// updating the sections in [Begin, Mid). We use Mid as an equivalence<br>
// class ID because every group ends with a unique index.<br>
- for (size_t I = Begin; I < Mid; ++I)<br>
- Sections[I]->Class[Next] = Mid;<br>
+ for (size_t i = begin; i < mid; ++i)<br>
+ sections[i]->eqClass[next] = mid;<br>
<br>
// If we created a group, we need to iterate the main loop again.<br>
- if (Mid != End)<br>
- Repeat = true;<br>
+ if (mid != end)<br>
+ repeat = true;<br>
<br>
- Begin = Mid;<br>
+ begin = mid;<br>
}<br>
}<br>
<br>
// Compare two lists of relocations.<br>
template <class ELFT><br>
template <class RelTy><br>
-bool ICF<ELFT>::constantEq(const InputSection *SecA, ArrayRef<RelTy> RA,<br>
- const InputSection *SecB, ArrayRef<RelTy> RB) {<br>
- for (size_t I = 0; I < RA.size(); ++I) {<br>
- if (RA[I].r_offset != RB[I].r_offset ||<br>
- RA[I].getType(Config->IsMips64EL) != RB[I].getType(Config->IsMips64EL))<br>
+bool ICF<ELFT>::constantEq(const InputSection *secA, ArrayRef<RelTy> ra,<br>
+ const InputSection *secB, ArrayRef<RelTy> rb) {<br>
+ for (size_t i = 0; i < ra.size(); ++i) {<br>
+ if (ra[i].r_offset != rb[i].r_offset ||<br>
+ ra[i].getType(config->isMips64EL) != rb[i].getType(config->isMips64EL))<br>
return false;<br>
<br>
- uint64_t AddA = getAddend<ELFT>(RA[I]);<br>
- uint64_t AddB = getAddend<ELFT>(RB[I]);<br>
-<br>
- Symbol &SA = SecA->template getFile<ELFT>()->getRelocTargetSym(RA[I]);<br>
- Symbol &SB = SecB->template getFile<ELFT>()->getRelocTargetSym(RB[I]);<br>
- if (&SA == &SB) {<br>
- if (AddA == AddB)<br>
+ uint64_t addA = getAddend<ELFT>(ra[i]);<br>
+ uint64_t addB = getAddend<ELFT>(rb[i]);<br>
+<br>
+ Symbol &sa = secA->template getFile<ELFT>()->getRelocTargetSym(ra[i]);<br>
+ Symbol &sb = secB->template getFile<ELFT>()->getRelocTargetSym(rb[i]);<br>
+ if (&sa == &sb) {<br>
+ if (addA == addB)<br>
continue;<br>
return false;<br>
}<br>
<br>
- auto *DA = dyn_cast<Defined>(&SA);<br>
- auto *DB = dyn_cast<Defined>(&SB);<br>
+ auto *da = dyn_cast<Defined>(&sa);<br>
+ auto *db = dyn_cast<Defined>(&sb);<br>
<br>
// Placeholder symbols generated by linker scripts look the same now but<br>
// may have different values later.<br>
- if (!DA || !DB || DA->ScriptDefined || DB->ScriptDefined)<br>
+ if (!da || !db || da->scriptDefined || db->scriptDefined)<br>
return false;<br>
<br>
// Relocations referring to absolute symbols are constant-equal if their<br>
// values are equal.<br>
- if (!DA->Section && !DB->Section && DA->Value + AddA == DB->Value + AddB)<br>
+ if (!da->section && !db->section && da->value + addA == db->value + addB)<br>
continue;<br>
- if (!DA->Section || !DB->Section)<br>
+ if (!da->section || !db->section)<br>
return false;<br>
<br>
- if (DA->Section->kind() != DB->Section->kind())<br>
+ if (da->section->kind() != db->section->kind())<br>
return false;<br>
<br>
// Relocations referring to InputSections are constant-equal if their<br>
// section offsets are equal.<br>
- if (isa<InputSection>(DA->Section)) {<br>
- if (DA->Value + AddA == DB->Value + AddB)<br>
+ if (isa<InputSection>(da->section)) {<br>
+ if (da->value + addA == db->value + addB)<br>
continue;<br>
return false;<br>
}<br>
<br>
// Relocations referring to MergeInputSections are constant-equal if their<br>
// offsets in the output section are equal.<br>
- auto *X = dyn_cast<MergeInputSection>(DA->Section);<br>
- if (!X)<br>
+ auto *x = dyn_cast<MergeInputSection>(da->section);<br>
+ if (!x)<br>
return false;<br>
- auto *Y = cast<MergeInputSection>(DB->Section);<br>
- if (X->getParent() != Y->getParent())<br>
+ auto *y = cast<MergeInputSection>(db->section);<br>
+ if (x->getParent() != y->getParent())<br>
return false;<br>
<br>
- uint64_t OffsetA =<br>
- SA.isSection() ? X->getOffset(AddA) : X->getOffset(DA->Value) + AddA;<br>
- uint64_t OffsetB =<br>
- SB.isSection() ? Y->getOffset(AddB) : Y->getOffset(DB->Value) + AddB;<br>
- if (OffsetA != OffsetB)<br>
+ uint64_t offsetA =<br>
+ sa.isSection() ? x->getOffset(addA) : x->getOffset(da->value) + addA;<br>
+ uint64_t offsetB =<br>
+ sb.isSection() ? y->getOffset(addB) : y->getOffset(db->value) + addB;<br>
+ if (offsetA != offsetB)<br>
return false;<br>
}<br>
<br>
@@ -298,57 +298,57 @@ bool ICF<ELFT>::constantEq(const InputSe<br>
// Compare "non-moving" part of two InputSections, namely everything<br>
// except relocation targets.<br>
template <class ELFT><br>
-bool ICF<ELFT>::equalsConstant(const InputSection *A, const InputSection *B) {<br>
- if (A->NumRelocations != B->NumRelocations || A->Flags != B->Flags ||<br>
- A->getSize() != B->getSize() || A->data() != B->data())<br>
+bool ICF<ELFT>::equalsConstant(const InputSection *a, const InputSection *b) {<br>
+ if (a->numRelocations != b->numRelocations || a->flags != b->flags ||<br>
+ a->getSize() != b->getSize() || a->data() != b->data())<br>
return false;<br>
<br>
// If two sections have different output sections, we cannot merge them.<br>
// FIXME: This doesn't do the right thing in the case where there is a linker<br>
// script. We probably need to move output section assignment before ICF to<br>
// get the correct behaviour here.<br>
- if (getOutputSectionName(A) != getOutputSectionName(B))<br>
+ if (getOutputSectionName(a) != getOutputSectionName(b))<br>
return false;<br>
<br>
- if (A->AreRelocsRela)<br>
- return constantEq(A, A->template relas<ELFT>(), B,<br>
- B->template relas<ELFT>());<br>
- return constantEq(A, A->template rels<ELFT>(), B, B->template rels<ELFT>());<br>
+ if (a->areRelocsRela)<br>
+ return constantEq(a, a->template relas<ELFT>(), b,<br>
+ b->template relas<ELFT>());<br>
+ return constantEq(a, a->template rels<ELFT>(), b, b->template rels<ELFT>());<br>
}<br>
<br>
// Compare two lists of relocations. Returns true if all pairs of<br>
// relocations point to the same section in terms of ICF.<br>
template <class ELFT><br>
template <class RelTy><br>
-bool ICF<ELFT>::variableEq(const InputSection *SecA, ArrayRef<RelTy> RA,<br>
- const InputSection *SecB, ArrayRef<RelTy> RB) {<br>
- assert(RA.size() == RB.size());<br>
+bool ICF<ELFT>::variableEq(const InputSection *secA, ArrayRef<RelTy> ra,<br>
+ const InputSection *secB, ArrayRef<RelTy> rb) {<br>
+ assert(ra.size() == rb.size());<br>
<br>
- for (size_t I = 0; I < RA.size(); ++I) {<br>
+ for (size_t i = 0; i < ra.size(); ++i) {<br>
// The two sections must be identical.<br>
- Symbol &SA = SecA->template getFile<ELFT>()->getRelocTargetSym(RA[I]);<br>
- Symbol &SB = SecB->template getFile<ELFT>()->getRelocTargetSym(RB[I]);<br>
- if (&SA == &SB)<br>
+ Symbol &sa = secA->template getFile<ELFT>()->getRelocTargetSym(ra[i]);<br>
+ Symbol &sb = secB->template getFile<ELFT>()->getRelocTargetSym(rb[i]);<br>
+ if (&sa == &sb)<br>
continue;<br>
<br>
- auto *DA = cast<Defined>(&SA);<br>
- auto *DB = cast<Defined>(&SB);<br>
+ auto *da = cast<Defined>(&sa);<br>
+ auto *db = cast<Defined>(&sb);<br>
<br>
// We already dealt with absolute and non-InputSection symbols in<br>
// constantEq, and for InputSections we have already checked everything<br>
// except the equivalence class.<br>
- if (!DA->Section)<br>
+ if (!da->section)<br>
continue;<br>
- auto *X = dyn_cast<InputSection>(DA->Section);<br>
- if (!X)<br>
+ auto *x = dyn_cast<InputSection>(da->section);<br>
+ if (!x)<br>
continue;<br>
- auto *Y = cast<InputSection>(DB->Section);<br>
+ auto *y = cast<InputSection>(db->section);<br>
<br>
// Ineligible sections are in the special equivalence class 0.<br>
// They can never be the same in terms of the equivalence class.<br>
- if (X->Class[Current] == 0)<br>
+ if (x->eqClass[current] == 0)<br>
return false;<br>
- if (X->Class[Current] != Y->Class[Current])<br>
+ if (x->eqClass[current] != y->eqClass[current])<br>
return false;<br>
};<br>
<br>
@@ -357,19 +357,19 @@ bool ICF<ELFT>::variableEq(const InputSe<br>
<br>
// Compare "moving" part of two InputSections, namely relocation targets.<br>
template <class ELFT><br>
-bool ICF<ELFT>::equalsVariable(const InputSection *A, const InputSection *B) {<br>
- if (A->AreRelocsRela)<br>
- return variableEq(A, A->template relas<ELFT>(), B,<br>
- B->template relas<ELFT>());<br>
- return variableEq(A, A->template rels<ELFT>(), B, B->template rels<ELFT>());<br>
+bool ICF<ELFT>::equalsVariable(const InputSection *a, const InputSection *b) {<br>
+ if (a->areRelocsRela)<br>
+ return variableEq(a, a->template relas<ELFT>(), b,<br>
+ b->template relas<ELFT>());<br>
+ return variableEq(a, a->template rels<ELFT>(), b, b->template rels<ELFT>());<br>
}<br>
<br>
-template <class ELFT> size_t ICF<ELFT>::findBoundary(size_t Begin, size_t End) {<br>
- uint32_t Class = Sections[Begin]->Class[Current];<br>
- for (size_t I = Begin + 1; I < End; ++I)<br>
- if (Class != Sections[I]->Class[Current])<br>
- return I;<br>
- return End;<br>
+template <class ELFT> size_t ICF<ELFT>::findBoundary(size_t begin, size_t end) {<br>
+ uint32_t eqClass = sections[begin]->eqClass[current];<br>
+ for (size_t i = begin + 1; i < end; ++i)<br>
+ if (eqClass != sections[i]->eqClass[current])<br>
+ return i;<br>
+ return end;<br>
}<br>
<br>
// Sections in the same equivalence class are contiguous in Sections<br>
@@ -378,125 +378,125 @@ template <class ELFT> size_t ICF<ELFT>::<br>
//<br>
// This function calls Fn on every group within [Begin, End).<br>
template <class ELFT><br>
-void ICF<ELFT>::forEachClassRange(size_t Begin, size_t End,<br>
- llvm::function_ref<void(size_t, size_t)> Fn) {<br>
- while (Begin < End) {<br>
- size_t Mid = findBoundary(Begin, End);<br>
- Fn(Begin, Mid);<br>
- Begin = Mid;<br>
+void ICF<ELFT>::forEachClassRange(size_t begin, size_t end,<br>
+ llvm::function_ref<void(size_t, size_t)> fn) {<br>
+ while (begin < end) {<br>
+ size_t mid = findBoundary(begin, end);<br>
+ fn(begin, mid);<br>
+ begin = mid;<br>
}<br>
}<br>
<br>
// Call Fn on each equivalence class.<br>
template <class ELFT><br>
-void ICF<ELFT>::forEachClass(llvm::function_ref<void(size_t, size_t)> Fn) {<br>
+void ICF<ELFT>::forEachClass(llvm::function_ref<void(size_t, size_t)> fn) {<br>
// If threading is disabled or the number of sections are<br>
// too small to use threading, call Fn sequentially.<br>
- if (!ThreadsEnabled || Sections.size() < 1024) {<br>
- forEachClassRange(0, Sections.size(), Fn);<br>
- ++Cnt;<br>
+ if (!ThreadsEnabled || sections.size() < 1024) {<br>
+ forEachClassRange(0, sections.size(), fn);<br>
+ ++cnt;<br>
return;<br>
}<br>
<br>
- Current = Cnt % 2;<br>
- Next = (Cnt + 1) % 2;<br>
+ current = cnt % 2;<br>
+ next = (cnt + 1) % 2;<br>
<br>
// Shard into non-overlapping intervals, and call Fn in parallel.<br>
// The sharding must be completed before any calls to Fn are made<br>
// so that Fn can modify the Chunks in its shard without causing data<br>
// races.<br>
- const size_t NumShards = 256;<br>
- size_t Step = Sections.size() / NumShards;<br>
- size_t Boundaries[NumShards + 1];<br>
- Boundaries[0] = 0;<br>
- Boundaries[NumShards] = Sections.size();<br>
+ const size_t numShards = 256;<br>
+ size_t step = sections.size() / numShards;<br>
+ size_t boundaries[numShards + 1];<br>
+ boundaries[0] = 0;<br>
+ boundaries[numShards] = sections.size();<br>
<br>
- parallelForEachN(1, NumShards, [&](size_t I) {<br>
- Boundaries[I] = findBoundary((I - 1) * Step, Sections.size());<br>
+ parallelForEachN(1, numShards, [&](size_t i) {<br>
+ boundaries[i] = findBoundary((i - 1) * step, sections.size());<br>
});<br>
<br>
- parallelForEachN(1, NumShards + 1, [&](size_t I) {<br>
- if (Boundaries[I - 1] < Boundaries[I])<br>
- forEachClassRange(Boundaries[I - 1], Boundaries[I], Fn);<br>
+ parallelForEachN(1, numShards + 1, [&](size_t i) {<br>
+ if (boundaries[i - 1] < boundaries[i])<br>
+ forEachClassRange(boundaries[i - 1], boundaries[i], fn);<br>
});<br>
- ++Cnt;<br>
+ ++cnt;<br>
}<br>
<br>
// Combine the hashes of the sections referenced by the given section into its<br>
// hash.<br>
template <class ELFT, class RelTy><br>
-static void combineRelocHashes(unsigned Cnt, InputSection *IS,<br>
- ArrayRef<RelTy> Rels) {<br>
- uint32_t Hash = IS->Class[Cnt % 2];<br>
- for (RelTy Rel : Rels) {<br>
- Symbol &S = IS->template getFile<ELFT>()->getRelocTargetSym(Rel);<br>
- if (auto *D = dyn_cast<Defined>(&S))<br>
- if (auto *RelSec = dyn_cast_or_null<InputSection>(D->Section))<br>
- Hash += RelSec->Class[Cnt % 2];<br>
+static void combineRelocHashes(unsigned cnt, InputSection *isec,<br>
+ ArrayRef<RelTy> rels) {<br>
+ uint32_t hash = isec->eqClass[cnt % 2];<br>
+ for (RelTy rel : rels) {<br>
+ Symbol &s = isec->template getFile<ELFT>()->getRelocTargetSym(rel);<br>
+ if (auto *d = dyn_cast<Defined>(&s))<br>
+ if (auto *relSec = dyn_cast_or_null<InputSection>(d->section))<br>
+ hash += relSec->eqClass[cnt % 2];<br>
}<br>
// Set MSB to 1 to avoid collisions with non-hash IDs.<br>
- IS->Class[(Cnt + 1) % 2] = Hash | (1U << 31);<br>
+ isec->eqClass[(cnt + 1) % 2] = hash | (1U << 31);<br>
}<br>
<br>
-static void print(const Twine &S) {<br>
- if (Config->PrintIcfSections)<br>
- message(S);<br>
+static void print(const Twine &s) {<br>
+ if (config->printIcfSections)<br>
+ message(s);<br>
}<br>
<br>
// The main function of ICF.<br>
template <class ELFT> void ICF<ELFT>::run() {<br>
// Collect sections to merge.<br>
- for (InputSectionBase *Sec : InputSections)<br>
- if (auto *S = dyn_cast<InputSection>(Sec))<br>
- if (isEligible(S))<br>
- Sections.push_back(S);<br>
+ for (InputSectionBase *sec : inputSections)<br>
+ if (auto *s = dyn_cast<InputSection>(sec))<br>
+ if (isEligible(s))<br>
+ sections.push_back(s);<br>
<br>
// Initially, we use hash values to partition sections.<br>
- parallelForEach(Sections, [&](InputSection *S) {<br>
- S->Class[0] = xxHash64(S->data());<br>
+ parallelForEach(sections, [&](InputSection *s) {<br>
+ s->eqClass[0] = xxHash64(s->data());<br>
});<br>
<br>
- for (unsigned Cnt = 0; Cnt != 2; ++Cnt) {<br>
- parallelForEach(Sections, [&](InputSection *S) {<br>
- if (S->AreRelocsRela)<br>
- combineRelocHashes<ELFT>(Cnt, S, S->template relas<ELFT>());<br>
+ for (unsigned cnt = 0; cnt != 2; ++cnt) {<br>
+ parallelForEach(sections, [&](InputSection *s) {<br>
+ if (s->areRelocsRela)<br>
+ combineRelocHashes<ELFT>(cnt, s, s->template relas<ELFT>());<br>
else<br>
- combineRelocHashes<ELFT>(Cnt, S, S->template rels<ELFT>());<br>
+ combineRelocHashes<ELFT>(cnt, s, s->template rels<ELFT>());<br>
});<br>
}<br>
<br>
// From now on, sections in Sections vector are ordered so that sections<br>
// in the same equivalence class are consecutive in the vector.<br>
- llvm::stable_sort(Sections, [](const InputSection *A, const InputSection *B) {<br>
- return A->Class[0] < B->Class[0];<br>
+ llvm::stable_sort(sections, [](const InputSection *a, const InputSection *b) {<br>
+ return a->eqClass[0] < b->eqClass[0];<br>
});<br>
<br>
// Compare static contents and assign unique IDs for each static content.<br>
- forEachClass([&](size_t Begin, size_t End) { segregate(Begin, End, true); });<br>
+ forEachClass([&](size_t begin, size_t end) { segregate(begin, end, true); });<br>
<br>
// Split groups by comparing relocations until convergence is obtained.<br>
do {<br>
- Repeat = false;<br>
+ repeat = false;<br>
forEachClass(<br>
- [&](size_t Begin, size_t End) { segregate(Begin, End, false); });<br>
- } while (Repeat);<br>
+ [&](size_t begin, size_t end) { segregate(begin, end, false); });<br>
+ } while (repeat);<br>
<br>
- log("ICF needed " + Twine(Cnt) + " iterations");<br>
+ log("ICF needed " + Twine(cnt) + " iterations");<br>
<br>
// Merge sections by the equivalence class.<br>
- forEachClassRange(0, Sections.size(), [&](size_t Begin, size_t End) {<br>
- if (End - Begin == 1)<br>
+ forEachClassRange(0, sections.size(), [&](size_t begin, size_t end) {<br>
+ if (end - begin == 1)<br>
return;<br>
- print("selected section " + toString(Sections[Begin]));<br>
- for (size_t I = Begin + 1; I < End; ++I) {<br>
- print(" removing identical section " + toString(Sections[I]));<br>
- Sections[Begin]->replace(Sections[I]);<br>
+ print("selected section " + toString(sections[begin]));<br>
+ for (size_t i = begin + 1; i < end; ++i) {<br>
+ print(" removing identical section " + toString(sections[i]));<br>
+ sections[begin]->replace(sections[i]);<br>
<br>
// At this point we know sections merged are fully identical and hence<br>
// we want to remove duplicate implicit dependencies such as link order<br>
// and relocation sections.<br>
- for (InputSection *IS : Sections[I]->DependentSections)<br>
- IS->markDead();<br>
+ for (InputSection *isec : sections[i]->dependentSections)<br>
+ isec->markDead();<br>
}<br>
});<br>
}<br>
<br>
Modified: lld/trunk/ELF/InputFiles.cpp<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_ELF_InputFiles.cpp-3Frev-3D365595-26r1-3D365594-26r2-3D365595-26view-3Ddiff&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=GJ5xqpJkWibOMk0BSiEfVapSpT45DiE3cFQ9Day_oHk&e=" rel="noreferrer" target="_blank">https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_ELF_InputFiles.cpp-3Frev-3D365595-26r1-3D365594-26r2-3D365595-26view-3Ddiff&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=GJ5xqpJkWibOMk0BSiEfVapSpT45DiE3cFQ9Day_oHk&e=</a> <br>
==============================================================================<br>
--- lld/trunk/ELF/InputFiles.cpp (original)<br>
+++ lld/trunk/ELF/InputFiles.cpp Tue Jul 9 22:00:37 2019<br>
@@ -40,167 +40,167 @@ using namespace llvm::support::endian;<br>
using namespace lld;<br>
using namespace lld::elf;<br>
<br>
-bool InputFile::IsInGroup;<br>
-uint32_t InputFile::NextGroupId;<br>
-std::vector<BinaryFile *> elf::BinaryFiles;<br>
-std::vector<BitcodeFile *> elf::BitcodeFiles;<br>
-std::vector<LazyObjFile *> elf::LazyObjFiles;<br>
-std::vector<InputFile *> elf::ObjectFiles;<br>
-std::vector<SharedFile *> elf::SharedFiles;<br>
-<br>
-std::unique_ptr<TarWriter> elf::Tar;<br>
-<br>
-static ELFKind getELFKind(MemoryBufferRef MB, StringRef ArchiveName) {<br>
- unsigned char Size;<br>
- unsigned char Endian;<br>
- std::tie(Size, Endian) = getElfArchType(MB.getBuffer());<br>
-<br>
- auto Report = [&](StringRef Msg) {<br>
- StringRef Filename = MB.getBufferIdentifier();<br>
- if (ArchiveName.empty())<br>
- fatal(Filename + ": " + Msg);<br>
+bool InputFile::isInGroup;<br>
+uint32_t InputFile::nextGroupId;<br>
+std::vector<BinaryFile *> elf::binaryFiles;<br>
+std::vector<BitcodeFile *> elf::bitcodeFiles;<br>
+std::vector<LazyObjFile *> elf::lazyObjFiles;<br>
+std::vector<InputFile *> elf::objectFiles;<br>
+std::vector<SharedFile *> elf::sharedFiles;<br>
+<br>
+std::unique_ptr<TarWriter> elf::tar;<br>
+<br>
+static ELFKind getELFKind(MemoryBufferRef mb, StringRef archiveName) {<br>
+ unsigned char size;<br>
+ unsigned char endian;<br>
+ std::tie(size, endian) = getElfArchType(mb.getBuffer());<br>
+<br>
+ auto report = [&](StringRef msg) {<br>
+ StringRef filename = mb.getBufferIdentifier();<br>
+ if (archiveName.empty())<br>
+ fatal(filename + ": " + msg);<br>
else<br>
- fatal(ArchiveName + "(" + Filename + "): " + Msg);<br>
+ fatal(archiveName + "(" + filename + "): " + msg);<br>
};<br>
<br>
- if (!MB.getBuffer().startswith(ElfMagic))<br>
- Report("not an ELF file");<br>
- if (Endian != ELFDATA2LSB && Endian != ELFDATA2MSB)<br>
- Report("corrupted ELF file: invalid data encoding");<br>
- if (Size != ELFCLASS32 && Size != ELFCLASS64)<br>
- Report("corrupted ELF file: invalid file class");<br>
-<br>
- size_t BufSize = MB.getBuffer().size();<br>
- if ((Size == ELFCLASS32 && BufSize < sizeof(Elf32_Ehdr)) ||<br>
- (Size == ELFCLASS64 && BufSize < sizeof(Elf64_Ehdr)))<br>
- Report("corrupted ELF file: file is too short");<br>
-<br>
- if (Size == ELFCLASS32)<br>
- return (Endian == ELFDATA2LSB) ? ELF32LEKind : ELF32BEKind;<br>
- return (Endian == ELFDATA2LSB) ? ELF64LEKind : ELF64BEKind;<br>
+ if (!mb.getBuffer().startswith(ElfMagic))<br>
+ report("not an ELF file");<br>
+ if (endian != ELFDATA2LSB && endian != ELFDATA2MSB)<br>
+ report("corrupted ELF file: invalid data encoding");<br>
+ if (size != ELFCLASS32 && size != ELFCLASS64)<br>
+ report("corrupted ELF file: invalid file class");<br>
+<br>
+ size_t bufSize = mb.getBuffer().size();<br>
+ if ((size == ELFCLASS32 && bufSize < sizeof(Elf32_Ehdr)) ||<br>
+ (size == ELFCLASS64 && bufSize < sizeof(Elf64_Ehdr)))<br>
+ report("corrupted ELF file: file is too short");<br>
+<br>
+ if (size == ELFCLASS32)<br>
+ return (endian == ELFDATA2LSB) ? ELF32LEKind : ELF32BEKind;<br>
+ return (endian == ELFDATA2LSB) ? ELF64LEKind : ELF64BEKind;<br>
}<br>
<br>
-InputFile::InputFile(Kind K, MemoryBufferRef M)<br>
- : MB(M), GroupId(NextGroupId), FileKind(K) {<br>
+InputFile::InputFile(Kind k, MemoryBufferRef m)<br>
+ : mb(m), groupId(nextGroupId), fileKind(k) {<br>
// All files within the same --{start,end}-group get the same group ID.<br>
// Otherwise, a new file will get a new group ID.<br>
- if (!IsInGroup)<br>
- ++NextGroupId;<br>
+ if (!isInGroup)<br>
+ ++nextGroupId;<br>
}<br>
<br>
-Optional<MemoryBufferRef> elf::readFile(StringRef Path) {<br>
+Optional<MemoryBufferRef> elf::readFile(StringRef path) {<br>
// The --chroot option changes our virtual root directory.<br>
// This is useful when you are dealing with files created by --reproduce.<br>
- if (!Config->Chroot.empty() && Path.startswith("/"))<br>
- Path = Saver.save(Config->Chroot + Path);<br>
+ if (!config->chroot.empty() && path.startswith("/"))<br>
+ path = Saver.save(config->chroot + path);<br>
<br>
- log(Path);<br>
+ log(path);<br>
<br>
- auto MBOrErr = MemoryBuffer::getFile(Path, -1, false);<br>
- if (auto EC = MBOrErr.getError()) {<br>
- error("cannot open " + Path + ": " + EC.message());<br>
+ auto mbOrErr = MemoryBuffer::getFile(path, -1, false);<br>
+ if (auto ec = mbOrErr.getError()) {<br>
+ error("cannot open " + path + ": " + ec.message());<br>
return None;<br>
}<br>
<br>
- std::unique_ptr<MemoryBuffer> &MB = *MBOrErr;<br>
- MemoryBufferRef MBRef = MB->getMemBufferRef();<br>
- make<std::unique_ptr<MemoryBuffer>>(std::move(MB)); // take MB ownership<br>
-<br>
- if (Tar)<br>
- Tar->append(relativeToRoot(Path), MBRef.getBuffer());<br>
- return MBRef;<br>
+ std::unique_ptr<MemoryBuffer> &mb = *mbOrErr;<br>
+ MemoryBufferRef mbref = mb->getMemBufferRef();<br>
+ make<std::unique_ptr<MemoryBuffer>>(std::move(mb)); // take MB ownership<br>
+<br>
+ if (tar)<br>
+ tar->append(relativeToRoot(path), mbref.getBuffer());<br>
+ return mbref;<br>
}<br>
<br>
// All input object files must be for the same architecture<br>
// (e.g. it does not make sense to link x86 object files with<br>
// MIPS object files.) This function checks for that error.<br>
-static bool isCompatible(InputFile *File) {<br>
- if (!File->isElf() && !isa<BitcodeFile>(File))<br>
+static bool isCompatible(InputFile *file) {<br>
+ if (!file->isElf() && !isa<BitcodeFile>(file))<br>
return true;<br>
<br>
- if (File->EKind == Config->EKind && File->EMachine == Config->EMachine) {<br>
- if (Config->EMachine != EM_MIPS)<br>
+ if (file->ekind == config->ekind && file->emachine == config->emachine) {<br>
+ if (config->emachine != EM_MIPS)<br>
return true;<br>
- if (isMipsN32Abi(File) == Config->MipsN32Abi)<br>
+ if (isMipsN32Abi(file) == config->mipsN32Abi)<br>
return true;<br>
}<br>
<br>
- if (!Config->Emulation.empty()) {<br>
- error(toString(File) + " is incompatible with " + Config->Emulation);<br>
+ if (!config->emulation.empty()) {<br>
+ error(toString(file) + " is incompatible with " + config->emulation);<br>
} else {<br>
- InputFile *Existing;<br>
- if (!ObjectFiles.empty())<br>
- Existing = ObjectFiles[0];<br>
- else if (!SharedFiles.empty())<br>
- Existing = SharedFiles[0];<br>
+ InputFile *existing;<br>
+ if (!objectFiles.empty())<br>
+ existing = objectFiles[0];<br>
+ else if (!sharedFiles.empty())<br>
+ existing = sharedFiles[0];<br>
else<br>
- Existing = BitcodeFiles[0];<br>
+ existing = bitcodeFiles[0];<br>
<br>
- error(toString(File) + " is incompatible with " + toString(Existing));<br>
+ error(toString(file) + " is incompatible with " + toString(existing));<br>
}<br>
<br>
return false;<br>
}<br>
<br>
-template <class ELFT> static void doParseFile(InputFile *File) {<br>
- if (!isCompatible(File))<br>
+template <class ELFT> static void doParseFile(InputFile *file) {<br>
+ if (!isCompatible(file))<br>
return;<br>
<br>
// Binary file<br>
- if (auto *F = dyn_cast<BinaryFile>(File)) {<br>
- BinaryFiles.push_back(F);<br>
- F->parse();<br>
+ if (auto *f = dyn_cast<BinaryFile>(file)) {<br>
+ binaryFiles.push_back(f);<br>
+ f->parse();<br>
return;<br>
}<br>
<br>
// .a file<br>
- if (auto *F = dyn_cast<ArchiveFile>(File)) {<br>
- F->parse();<br>
+ if (auto *f = dyn_cast<ArchiveFile>(file)) {<br>
+ f->parse();<br>
return;<br>
}<br>
<br>
// Lazy object file<br>
- if (auto *F = dyn_cast<LazyObjFile>(File)) {<br>
- LazyObjFiles.push_back(F);<br>
- F->parse<ELFT>();<br>
+ if (auto *f = dyn_cast<LazyObjFile>(file)) {<br>
+ lazyObjFiles.push_back(f);<br>
+ f->parse<ELFT>();<br>
return;<br>
}<br>
<br>
- if (Config->Trace)<br>
- message(toString(File));<br>
+ if (config->trace)<br>
+ message(toString(file));<br>
<br>
// .so file<br>
- if (auto *F = dyn_cast<SharedFile>(File)) {<br>
- F->parse<ELFT>();<br>
+ if (auto *f = dyn_cast<SharedFile>(file)) {<br>
+ f->parse<ELFT>();<br>
return;<br>
}<br>
<br>
// LLVM bitcode file<br>
- if (auto *F = dyn_cast<BitcodeFile>(File)) {<br>
- BitcodeFiles.push_back(F);<br>
- F->parse<ELFT>();<br>
+ if (auto *f = dyn_cast<BitcodeFile>(file)) {<br>
+ bitcodeFiles.push_back(f);<br>
+ f->parse<ELFT>();<br>
return;<br>
}<br>
<br>
// Regular object file<br>
- ObjectFiles.push_back(File);<br>
- cast<ObjFile<ELFT>>(File)->parse();<br>
+ objectFiles.push_back(file);<br>
+ cast<ObjFile<ELFT>>(file)->parse();<br>
}<br>
<br>
// Add symbols in File to the symbol table.<br>
-void elf::parseFile(InputFile *File) {<br>
- switch (Config->EKind) {<br>
+void elf::parseFile(InputFile *file) {<br>
+ switch (config->ekind) {<br>
case ELF32LEKind:<br>
- doParseFile<ELF32LE>(File);<br>
+ doParseFile<ELF32LE>(file);<br>
return;<br>
case ELF32BEKind:<br>
- doParseFile<ELF32BE>(File);<br>
+ doParseFile<ELF32BE>(file);<br>
return;<br>
case ELF64LEKind:<br>
- doParseFile<ELF64LE>(File);<br>
+ doParseFile<ELF64LE>(file);<br>
return;<br>
case ELF64BEKind:<br>
- doParseFile<ELF64BE>(File);<br>
+ doParseFile<ELF64BE>(file);<br>
return;<br>
default:<br>
llvm_unreachable("unknown ELFT");<br>
@@ -208,87 +208,87 @@ void elf::parseFile(InputFile *File) {<br>
}<br>
<br>
// Concatenates arguments to construct a string representing an error location.<br>
-static std::string createFileLineMsg(StringRef Path, unsigned Line) {<br>
- std::string Filename = path::filename(Path);<br>
- std::string Lineno = ":" + std::to_string(Line);<br>
- if (Filename == Path)<br>
- return Filename + Lineno;<br>
- return Filename + Lineno + " (" + Path.str() + Lineno + ")";<br>
+static std::string createFileLineMsg(StringRef path, unsigned line) {<br>
+ std::string filename = path::filename(path);<br>
+ std::string lineno = ":" + std::to_string(line);<br>
+ if (filename == path)<br>
+ return filename + lineno;<br>
+ return filename + lineno + " (" + path.str() + lineno + ")";<br>
}<br>
<br>
template <class ELFT><br>
-static std::string getSrcMsgAux(ObjFile<ELFT> &File, const Symbol &Sym,<br>
- InputSectionBase &Sec, uint64_t Offset) {<br>
+static std::string getSrcMsgAux(ObjFile<ELFT> &file, const Symbol &sym,<br>
+ InputSectionBase &sec, uint64_t offset) {<br>
// In DWARF, functions and variables are stored to different places.<br>
// First, lookup a function for a given offset.<br>
- if (Optional<DILineInfo> Info = File.getDILineInfo(&Sec, Offset))<br>
- return createFileLineMsg(Info->FileName, Info->Line);<br>
+ if (Optional<DILineInfo> info = file.getDILineInfo(&sec, offset))<br>
+ return createFileLineMsg(info->FileName, info->Line);<br>
<br>
// If it failed, lookup again as a variable.<br>
- if (Optional<std::pair<std::string, unsigned>> FileLine =<br>
- File.getVariableLoc(Sym.getName()))<br>
- return createFileLineMsg(FileLine->first, FileLine->second);<br>
+ if (Optional<std::pair<std::string, unsigned>> fileLine =<br>
+ file.getVariableLoc(sym.getName()))<br>
+ return createFileLineMsg(fileLine->first, fileLine->second);<br>
<br>
// File.SourceFile contains STT_FILE symbol, and that is a last resort.<br>
- return File.SourceFile;<br>
+ return file.sourceFile;<br>
}<br>
<br>
-std::string InputFile::getSrcMsg(const Symbol &Sym, InputSectionBase &Sec,<br>
- uint64_t Offset) {<br>
+std::string InputFile::getSrcMsg(const Symbol &sym, InputSectionBase &sec,<br>
+ uint64_t offset) {<br>
if (kind() != ObjKind)<br>
return "";<br>
- switch (Config->EKind) {<br>
+ switch (config->ekind) {<br>
default:<br>
llvm_unreachable("Invalid kind");<br>
case ELF32LEKind:<br>
- return getSrcMsgAux(cast<ObjFile<ELF32LE>>(*this), Sym, Sec, Offset);<br>
+ return getSrcMsgAux(cast<ObjFile<ELF32LE>>(*this), sym, sec, offset);<br>
case ELF32BEKind:<br>
- return getSrcMsgAux(cast<ObjFile<ELF32BE>>(*this), Sym, Sec, Offset);<br>
+ return getSrcMsgAux(cast<ObjFile<ELF32BE>>(*this), sym, sec, offset);<br>
case ELF64LEKind:<br>
- return getSrcMsgAux(cast<ObjFile<ELF64LE>>(*this), Sym, Sec, Offset);<br>
+ return getSrcMsgAux(cast<ObjFile<ELF64LE>>(*this), sym, sec, offset);<br>
case ELF64BEKind:<br>
- return getSrcMsgAux(cast<ObjFile<ELF64BE>>(*this), Sym, Sec, Offset);<br>
+ return getSrcMsgAux(cast<ObjFile<ELF64BE>>(*this), sym, sec, offset);<br>
}<br>
}<br>
<br>
template <class ELFT> void ObjFile<ELFT>::initializeDwarf() {<br>
- Dwarf = llvm::make_unique<DWARFContext>(make_unique<LLDDwarfObj<ELFT>>(this));<br>
- for (std::unique_ptr<DWARFUnit> &CU : Dwarf->compile_units()) {<br>
- auto Report = [](Error Err) {<br>
- handleAllErrors(std::move(Err),<br>
- [](ErrorInfoBase &Info) { warn(Info.message()); });<br>
+ dwarf = llvm::make_unique<DWARFContext>(make_unique<LLDDwarfObj<ELFT>>(this));<br>
+ for (std::unique_ptr<DWARFUnit> &cu : dwarf->compile_units()) {<br>
+ auto report = [](Error err) {<br>
+ handleAllErrors(std::move(err),<br>
+ [](ErrorInfoBase &info) { warn(info.message()); });<br>
};<br>
- Expected<const DWARFDebugLine::LineTable *> ExpectedLT =<br>
- Dwarf->getLineTableForUnit(CU.get(), Report);<br>
- const DWARFDebugLine::LineTable *LT = nullptr;<br>
- if (ExpectedLT)<br>
- LT = *ExpectedLT;<br>
+ Expected<const DWARFDebugLine::LineTable *> expectedLT =<br>
+ dwarf->getLineTableForUnit(cu.get(), report);<br>
+ const DWARFDebugLine::LineTable *lt = nullptr;<br>
+ if (expectedLT)<br>
+ lt = *expectedLT;<br>
else<br>
- Report(ExpectedLT.takeError());<br>
- if (!LT)<br>
+ report(expectedLT.takeError());<br>
+ if (!lt)<br>
continue;<br>
- LineTables.push_back(LT);<br>
+ lineTables.push_back(lt);<br>
<br>
// Loop over variable records and insert them to VariableLoc.<br>
- for (const auto &Entry : CU->dies()) {<br>
- DWARFDie Die(CU.get(), &Entry);<br>
+ for (const auto &entry : cu->dies()) {<br>
+ DWARFDie die(cu.get(), &entry);<br>
// Skip all tags that are not variables.<br>
- if (Die.getTag() != dwarf::DW_TAG_variable)<br>
+ if (die.getTag() != dwarf::DW_TAG_variable)<br>
continue;<br>
<br>
// Skip if a local variable because we don't need them for generating<br>
// error messages. In general, only non-local symbols can fail to be<br>
// linked.<br>
- if (!dwarf::toUnsigned(Die.find(dwarf::DW_AT_external), 0))<br>
+ if (!dwarf::toUnsigned(die.find(dwarf::DW_AT_external), 0))<br>
continue;<br>
<br>
// Get the source filename index for the variable.<br>
- unsigned File = dwarf::toUnsigned(Die.find(dwarf::DW_AT_decl_file), 0);<br>
- if (!LT->hasFileAtIndex(File))<br>
+ unsigned file = dwarf::toUnsigned(die.find(dwarf::DW_AT_decl_file), 0);<br>
+ if (!lt->hasFileAtIndex(file))<br>
continue;<br>
<br>
// Get the line number on which the variable is declared.<br>
- unsigned Line = dwarf::toUnsigned(Die.find(dwarf::DW_AT_decl_line), 0);<br>
+ unsigned line = dwarf::toUnsigned(die.find(dwarf::DW_AT_decl_line), 0);<br>
<br>
// Here we want to take the variable name to add it into VariableLoc.<br>
// Variable can have regular and linkage name associated. At first, we try<br>
@@ -296,11 +296,11 @@ template <class ELFT> void ObjFile<ELFT><br>
// two variables in different namespaces of the same object. Use common<br>
// name otherwise, but handle the case when it also absent in case if the<br>
// input object file lacks some debug info.<br>
- StringRef Name =<br>
- dwarf::toString(Die.find(dwarf::DW_AT_linkage_name),<br>
- dwarf::toString(Die.find(dwarf::DW_AT_name), ""));<br>
- if (!Name.empty())<br>
- VariableLoc.insert({Name, {LT, File, Line}});<br>
+ StringRef name =<br>
+ dwarf::toString(die.find(dwarf::DW_AT_linkage_name),<br>
+ dwarf::toString(die.find(dwarf::DW_AT_name), ""));<br>
+ if (!name.empty())<br>
+ variableLoc.insert({name, {lt, file, line}});<br>
}<br>
}<br>
}<br>
@@ -309,71 +309,71 @@ template <class ELFT> void ObjFile<ELFT><br>
// object (variable, array, etc) definition.<br>
template <class ELFT><br>
Optional<std::pair<std::string, unsigned>><br>
-ObjFile<ELFT>::getVariableLoc(StringRef Name) {<br>
- llvm::call_once(InitDwarfLine, [this]() { initializeDwarf(); });<br>
+ObjFile<ELFT>::getVariableLoc(StringRef name) {<br>
+ llvm::call_once(initDwarfLine, [this]() { initializeDwarf(); });<br>
<br>
// Return if we have no debug information about data object.<br>
- auto It = VariableLoc.find(Name);<br>
- if (It == VariableLoc.end())<br>
+ auto it = variableLoc.find(name);<br>
+ if (it == variableLoc.end())<br>
return None;<br>
<br>
// Take file name string from line table.<br>
- std::string FileName;<br>
- if (!It->second.LT->getFileNameByIndex(<br>
- It->second.File, nullptr,<br>
- DILineInfoSpecifier::FileLineInfoKind::AbsoluteFilePath, FileName))<br>
+ std::string fileName;<br>
+ if (!it->second.lt->getFileNameByIndex(<br>
+ it->second.file, nullptr,<br>
+ DILineInfoSpecifier::FileLineInfoKind::AbsoluteFilePath, fileName))<br>
return None;<br>
<br>
- return std::make_pair(FileName, It->second.Line);<br>
+ return std::make_pair(fileName, it->second.line);<br>
}<br>
<br>
// Returns source line information for a given offset<br>
// using DWARF debug info.<br>
template <class ELFT><br>
-Optional<DILineInfo> ObjFile<ELFT>::getDILineInfo(InputSectionBase *S,<br>
- uint64_t Offset) {<br>
- llvm::call_once(InitDwarfLine, [this]() { initializeDwarf(); });<br>
+Optional<DILineInfo> ObjFile<ELFT>::getDILineInfo(InputSectionBase *s,<br>
+ uint64_t offset) {<br>
+ llvm::call_once(initDwarfLine, [this]() { initializeDwarf(); });<br>
<br>
// Detect SectionIndex for specified section.<br>
- uint64_t SectionIndex = object::SectionedAddress::UndefSection;<br>
- ArrayRef<InputSectionBase *> Sections = S->File->getSections();<br>
- for (uint64_t CurIndex = 0; CurIndex < Sections.size(); ++CurIndex) {<br>
- if (S == Sections[CurIndex]) {<br>
- SectionIndex = CurIndex;<br>
+ uint64_t sectionIndex = object::SectionedAddress::UndefSection;<br>
+ ArrayRef<InputSectionBase *> sections = s->file->getSections();<br>
+ for (uint64_t curIndex = 0; curIndex < sections.size(); ++curIndex) {<br>
+ if (s == sections[curIndex]) {<br>
+ sectionIndex = curIndex;<br>
break;<br>
}<br>
}<br>
<br>
// Use fake address calcuated by adding section file offset and offset in<br>
// section. See comments for ObjectInfo class.<br>
- DILineInfo Info;<br>
- for (const llvm::DWARFDebugLine::LineTable *LT : LineTables) {<br>
- if (LT->getFileLineInfoForAddress(<br>
- {S->getOffsetInFile() + Offset, SectionIndex}, nullptr,<br>
- DILineInfoSpecifier::FileLineInfoKind::AbsoluteFilePath, Info))<br>
- return Info;<br>
+ DILineInfo info;<br>
+ for (const llvm::DWARFDebugLine::LineTable *lt : lineTables) {<br>
+ if (lt->getFileLineInfoForAddress(<br>
+ {s->getOffsetInFile() + offset, sectionIndex}, nullptr,<br>
+ DILineInfoSpecifier::FileLineInfoKind::AbsoluteFilePath, info))<br>
+ return info;<br>
}<br>
return None;<br>
}<br>
<br>
// Returns "<internal>", "foo.a(bar.o)" or "baz.o".<br>
-std::string lld::toString(const InputFile *F) {<br>
- if (!F)<br>
+std::string lld::toString(const InputFile *f) {<br>
+ if (!f)<br>
return "<internal>";<br>
<br>
- if (F->ToStringCache.empty()) {<br>
- if (F->ArchiveName.empty())<br>
- F->ToStringCache = F->getName();<br>
+ if (f->toStringCache.empty()) {<br>
+ if (f->archiveName.empty())<br>
+ f->toStringCache = f->getName();<br>
else<br>
- F->ToStringCache = (F->ArchiveName + "(" + F->getName() + ")").str();<br>
+ f->toStringCache = (f->archiveName + "(" + f->getName() + ")").str();<br>
}<br>
- return F->ToStringCache;<br>
+ return f->toStringCache;<br>
}<br>
<br>
-ELFFileBase::ELFFileBase(Kind K, MemoryBufferRef MB) : InputFile(K, MB) {<br>
- EKind = getELFKind(MB, "");<br>
+ELFFileBase::ELFFileBase(Kind k, MemoryBufferRef mb) : InputFile(k, mb) {<br>
+ ekind = getELFKind(mb, "");<br>
<br>
- switch (EKind) {<br>
+ switch (ekind) {<br>
case ELF32LEKind:<br>
init<ELF32LE>();<br>
break;<br>
@@ -392,10 +392,10 @@ ELFFileBase::ELFFileBase(Kind K, MemoryB<br>
}<br>
<br>
template <typename Elf_Shdr><br>
-static const Elf_Shdr *findSection(ArrayRef<Elf_Shdr> Sections, uint32_t Type) {<br>
- for (const Elf_Shdr &Sec : Sections)<br>
- if (Sec.sh_type == Type)<br>
- return &Sec;<br>
+static const Elf_Shdr *findSection(ArrayRef<Elf_Shdr> sections, uint32_t type) {<br>
+ for (const Elf_Shdr &sec : sections)<br>
+ if (sec.sh_type == type)<br>
+ return &sec;<br>
return nullptr;<br>
}<br>
<br>
@@ -404,57 +404,57 @@ template <class ELFT> void ELFFileBase::<br>
using Elf_Sym = typename ELFT::Sym;<br>
<br>
// Initialize trivial attributes.<br>
- const ELFFile<ELFT> &Obj = getObj<ELFT>();<br>
- EMachine = Obj.getHeader()->e_machine;<br>
- OSABI = Obj.getHeader()->e_ident[llvm::ELF::EI_OSABI];<br>
- ABIVersion = Obj.getHeader()->e_ident[llvm::ELF::EI_ABIVERSION];<br>
+ const ELFFile<ELFT> &obj = getObj<ELFT>();<br>
+ emachine = obj.getHeader()->e_machine;<br>
+ osabi = obj.getHeader()->e_ident[llvm::ELF::EI_OSABI];<br>
+ abiVersion = obj.getHeader()->e_ident[llvm::ELF::EI_ABIVERSION];<br>
<br>
- ArrayRef<Elf_Shdr> Sections = CHECK(Obj.sections(), this);<br>
+ ArrayRef<Elf_Shdr> sections = CHECK(obj.sections(), this);<br>
<br>
// Find a symbol table.<br>
- bool IsDSO =<br>
- (identify_magic(MB.getBuffer()) == file_magic::elf_shared_object);<br>
- const Elf_Shdr *SymtabSec =<br>
- findSection(Sections, IsDSO ? SHT_DYNSYM : SHT_SYMTAB);<br>
+ bool isDSO =<br>
+ (identify_magic(mb.getBuffer()) == file_magic::elf_shared_object);<br>
+ const Elf_Shdr *symtabSec =<br>
+ findSection(sections, isDSO ? SHT_DYNSYM : SHT_SYMTAB);<br>
<br>
- if (!SymtabSec)<br>
+ if (!symtabSec)<br>
return;<br>
<br>
// Initialize members corresponding to a symbol table.<br>
- FirstGlobal = SymtabSec->sh_info;<br>
+ firstGlobal = symtabSec->sh_info;<br>
<br>
- ArrayRef<Elf_Sym> ESyms = CHECK(Obj.symbols(SymtabSec), this);<br>
- if (FirstGlobal == 0 || FirstGlobal > ESyms.size())<br>
+ ArrayRef<Elf_Sym> eSyms = CHECK(obj.symbols(symtabSec), this);<br>
+ if (firstGlobal == 0 || firstGlobal > eSyms.size())<br>
fatal(toString(this) + ": invalid sh_info in symbol table");<br>
<br>
- ELFSyms = reinterpret_cast<const void *>(ESyms.data());<br>
- NumELFSyms = ESyms.size();<br>
- StringTable = CHECK(Obj.getStringTableForSymtab(*SymtabSec, Sections), this);<br>
+ elfSyms = reinterpret_cast<const void *>(eSyms.data());<br>
+ numELFSyms = eSyms.size();<br>
+ stringTable = CHECK(obj.getStringTableForSymtab(*symtabSec, sections), this);<br>
}<br>
<br>
template <class ELFT><br>
-uint32_t ObjFile<ELFT>::getSectionIndex(const Elf_Sym &Sym) const {<br>
+uint32_t ObjFile<ELFT>::getSectionIndex(const Elf_Sym &sym) const {<br>
return CHECK(<br>
- this->getObj().getSectionIndex(&Sym, getELFSyms<ELFT>(), ShndxTable),<br>
+ this->getObj().getSectionIndex(&sym, getELFSyms<ELFT>(), shndxTable),<br>
this);<br>
}<br>
<br>
template <class ELFT> ArrayRef<Symbol *> ObjFile<ELFT>::getLocalSymbols() {<br>
- if (this->Symbols.empty())<br>
+ if (this->symbols.empty())<br>
return {};<br>
- return makeArrayRef(this->Symbols).slice(1, this->FirstGlobal - 1);<br>
+ return makeArrayRef(this->symbols).slice(1, this->firstGlobal - 1);<br>
}<br>
<br>
template <class ELFT> ArrayRef<Symbol *> ObjFile<ELFT>::getGlobalSymbols() {<br>
- return makeArrayRef(this->Symbols).slice(this->FirstGlobal);<br>
+ return makeArrayRef(this->symbols).slice(this->firstGlobal);<br>
}<br>
<br>
-template <class ELFT> void ObjFile<ELFT>::parse(bool IgnoreComdats) {<br>
+template <class ELFT> void ObjFile<ELFT>::parse(bool ignoreComdats) {<br>
// Read a section table. JustSymbols is usually false.<br>
- if (this->JustSymbols)<br>
+ if (this->justSymbols)<br>
initializeJustSymbols();<br>
else<br>
- initializeSections(IgnoreComdats);<br>
+ initializeSections(ignoreComdats);<br>
<br>
// Read a symbol table.<br>
initializeSymbols();<br>
@@ -464,11 +464,11 @@ template <class ELFT> void ObjFile<ELFT><br>
// They are identified and deduplicated by group name. This function<br>
// returns a group name.<br>
template <class ELFT><br>
-StringRef ObjFile<ELFT>::getShtGroupSignature(ArrayRef<Elf_Shdr> Sections,<br>
- const Elf_Shdr &Sec) {<br>
- const Elf_Sym *Sym =<br>
- CHECK(object::getSymbol<ELFT>(this->getELFSyms<ELFT>(), Sec.sh_info), this);<br>
- StringRef Signature = CHECK(Sym->getName(this->StringTable), this);<br>
+StringRef ObjFile<ELFT>::getShtGroupSignature(ArrayRef<Elf_Shdr> sections,<br>
+ const Elf_Shdr &sec) {<br>
+ const Elf_Sym *sym =<br>
+ CHECK(object::getSymbol<ELFT>(this->getELFSyms<ELFT>(), sec.sh_info), this);<br>
+ StringRef signature = CHECK(sym->getName(this->stringTable), this);<br>
<br>
// As a special case, if a symbol is a section symbol and has no name,<br>
// we use a section name as a signature.<br>
@@ -477,12 +477,12 @@ StringRef ObjFile<ELFT>::getShtGroupSign<br>
// standard, but GNU gold 1.14 (the newest version as of July 2017) or<br>
// older produce such sections as outputs for the -r option, so we need<br>
// a bug-compatibility.<br>
- if (Signature.empty() && Sym->getType() == STT_SECTION)<br>
- return getSectionName(Sec);<br>
- return Signature;<br>
+ if (signature.empty() && sym->getType() == STT_SECTION)<br>
+ return getSectionName(sec);<br>
+ return signature;<br>
}<br>
<br>
-template <class ELFT> bool ObjFile<ELFT>::shouldMerge(const Elf_Shdr &Sec) {<br>
+template <class ELFT> bool ObjFile<ELFT>::shouldMerge(const Elf_Shdr &sec) {<br>
// On a regular link we don't merge sections if -O0 (default is -O1). This<br>
// sometimes makes the linker significantly faster, although the output will<br>
// be bigger.<br>
@@ -495,14 +495,14 @@ template <class ELFT> bool ObjFile<ELFT><br>
// SHF_MERGE sections based both on their name and sh_entsize, but that seems<br>
// to be more trouble than it is worth. Instead, we just use the regular (-O1)<br>
// logic for -r.<br>
- if (Config->Optimize == 0 && !Config->Relocatable)<br>
+ if (config->optimize == 0 && !config->relocatable)<br>
return false;<br>
<br>
// A mergeable section with size 0 is useless because they don't have<br>
// any data to merge. A mergeable string section with size 0 can be<br>
// argued as invalid because it doesn't end with a null character.<br>
// We'll avoid a mess by handling them as if they were non-mergeable.<br>
- if (Sec.sh_size == 0)<br>
+ if (sec.sh_size == 0)<br>
return false;<br>
<br>
// Check for sh_entsize. The ELF spec is not clear about the zero<br>
@@ -510,17 +510,17 @@ template <class ELFT> bool ObjFile<ELFT><br>
// the section does not hold a table of fixed-size entries". We know<br>
// that Rust 1.13 produces a string mergeable section with a zero<br>
// sh_entsize. Here we just accept it rather than being picky about it.<br>
- uint64_t EntSize = Sec.sh_entsize;<br>
- if (EntSize == 0)<br>
+ uint64_t entSize = sec.sh_entsize;<br>
+ if (entSize == 0)<br>
return false;<br>
- if (Sec.sh_size % EntSize)<br>
+ if (sec.sh_size % entSize)<br>
fatal(toString(this) +<br>
": SHF_MERGE section size must be a multiple of sh_entsize");<br>
<br>
- uint64_t Flags = Sec.sh_flags;<br>
- if (!(Flags & SHF_MERGE))<br>
+ uint64_t flags = sec.sh_flags;<br>
+ if (!(flags & SHF_MERGE))<br>
return false;<br>
- if (Flags & SHF_WRITE)<br>
+ if (flags & SHF_WRITE)<br>
fatal(toString(this) + ": writable SHF_MERGE section is not supported");<br>
<br>
return true;<br>
@@ -536,8 +536,8 @@ template <class ELFT> bool ObjFile<ELFT><br>
// When the option is given, we link "just symbols". The section table is<br>
// initialized with null pointers.<br>
template <class ELFT> void ObjFile<ELFT>::initializeJustSymbols() {<br>
- ArrayRef<Elf_Shdr> Sections = CHECK(this->getObj().sections(), this);<br>
- this->Sections.resize(Sections.size());<br>
+ ArrayRef<Elf_Shdr> sections = CHECK(this->getObj().sections(), this);<br>
+ this->sections.resize(sections.size());<br>
}<br>
<br>
// An ELF object file may contain a `.deplibs` section. If it exists, the<br>
@@ -546,128 +546,128 @@ template <class ELFT> void ObjFile<ELFT><br>
// the various ways that a library can be specified to LLD. This ELF extension<br>
// is a form of autolinking and is called `dependent libraries`. It is currently<br>
// unique to LLVM and lld.<br>
-static void addDependentLibrary(StringRef Specifier, const InputFile *F) {<br>
- if (!Config->DependentLibraries)<br>
+static void addDependentLibrary(StringRef specifier, const InputFile *f) {<br>
+ if (!config->dependentLibraries)<br>
return;<br>
- if (fs::exists(Specifier))<br>
- Driver->addFile(Specifier, /*WithLOption=*/false);<br>
- else if (Optional<std::string> S = findFromSearchPaths(Specifier))<br>
- Driver->addFile(*S, /*WithLOption=*/true);<br>
- else if (Optional<std::string> S = searchLibraryBaseName(Specifier))<br>
- Driver->addFile(*S, /*WithLOption=*/true);<br>
+ if (fs::exists(specifier))<br>
+ driver->addFile(specifier, /*WithLOption=*/false);<br>
+ else if (Optional<std::string> s = findFromSearchPaths(specifier))<br>
+ driver->addFile(*s, /*WithLOption=*/true);<br>
+ else if (Optional<std::string> s = searchLibraryBaseName(specifier))<br>
+ driver->addFile(*s, /*WithLOption=*/true);<br>
else<br>
- error(toString(F) +<br>
+ error(toString(f) +<br>
": unable to find library from dependent library specifier: " +<br>
- Specifier);<br>
+ specifier);<br>
}<br>
<br>
template <class ELFT><br>
-void ObjFile<ELFT>::initializeSections(bool IgnoreComdats) {<br>
- const ELFFile<ELFT> &Obj = this->getObj();<br>
+void ObjFile<ELFT>::initializeSections(bool ignoreComdats) {<br>
+ const ELFFile<ELFT> &obj = this->getObj();<br>
<br>
- ArrayRef<Elf_Shdr> ObjSections = CHECK(Obj.sections(), this);<br>
- uint64_t Size = ObjSections.size();<br>
- this->Sections.resize(Size);<br>
- this->SectionStringTable =<br>
- CHECK(Obj.getSectionStringTable(ObjSections), this);<br>
+ ArrayRef<Elf_Shdr> objSections = CHECK(obj.sections(), this);<br>
+ uint64_t size = objSections.size();<br>
+ this->sections.resize(size);<br>
+ this->sectionStringTable =<br>
+ CHECK(obj.getSectionStringTable(objSections), this);<br>
<br>
- for (size_t I = 0, E = ObjSections.size(); I < E; I++) {<br>
- if (this->Sections[I] == &InputSection::Discarded)<br>
+ for (size_t i = 0, e = objSections.size(); i < e; i++) {<br>
+ if (this->sections[i] == &InputSection::discarded)<br>
continue;<br>
- const Elf_Shdr &Sec = ObjSections[I];<br>
+ const Elf_Shdr &sec = objSections[i];<br>
<br>
- if (Sec.sh_type == ELF::SHT_LLVM_CALL_GRAPH_PROFILE)<br>
- CGProfile =<br>
- check(Obj.template getSectionContentsAsArray<Elf_CGProfile>(&Sec));<br>
+ if (sec.sh_type == ELF::SHT_LLVM_CALL_GRAPH_PROFILE)<br>
+ cgProfile =<br>
+ check(obj.template getSectionContentsAsArray<Elf_CGProfile>(&sec));<br>
<br>
// SHF_EXCLUDE'ed sections are discarded by the linker. However,<br>
// if -r is given, we'll let the final link discard such sections.<br>
// This is compatible with GNU.<br>
- if ((Sec.sh_flags & SHF_EXCLUDE) && !Config->Relocatable) {<br>
- if (Sec.sh_type == SHT_LLVM_ADDRSIG) {<br>
+ if ((sec.sh_flags & SHF_EXCLUDE) && !config->relocatable) {<br>
+ if (sec.sh_type == SHT_LLVM_ADDRSIG) {<br>
// We ignore the address-significance table if we know that the object<br>
// file was created by objcopy or ld -r. This is because these tools<br>
// will reorder the symbols in the symbol table, invalidating the data<br>
// in the address-significance table, which refers to symbols by index.<br>
- if (Sec.sh_link != 0)<br>
- this->AddrsigSec = &Sec;<br>
- else if (Config->ICF == ICFLevel::Safe)<br>
+ if (sec.sh_link != 0)<br>
+ this->addrsigSec = &sec;<br>
+ else if (config->icf == ICFLevel::Safe)<br>
warn(toString(this) + ": --icf=safe is incompatible with object "<br>
"files created using objcopy or ld -r");<br>
}<br>
- this->Sections[I] = &InputSection::Discarded;<br>
+ this->sections[i] = &InputSection::discarded;<br>
continue;<br>
}<br>
<br>
- switch (Sec.sh_type) {<br>
+ switch (sec.sh_type) {<br>
case SHT_GROUP: {<br>
// De-duplicate section groups by their signatures.<br>
- StringRef Signature = getShtGroupSignature(ObjSections, Sec);<br>
- this->Sections[I] = &InputSection::Discarded;<br>
+ StringRef signature = getShtGroupSignature(objSections, sec);<br>
+ this->sections[i] = &InputSection::discarded;<br>
<br>
<br>
- ArrayRef<Elf_Word> Entries =<br>
- CHECK(Obj.template getSectionContentsAsArray<Elf_Word>(&Sec), this);<br>
- if (Entries.empty())<br>
+ ArrayRef<Elf_Word> entries =<br>
+ CHECK(obj.template getSectionContentsAsArray<Elf_Word>(&sec), this);<br>
+ if (entries.empty())<br>
fatal(toString(this) + ": empty SHT_GROUP");<br>
<br>
// The first word of a SHT_GROUP section contains flags. Currently,<br>
// the standard defines only "GRP_COMDAT" flag for the COMDAT group.<br>
// An group with the empty flag doesn't define anything; such sections<br>
// are just skipped.<br>
- if (Entries[0] == 0)<br>
+ if (entries[0] == 0)<br>
continue;<br>
<br>
- if (Entries[0] != GRP_COMDAT)<br>
+ if (entries[0] != GRP_COMDAT)<br>
fatal(toString(this) + ": unsupported SHT_GROUP format");<br>
<br>
- bool IsNew =<br>
- IgnoreComdats ||<br>
- Symtab->ComdatGroups.try_emplace(CachedHashStringRef(Signature), this)<br>
+ bool isNew =<br>
+ ignoreComdats ||<br>
+ symtab->comdatGroups.try_emplace(CachedHashStringRef(signature), this)<br>
.second;<br>
- if (IsNew) {<br>
- if (Config->Relocatable)<br>
- this->Sections[I] = createInputSection(Sec);<br>
+ if (isNew) {<br>
+ if (config->relocatable)<br>
+ this->sections[i] = createInputSection(sec);<br>
continue;<br>
}<br>
<br>
// Otherwise, discard group members.<br>
- for (uint32_t SecIndex : Entries.slice(1)) {<br>
- if (SecIndex >= Size)<br>
+ for (uint32_t secIndex : entries.slice(1)) {<br>
+ if (secIndex >= size)<br>
fatal(toString(this) +<br>
- ": invalid section index in group: " + Twine(SecIndex));<br>
- this->Sections[SecIndex] = &InputSection::Discarded;<br>
+ ": invalid section index in group: " + Twine(secIndex));<br>
+ this->sections[secIndex] = &InputSection::discarded;<br>
}<br>
break;<br>
}<br>
case SHT_SYMTAB_SHNDX:<br>
- ShndxTable = CHECK(Obj.getSHNDXTable(Sec, ObjSections), this);<br>
+ shndxTable = CHECK(obj.getSHNDXTable(sec, objSections), this);<br>
break;<br>
case SHT_SYMTAB:<br>
case SHT_STRTAB:<br>
case SHT_NULL:<br>
break;<br>
default:<br>
- this->Sections[I] = createInputSection(Sec);<br>
+ this->sections[i] = createInputSection(sec);<br>
}<br>
<br>
// .ARM.exidx sections have a reverse dependency on the InputSection they<br>
// have a SHF_LINK_ORDER dependency, this is identified by the sh_link.<br>
- if (Sec.sh_flags & SHF_LINK_ORDER) {<br>
- InputSectionBase *LinkSec = nullptr;<br>
- if (Sec.sh_link < this->Sections.size())<br>
- LinkSec = this->Sections[Sec.sh_link];<br>
- if (!LinkSec)<br>
+ if (sec.sh_flags & SHF_LINK_ORDER) {<br>
+ InputSectionBase *linkSec = nullptr;<br>
+ if (sec.sh_link < this->sections.size())<br>
+ linkSec = this->sections[sec.sh_link];<br>
+ if (!linkSec)<br>
fatal(toString(this) +<br>
- ": invalid sh_link index: " + Twine(Sec.sh_link));<br>
+ ": invalid sh_link index: " + Twine(sec.sh_link));<br>
<br>
- InputSection *IS = cast<InputSection>(this->Sections[I]);<br>
- LinkSec->DependentSections.push_back(IS);<br>
- if (!isa<InputSection>(LinkSec))<br>
- error("a section " + IS->Name +<br>
+ InputSection *isec = cast<InputSection>(this->sections[i]);<br>
+ linkSec->dependentSections.push_back(isec);<br>
+ if (!isa<InputSection>(linkSec))<br>
+ error("a section " + isec->name +<br>
" with SHF_LINK_ORDER should not refer a non-regular "<br>
"section: " +<br>
- toString(LinkSec));<br>
+ toString(linkSec));<br>
}<br>
}<br>
}<br>
@@ -675,9 +675,9 @@ void ObjFile<ELFT>::initializeSections(b<br>
// For ARM only, to set the EF_ARM_ABI_FLOAT_SOFT or EF_ARM_ABI_FLOAT_HARD<br>
// flag in the ELF Header we need to look at Tag_ABI_VFP_args to find out how<br>
// the input objects have been compiled.<br>
-static void updateARMVFPArgs(const ARMAttributeParser &Attributes,<br>
- const InputFile *F) {<br>
- if (!Attributes.hasAttribute(ARMBuildAttrs::ABI_VFP_args))<br>
+static void updateARMVFPArgs(const ARMAttributeParser &attributes,<br>
+ const InputFile *f) {<br>
+ if (!attributes.hasAttribute(ARMBuildAttrs::ABI_VFP_args))<br>
// If an ABI tag isn't present then it is implicitly given the value of 0<br>
// which maps to ARMBuildAttrs::BaseAAPCS. However many assembler files,<br>
// including some in glibc that don't use FP args (and should have value 3)<br>
@@ -685,31 +685,31 @@ static void updateARMVFPArgs(const ARMAt<br>
// as a clash.<br>
return;<br>
<br>
- unsigned VFPArgs = Attributes.getAttributeValue(ARMBuildAttrs::ABI_VFP_args);<br>
- ARMVFPArgKind Arg;<br>
- switch (VFPArgs) {<br>
+ unsigned vfpArgs = attributes.getAttributeValue(ARMBuildAttrs::ABI_VFP_args);<br>
+ ARMVFPArgKind arg;<br>
+ switch (vfpArgs) {<br>
case ARMBuildAttrs::BaseAAPCS:<br>
- Arg = ARMVFPArgKind::Base;<br>
+ arg = ARMVFPArgKind::Base;<br>
break;<br>
case ARMBuildAttrs::HardFPAAPCS:<br>
- Arg = ARMVFPArgKind::VFP;<br>
+ arg = ARMVFPArgKind::VFP;<br>
break;<br>
case ARMBuildAttrs::ToolChainFPPCS:<br>
// Tool chain specific convention that conforms to neither AAPCS variant.<br>
- Arg = ARMVFPArgKind::ToolChain;<br>
+ arg = ARMVFPArgKind::ToolChain;<br>
break;<br>
case ARMBuildAttrs::CompatibleFPAAPCS:<br>
// Object compatible with all conventions.<br>
return;<br>
default:<br>
- error(toString(F) + ": unknown Tag_ABI_VFP_args value: " + Twine(VFPArgs));<br>
+ error(toString(f) + ": unknown Tag_ABI_VFP_args value: " + Twine(vfpArgs));<br>
return;<br>
}<br>
// Follow ld.bfd and error if there is a mix of calling conventions.<br>
- if (Config->ARMVFPArgs != Arg && Config->ARMVFPArgs != ARMVFPArgKind::Default)<br>
- error(toString(F) + ": incompatible Tag_ABI_VFP_args");<br>
+ if (config->armVFPArgs != arg && config->armVFPArgs != ARMVFPArgKind::Default)<br>
+ error(toString(f) + ": incompatible Tag_ABI_VFP_args");<br>
else<br>
- Config->ARMVFPArgs = Arg;<br>
+ config->armVFPArgs = arg;<br>
}<br>
<br>
// The ARM support in lld makes some use of instructions that are not available<br>
@@ -721,11 +721,11 @@ static void updateARMVFPArgs(const ARMAt<br>
// at compile time. We follow the convention that if at least one input object<br>
// is compiled with an architecture that supports these features then lld is<br>
// permitted to use them.<br>
-static void updateSupportedARMFeatures(const ARMAttributeParser &Attributes) {<br>
- if (!Attributes.hasAttribute(ARMBuildAttrs::CPU_arch))<br>
+static void updateSupportedARMFeatures(const ARMAttributeParser &attributes) {<br>
+ if (!attributes.hasAttribute(ARMBuildAttrs::CPU_arch))<br>
return;<br>
- auto Arch = Attributes.getAttributeValue(ARMBuildAttrs::CPU_arch);<br>
- switch (Arch) {<br>
+ auto arch = attributes.getAttributeValue(ARMBuildAttrs::CPU_arch);<br>
+ switch (arch) {<br>
case ARMBuildAttrs::Pre_v4:<br>
case ARMBuildAttrs::v4:<br>
case ARMBuildAttrs::v4T:<br>
@@ -737,19 +737,19 @@ static void updateSupportedARMFeatures(c<br>
case ARMBuildAttrs::v6:<br>
case ARMBuildAttrs::v6KZ:<br>
case ARMBuildAttrs::v6K:<br>
- Config->ARMHasBlx = true;<br>
+ config->armHasBlx = true;<br>
// Architectures used in pre-Cortex processors do not support<br>
// The J1 = 1 J2 = 1 Thumb branch range extension, with the exception<br>
// of Architecture v6T2 (arm1156t2-s and arm1156t2f-s) that do.<br>
break;<br>
default:<br>
// All other Architectures have BLX and extended branch encoding<br>
- Config->ARMHasBlx = true;<br>
- Config->ARMJ1J2BranchEncoding = true;<br>
- if (Arch != ARMBuildAttrs::v6_M && Arch != ARMBuildAttrs::v6S_M)<br>
+ config->armHasBlx = true;<br>
+ config->armJ1J2BranchEncoding = true;<br>
+ if (arch != ARMBuildAttrs::v6_M && arch != ARMBuildAttrs::v6S_M)<br>
// All Architectures used in Cortex processors with the exception<br>
// of v6-M and v6S-M have the MOVT and MOVW instructions.<br>
- Config->ARMHasMovtMovw = true;<br>
+ config->armHasMovtMovw = true;<br>
break;<br>
}<br>
}<br>
@@ -767,126 +767,126 @@ static void updateSupportedARMFeatures(c<br>
// certain type. It seems a bit too much to just store a 32-bit value, perhaps<br>
// the ABI is unnecessarily complicated.<br>
template <class ELFT><br>
-static uint32_t readAndFeatures(ObjFile<ELFT> *Obj, ArrayRef<uint8_t> Data) {<br>
+static uint32_t readAndFeatures(ObjFile<ELFT> *obj, ArrayRef<uint8_t> data) {<br>
using Elf_Nhdr = typename ELFT::Nhdr;<br>
using Elf_Note = typename ELFT::Note;<br>
<br>
- uint32_t FeaturesSet = 0;<br>
- while (!Data.empty()) {<br>
+ uint32_t featuresSet = 0;<br>
+ while (!data.empty()) {<br>
// Read one NOTE record.<br>
- if (Data.size() < sizeof(Elf_Nhdr))<br>
- fatal(toString(Obj) + ": .note.gnu.property: section too short");<br>
+ if (data.size() < sizeof(Elf_Nhdr))<br>
+ fatal(toString(obj) + ": .note.gnu.property: section too short");<br>
<br>
- auto *Nhdr = reinterpret_cast<const Elf_Nhdr *>(Data.data());<br>
- if (Data.size() < Nhdr->getSize())<br>
- fatal(toString(Obj) + ": .note.gnu.property: section too short");<br>
-<br>
- Elf_Note Note(*Nhdr);<br>
- if (Nhdr->n_type != NT_GNU_PROPERTY_TYPE_0 || Note.getName() != "GNU") {<br>
- Data = Data.slice(Nhdr->getSize());<br>
+ auto *nhdr = reinterpret_cast<const Elf_Nhdr *>(data.data());<br>
+ if (data.size() < nhdr->getSize())<br>
+ fatal(toString(obj) + ": .note.gnu.property: section too short");<br>
+<br>
+ Elf_Note note(*nhdr);<br>
+ if (nhdr->n_type != NT_GNU_PROPERTY_TYPE_0 || note.getName() != "GNU") {<br>
+ data = data.slice(nhdr->getSize());<br>
continue;<br>
}<br>
<br>
- uint32_t FeatureAndType = Config->EMachine == EM_AARCH64<br>
+ uint32_t featureAndType = config->emachine == EM_AARCH64<br>
? GNU_PROPERTY_AARCH64_FEATURE_1_AND<br>
: GNU_PROPERTY_X86_FEATURE_1_AND;<br>
<br>
// Read a body of a NOTE record, which consists of type-length-value fields.<br>
- ArrayRef<uint8_t> Desc = Note.getDesc();<br>
- while (!Desc.empty()) {<br>
- if (Desc.size() < 8)<br>
- fatal(toString(Obj) + ": .note.gnu.property: section too short");<br>
+ ArrayRef<uint8_t> desc = note.getDesc();<br>
+ while (!desc.empty()) {<br>
+ if (desc.size() < 8)<br>
+ fatal(toString(obj) + ": .note.gnu.property: section too short");<br>
<br>
- uint32_t Type = read32le(Desc.data());<br>
- uint32_t Size = read32le(Desc.data() + 4);<br>
+ uint32_t type = read32le(desc.data());<br>
+ uint32_t size = read32le(desc.data() + 4);<br>
<br>
- if (Type == FeatureAndType) {<br>
+ if (type == featureAndType) {<br>
// We found a FEATURE_1_AND field. There may be more than one of these<br>
// in a .note.gnu.propery section, for a relocatable object we<br>
// accumulate the bits set.<br>
- FeaturesSet |= read32le(Desc.data() + 8);<br>
+ featuresSet |= read32le(desc.data() + 8);<br>
}<br>
<br>
// On 64-bit, a payload may be followed by a 4-byte padding to make its<br>
// size a multiple of 8.<br>
if (ELFT::Is64Bits)<br>
- Size = alignTo(Size, 8);<br>
+ size = alignTo(size, 8);<br>
<br>
- Desc = Desc.slice(Size + 8); // +8 for Type and Size<br>
+ desc = desc.slice(size + 8); // +8 for Type and Size<br>
}<br>
<br>
// Go to next NOTE record to look for more FEATURE_1_AND descriptions.<br>
- Data = Data.slice(Nhdr->getSize());<br>
+ data = data.slice(nhdr->getSize());<br>
}<br>
<br>
- return FeaturesSet;<br>
+ return featuresSet;<br>
}<br>
<br>
template <class ELFT><br>
-InputSectionBase *ObjFile<ELFT>::getRelocTarget(const Elf_Shdr &Sec) {<br>
- uint32_t Idx = Sec.sh_info;<br>
- if (Idx >= this->Sections.size())<br>
- fatal(toString(this) + ": invalid relocated section index: " + Twine(Idx));<br>
- InputSectionBase *Target = this->Sections[Idx];<br>
+InputSectionBase *ObjFile<ELFT>::getRelocTarget(const Elf_Shdr &sec) {<br>
+ uint32_t idx = sec.sh_info;<br>
+ if (idx >= this->sections.size())<br>
+ fatal(toString(this) + ": invalid relocated section index: " + Twine(idx));<br>
+ InputSectionBase *target = this->sections[idx];<br>
<br>
// Strictly speaking, a relocation section must be included in the<br>
// group of the section it relocates. However, LLVM 3.3 and earlier<br>
// would fail to do so, so we gracefully handle that case.<br>
- if (Target == &InputSection::Discarded)<br>
+ if (target == &InputSection::discarded)<br>
return nullptr;<br>
<br>
- if (!Target)<br>
+ if (!target)<br>
fatal(toString(this) + ": unsupported relocation reference");<br>
- return Target;<br>
+ return target;<br>
}<br>
<br>
// Create a regular InputSection class that has the same contents<br>
// as a given section.<br>
-static InputSection *toRegularSection(MergeInputSection *Sec) {<br>
- return make<InputSection>(Sec->File, Sec->Flags, Sec->Type, Sec->Alignment,<br>
- Sec->data(), Sec->Name);<br>
+static InputSection *toRegularSection(MergeInputSection *sec) {<br>
+ return make<InputSection>(sec->file, sec->flags, sec->type, sec->alignment,<br>
+ sec->data(), sec->name);<br>
}<br>
<br>
template <class ELFT><br>
-InputSectionBase *ObjFile<ELFT>::createInputSection(const Elf_Shdr &Sec) {<br>
- StringRef Name = getSectionName(Sec);<br>
+InputSectionBase *ObjFile<ELFT>::createInputSection(const Elf_Shdr &sec) {<br>
+ StringRef name = getSectionName(sec);<br>
<br>
- switch (Sec.sh_type) {<br>
+ switch (sec.sh_type) {<br>
case SHT_ARM_ATTRIBUTES: {<br>
- if (Config->EMachine != EM_ARM)<br>
+ if (config->emachine != EM_ARM)<br>
break;<br>
- ARMAttributeParser Attributes;<br>
- ArrayRef<uint8_t> Contents = check(this->getObj().getSectionContents(&Sec));<br>
- Attributes.Parse(Contents, /*isLittle*/ Config->EKind == ELF32LEKind);<br>
- updateSupportedARMFeatures(Attributes);<br>
- updateARMVFPArgs(Attributes, this);<br>
+ ARMAttributeParser attributes;<br>
+ ArrayRef<uint8_t> contents = check(this->getObj().getSectionContents(&sec));<br>
+ attributes.Parse(contents, /*isLittle*/ config->ekind == ELF32LEKind);<br>
+ updateSupportedARMFeatures(attributes);<br>
+ updateARMVFPArgs(attributes, this);<br>
<br>
// FIXME: Retain the first attribute section we see. The eglibc ARM<br>
// dynamic loaders require the presence of an attribute section for dlopen<br>
// to work. In a full implementation we would merge all attribute sections.<br>
- if (In.ARMAttributes == nullptr) {<br>
- In.ARMAttributes = make<InputSection>(*this, Sec, Name);<br>
- return In.ARMAttributes;<br>
+ if (in.armAttributes == nullptr) {<br>
+ in.armAttributes = make<InputSection>(*this, sec, name);<br>
+ return in.armAttributes;<br>
}<br>
- return &InputSection::Discarded;<br>
+ return &InputSection::discarded;<br>
}<br>
case SHT_LLVM_DEPENDENT_LIBRARIES: {<br>
- if (Config->Relocatable)<br>
+ if (config->relocatable)<br>
break;<br>
- ArrayRef<char> Data =<br>
- CHECK(this->getObj().template getSectionContentsAsArray<char>(&Sec), this);<br>
- if (!Data.empty() && Data.back() != '\0') {<br>
+ ArrayRef<char> data =<br>
+ CHECK(this->getObj().template getSectionContentsAsArray<char>(&sec), this);<br>
+ if (!data.empty() && data.back() != '\0') {<br>
error(toString(this) +<br>
": corrupted dependent libraries section (unterminated string): " +<br>
- Name);<br>
- return &InputSection::Discarded;<br>
+ name);<br>
+ return &InputSection::discarded;<br>
}<br>
- for (const char *D = Data.begin(), *E = Data.end(); D < E;) {<br>
- StringRef S(D);<br>
- addDependentLibrary(S, this);<br>
- D += S.size() + 1;<br>
+ for (const char *d = data.begin(), *e = data.end(); d < e;) {<br>
+ StringRef s(d);<br>
+ addDependentLibrary(s, this);<br>
+ d += s.size() + 1;<br>
}<br>
- return &InputSection::Discarded;<br>
+ return &InputSection::discarded;<br>
}<br>
case SHT_RELA:<br>
case SHT_REL: {<br>
@@ -895,25 +895,25 @@ InputSectionBase *ObjFile<ELFT>::createI<br>
// and the group is discarded, even though it's a violation of the<br>
// spec. We handle that situation gracefully by discarding dangling<br>
// relocation sections.<br>
- InputSectionBase *Target = getRelocTarget(Sec);<br>
- if (!Target)<br>
+ InputSectionBase *target = getRelocTarget(sec);<br>
+ if (!target)<br>
return nullptr;<br>
<br>
// This section contains relocation information.<br>
// If -r is given, we do not interpret or apply relocation<br>
// but just copy relocation sections to output.<br>
- if (Config->Relocatable) {<br>
- InputSection *RelocSec = make<InputSection>(*this, Sec, Name);<br>
+ if (config->relocatable) {<br>
+ InputSection *relocSec = make<InputSection>(*this, sec, name);<br>
// We want to add a dependency to target, similar like we do for<br>
// -emit-relocs below. This is useful for the case when linker script<br>
// contains the "/DISCARD/". It is perhaps uncommon to use a script with<br>
// -r, but we faced it in the Linux kernel and have to handle such case<br>
// and not to crash.<br>
- Target->DependentSections.push_back(RelocSec);<br>
- return RelocSec;<br>
+ target->dependentSections.push_back(relocSec);<br>
+ return relocSec;<br>
}<br>
<br>
- if (Target->FirstRelocation)<br>
+ if (target->firstRelocation)<br>
fatal(toString(this) +<br>
": multiple relocation sections to one section are not supported");<br>
<br>
@@ -922,33 +922,33 @@ InputSectionBase *ObjFile<ELFT>::createI<br>
// because applying relocations at end of linking changes section<br>
// contents. So, we simply handle such sections as non-mergeable ones.<br>
// Degrading like this is acceptable because section merging is optional.<br>
- if (auto *MS = dyn_cast<MergeInputSection>(Target)) {<br>
- Target = toRegularSection(MS);<br>
- this->Sections[Sec.sh_info] = Target;<br>
+ if (auto *ms = dyn_cast<MergeInputSection>(target)) {<br>
+ target = toRegularSection(ms);<br>
+ this->sections[sec.sh_info] = target;<br>
}<br>
<br>
- if (Sec.sh_type == SHT_RELA) {<br>
- ArrayRef<Elf_Rela> Rels = CHECK(getObj().relas(&Sec), this);<br>
- Target->FirstRelocation = Rels.begin();<br>
- Target->NumRelocations = Rels.size();<br>
- Target->AreRelocsRela = true;<br>
+ if (sec.sh_type == SHT_RELA) {<br>
+ ArrayRef<Elf_Rela> rels = CHECK(getObj().relas(&sec), this);<br>
+ target->firstRelocation = rels.begin();<br>
+ target->numRelocations = rels.size();<br>
+ target->areRelocsRela = true;<br>
} else {<br>
- ArrayRef<Elf_Rel> Rels = CHECK(getObj().rels(&Sec), this);<br>
- Target->FirstRelocation = Rels.begin();<br>
- Target->NumRelocations = Rels.size();<br>
- Target->AreRelocsRela = false;<br>
+ ArrayRef<Elf_Rel> rels = CHECK(getObj().rels(&sec), this);<br>
+ target->firstRelocation = rels.begin();<br>
+ target->numRelocations = rels.size();<br>
+ target->areRelocsRela = false;<br>
}<br>
- assert(isUInt<31>(Target->NumRelocations));<br>
+ assert(isUInt<31>(target->numRelocations));<br>
<br>
// Relocation sections processed by the linker are usually removed<br>
// from the output, so returning `nullptr` for the normal case.<br>
// However, if -emit-relocs is given, we need to leave them in the output.<br>
// (Some post link analysis tools need this information.)<br>
- if (Config->EmitRelocs) {<br>
- InputSection *RelocSec = make<InputSection>(*this, Sec, Name);<br>
+ if (config->emitRelocs) {<br>
+ InputSection *relocSec = make<InputSection>(*this, sec, name);<br>
// We will not emit relocation section if target was discarded.<br>
- Target->DependentSections.push_back(RelocSec);<br>
- return RelocSec;<br>
+ target->dependentSections.push_back(relocSec);<br>
+ return relocSec;<br>
}<br>
return nullptr;<br>
}<br>
@@ -967,8 +967,8 @@ InputSectionBase *ObjFile<ELFT>::createI<br>
// explicitly told to do otherwise (by -z execstack). Because the stack<br>
// executable-ness is controlled solely by command line options,<br>
// .note.GNU-stack sections are simply ignored.<br>
- if (Name == ".note.GNU-stack")<br>
- return &InputSection::Discarded;<br>
+ if (name == ".note.GNU-stack")<br>
+ return &InputSection::discarded;<br>
<br>
// Object files that use processor features such as Intel Control-Flow<br>
// Enforcement (CET) or AArch64 Branch Target Identification BTI, use a<br>
@@ -978,31 +978,31 @@ InputSectionBase *ObjFile<ELFT>::createI<br>
// Since we merge bitmaps from multiple object files to create a new<br>
// .note.gnu.property containing a single AND'ed bitmap, we discard an input<br>
// file's .note.gnu.property section.<br>
- if (Name == ".note.gnu.property") {<br>
- ArrayRef<uint8_t> Contents = check(this->getObj().getSectionContents(&Sec));<br>
- this->AndFeatures = readAndFeatures(this, Contents);<br>
- return &InputSection::Discarded;<br>
+ if (name == ".note.gnu.property") {<br>
+ ArrayRef<uint8_t> contents = check(this->getObj().getSectionContents(&sec));<br>
+ this->andFeatures = readAndFeatures(this, contents);<br>
+ return &InputSection::discarded;<br>
}<br>
<br>
// Split stacks is a feature to support a discontiguous stack,<br>
// commonly used in the programming language Go. For the details,<br>
// see <a href="https://gcc.gnu.org/wiki/SplitStacks" rel="noreferrer" target="_blank">https://gcc.gnu.org/wiki/SplitStacks</a>. An object file compiled<br>
// for split stack will include a .note.GNU-split-stack section.<br>
- if (Name == ".note.GNU-split-stack") {<br>
- if (Config->Relocatable) {<br>
+ if (name == ".note.GNU-split-stack") {<br>
+ if (config->relocatable) {<br>
error("cannot mix split-stack and non-split-stack in a relocatable link");<br>
- return &InputSection::Discarded;<br>
+ return &InputSection::discarded;<br>
}<br>
- this->SplitStack = true;<br>
- return &InputSection::Discarded;<br>
+ this->splitStack = true;<br>
+ return &InputSection::discarded;<br>
}<br>
<br>
// An object file cmpiled for split stack, but where some of the<br>
// functions were compiled with the no_split_stack_attribute will<br>
// include a .note.GNU-no-split-stack section.<br>
- if (Name == ".note.GNU-no-split-stack") {<br>
- this->SomeNoSplitStack = true;<br>
- return &InputSection::Discarded;<br>
+ if (name == ".note.GNU-no-split-stack") {<br>
+ this->someNoSplitStack = true;<br>
+ return &InputSection::discarded;<br>
}<br>
<br>
// The linkonce feature is a sort of proto-comdat. Some glibc i386 object<br>
@@ -1010,98 +1010,98 @@ InputSectionBase *ObjFile<ELFT>::createI<br>
// sections. Drop those sections to avoid duplicate symbol errors.<br>
// FIXME: This is glibc PR20543, we should remove this hack once that has been<br>
// fixed for a while.<br>
- if (Name == ".gnu.linkonce.t.__x86.get_pc_thunk.bx" ||<br>
- Name == ".gnu.linkonce.t.__i686.get_pc_thunk.bx")<br>
- return &InputSection::Discarded;<br>
+ if (name == ".gnu.linkonce.t.__x86.get_pc_thunk.bx" ||<br>
+ name == ".gnu.linkonce.t.__i686.get_pc_thunk.bx")<br>
+ return &InputSection::discarded;<br>
<br>
// If we are creating a new .build-id section, strip existing .build-id<br>
// sections so that the output won't have more than one .build-id.<br>
// This is not usually a problem because input object files normally don't<br>
// have .build-id sections, but you can create such files by<br>
// "ld.{bfd,gold,lld} -r --build-id", and we want to guard against it.<br>
- if (Name == ".note.gnu.build-id" && Config->BuildId != BuildIdKind::None)<br>
- return &InputSection::Discarded;<br>
+ if (name == ".note.gnu.build-id" && config->buildId != BuildIdKind::None)<br>
+ return &InputSection::discarded;<br>
<br>
// The linker merges EH (exception handling) frames and creates a<br>
// .eh_frame_hdr section for runtime. So we handle them with a special<br>
// class. For relocatable outputs, they are just passed through.<br>
- if (Name == ".eh_frame" && !Config->Relocatable)<br>
- return make<EhInputSection>(*this, Sec, Name);<br>
+ if (name == ".eh_frame" && !config->relocatable)<br>
+ return make<EhInputSection>(*this, sec, name);<br>
<br>
- if (shouldMerge(Sec))<br>
- return make<MergeInputSection>(*this, Sec, Name);<br>
- return make<InputSection>(*this, Sec, Name);<br>
+ if (shouldMerge(sec))<br>
+ return make<MergeInputSection>(*this, sec, name);<br>
+ return make<InputSection>(*this, sec, name);<br>
}<br>
<br>
template <class ELFT><br>
-StringRef ObjFile<ELFT>::getSectionName(const Elf_Shdr &Sec) {<br>
- return CHECK(getObj().getSectionName(&Sec, SectionStringTable), this);<br>
+StringRef ObjFile<ELFT>::getSectionName(const Elf_Shdr &sec) {<br>
+ return CHECK(getObj().getSectionName(&sec, sectionStringTable), this);<br>
}<br>
<br>
// Initialize this->Symbols. this->Symbols is a parallel array as<br>
// its corresponding ELF symbol table.<br>
template <class ELFT> void ObjFile<ELFT>::initializeSymbols() {<br>
- ArrayRef<Elf_Sym> ESyms = this->getELFSyms<ELFT>();<br>
- this->Symbols.resize(ESyms.size());<br>
+ ArrayRef<Elf_Sym> eSyms = this->getELFSyms<ELFT>();<br>
+ this->symbols.resize(eSyms.size());<br>
<br>
// Our symbol table may have already been partially initialized<br>
// because of LazyObjFile.<br>
- for (size_t I = 0, End = ESyms.size(); I != End; ++I)<br>
- if (!this->Symbols[I] && ESyms[I].getBinding() != STB_LOCAL)<br>
- this->Symbols[I] =<br>
- Symtab->insert(CHECK(ESyms[I].getName(this->StringTable), this));<br>
+ for (size_t i = 0, end = eSyms.size(); i != end; ++i)<br>
+ if (!this->symbols[i] && eSyms[i].getBinding() != STB_LOCAL)<br>
+ this->symbols[i] =<br>
+ symtab->insert(CHECK(eSyms[i].getName(this->stringTable), this));<br>
<br>
// Fill this->Symbols. A symbol is either local or global.<br>
- for (size_t I = 0, End = ESyms.size(); I != End; ++I) {<br>
- const Elf_Sym &ESym = ESyms[I];<br>
+ for (size_t i = 0, end = eSyms.size(); i != end; ++i) {<br>
+ const Elf_Sym &eSym = eSyms[i];<br>
<br>
// Read symbol attributes.<br>
- uint32_t SecIdx = getSectionIndex(ESym);<br>
- if (SecIdx >= this->Sections.size())<br>
- fatal(toString(this) + ": invalid section index: " + Twine(SecIdx));<br>
-<br>
- InputSectionBase *Sec = this->Sections[SecIdx];<br>
- uint8_t Binding = ESym.getBinding();<br>
- uint8_t StOther = ESym.st_other;<br>
- uint8_t Type = ESym.getType();<br>
- uint64_t Value = ESym.st_value;<br>
- uint64_t Size = ESym.st_size;<br>
- StringRefZ Name = this->StringTable.data() + ESym.st_name;<br>
+ uint32_t secIdx = getSectionIndex(eSym);<br>
+ if (secIdx >= this->sections.size())<br>
+ fatal(toString(this) + ": invalid section index: " + Twine(secIdx));<br>
+<br>
+ InputSectionBase *sec = this->sections[secIdx];<br>
+ uint8_t binding = eSym.getBinding();<br>
+ uint8_t stOther = eSym.st_other;<br>
+ uint8_t type = eSym.getType();<br>
+ uint64_t value = eSym.st_value;<br>
+ uint64_t size = eSym.st_size;<br>
+ StringRefZ name = this->stringTable.data() + eSym.st_name;<br>
<br>
// Handle local symbols. Local symbols are not added to the symbol<br>
// table because they are not visible from other object files. We<br>
// allocate symbol instances and add their pointers to Symbols.<br>
- if (Binding == STB_LOCAL) {<br>
- if (ESym.getType() == STT_FILE)<br>
- SourceFile = CHECK(ESym.getName(this->StringTable), this);<br>
+ if (binding == STB_LOCAL) {<br>
+ if (eSym.getType() == STT_FILE)<br>
+ sourceFile = CHECK(eSym.getName(this->stringTable), this);<br>
<br>
- if (this->StringTable.size() <= ESym.st_name)<br>
+ if (this->stringTable.size() <= eSym.st_name)<br>
fatal(toString(this) + ": invalid symbol name offset");<br>
<br>
- if (ESym.st_shndx == SHN_UNDEF)<br>
- this->Symbols[I] = make<Undefined>(this, Name, Binding, StOther, Type);<br>
- else if (Sec == &InputSection::Discarded)<br>
- this->Symbols[I] = make<Undefined>(this, Name, Binding, StOther, Type,<br>
- /*DiscardedSecIdx=*/SecIdx);<br>
+ if (eSym.st_shndx == SHN_UNDEF)<br>
+ this->symbols[i] = make<Undefined>(this, name, binding, stOther, type);<br>
+ else if (sec == &InputSection::discarded)<br>
+ this->symbols[i] = make<Undefined>(this, name, binding, stOther, type,<br>
+ /*DiscardedSecIdx=*/secIdx);<br>
else<br>
- this->Symbols[I] =<br>
- make<Defined>(this, Name, Binding, StOther, Type, Value, Size, Sec);<br>
+ this->symbols[i] =<br>
+ make<Defined>(this, name, binding, stOther, type, value, size, sec);<br>
continue;<br>
}<br>
<br>
// Handle global undefined symbols.<br>
- if (ESym.st_shndx == SHN_UNDEF) {<br>
- this->Symbols[I]->resolve(Undefined{this, Name, Binding, StOther, Type});<br>
+ if (eSym.st_shndx == SHN_UNDEF) {<br>
+ this->symbols[i]->resolve(Undefined{this, name, binding, stOther, type});<br>
continue;<br>
}<br>
<br>
// Handle global common symbols.<br>
- if (ESym.st_shndx == SHN_COMMON) {<br>
- if (Value == 0 || Value >= UINT32_MAX)<br>
- fatal(toString(this) + ": common symbol '" + StringRef(Name.Data) +<br>
- "' has invalid alignment: " + Twine(Value));<br>
- this->Symbols[I]->resolve(<br>
- CommonSymbol{this, Name, Binding, StOther, Type, Value, Size});<br>
+ if (eSym.st_shndx == SHN_COMMON) {<br>
+ if (value == 0 || value >= UINT32_MAX)<br>
+ fatal(toString(this) + ": common symbol '" + StringRef(name.data) +<br>
+ "' has invalid alignment: " + Twine(value));<br>
+ this->symbols[i]->resolve(<br>
+ CommonSymbol{this, name, binding, stOther, type, value, size});<br>
continue;<br>
}<br>
<br>
@@ -1110,87 +1110,87 @@ template <class ELFT> void ObjFile<ELFT><br>
// standard, but in practice, a .eh_frame often directly refer<br>
// COMDAT member sections, and if a comdat group is discarded, some<br>
// defined symbol in a .eh_frame becomes dangling symbols.<br>
- if (Sec == &InputSection::Discarded) {<br>
- this->Symbols[I]->resolve(<br>
- Undefined{this, Name, Binding, StOther, Type, SecIdx});<br>
+ if (sec == &InputSection::discarded) {<br>
+ this->symbols[i]->resolve(<br>
+ Undefined{this, name, binding, stOther, type, secIdx});<br>
continue;<br>
}<br>
<br>
// Handle global defined symbols.<br>
- if (Binding == STB_GLOBAL || Binding == STB_WEAK ||<br>
- Binding == STB_GNU_UNIQUE) {<br>
- this->Symbols[I]->resolve(<br>
- Defined{this, Name, Binding, StOther, Type, Value, Size, Sec});<br>
+ if (binding == STB_GLOBAL || binding == STB_WEAK ||<br>
+ binding == STB_GNU_UNIQUE) {<br>
+ this->symbols[i]->resolve(<br>
+ Defined{this, name, binding, stOther, type, value, size, sec});<br>
continue;<br>
}<br>
<br>
- fatal(toString(this) + ": unexpected binding: " + Twine((int)Binding));<br>
+ fatal(toString(this) + ": unexpected binding: " + Twine((int)binding));<br>
}<br>
}<br>
<br>
-ArchiveFile::ArchiveFile(std::unique_ptr<Archive> &&File)<br>
- : InputFile(ArchiveKind, File->getMemoryBufferRef()),<br>
- File(std::move(File)) {}<br>
+ArchiveFile::ArchiveFile(std::unique_ptr<Archive> &&file)<br>
+ : InputFile(ArchiveKind, file->getMemoryBufferRef()),<br>
+ file(std::move(file)) {}<br>
<br>
void ArchiveFile::parse() {<br>
- for (const Archive::Symbol &Sym : File->symbols())<br>
- Symtab->addSymbol(LazyArchive{*this, Sym});<br>
+ for (const Archive::Symbol &sym : file->symbols())<br>
+ symtab->addSymbol(LazyArchive{*this, sym});<br>
}<br>
<br>
// Returns a buffer pointing to a member file containing a given symbol.<br>
-void ArchiveFile::fetch(const Archive::Symbol &Sym) {<br>
- Archive::Child C =<br>
- CHECK(Sym.getMember(), toString(this) +<br>
+void ArchiveFile::fetch(const Archive::Symbol &sym) {<br>
+ Archive::Child c =<br>
+ CHECK(sym.getMember(), toString(this) +<br>
": could not get the member for symbol " +<br>
- Sym.getName());<br>
+ sym.getName());<br>
<br>
- if (!Seen.insert(C.getChildOffset()).second)<br>
+ if (!seen.insert(c.getChildOffset()).second)<br>
return;<br>
<br>
- MemoryBufferRef MB =<br>
- CHECK(C.getMemoryBufferRef(),<br>
+ MemoryBufferRef mb =<br>
+ CHECK(c.getMemoryBufferRef(),<br>
toString(this) +<br>
": could not get the buffer for the member defining symbol " +<br>
- Sym.getName());<br>
+ sym.getName());<br>
<br>
- if (Tar && C.getParent()->isThin())<br>
- Tar->append(relativeToRoot(CHECK(C.getFullName(), this)), MB.getBuffer());<br>
+ if (tar && c.getParent()->isThin())<br>
+ tar->append(relativeToRoot(CHECK(c.getFullName(), this)), mb.getBuffer());<br>
<br>
- InputFile *File = createObjectFile(<br>
- MB, getName(), C.getParent()->isThin() ? 0 : C.getChildOffset());<br>
- File->GroupId = GroupId;<br>
- parseFile(File);<br>
+ InputFile *file = createObjectFile(<br>
+ mb, getName(), c.getParent()->isThin() ? 0 : c.getChildOffset());<br>
+ file->groupId = groupId;<br>
+ parseFile(file);<br>
}<br>
<br>
-unsigned SharedFile::VernauxNum;<br>
+unsigned SharedFile::vernauxNum;<br>
<br>
// Parse the version definitions in the object file if present, and return a<br>
// vector whose nth element contains a pointer to the Elf_Verdef for version<br>
// identifier n. Version identifiers that are not definitions map to nullptr.<br>
template <typename ELFT><br>
-static std::vector<const void *> parseVerdefs(const uint8_t *Base,<br>
- const typename ELFT::Shdr *Sec) {<br>
- if (!Sec)<br>
+static std::vector<const void *> parseVerdefs(const uint8_t *base,<br>
+ const typename ELFT::Shdr *sec) {<br>
+ if (!sec)<br>
return {};<br>
<br>
// We cannot determine the largest verdef identifier without inspecting<br>
// every Elf_Verdef, but both bfd and gold assign verdef identifiers<br>
// sequentially starting from 1, so we predict that the largest identifier<br>
// will be VerdefCount.<br>
- unsigned VerdefCount = Sec->sh_info;<br>
- std::vector<const void *> Verdefs(VerdefCount + 1);<br>
+ unsigned verdefCount = sec->sh_info;<br>
+ std::vector<const void *> verdefs(verdefCount + 1);<br>
<br>
// Build the Verdefs array by following the chain of Elf_Verdef objects<br>
// from the start of the .gnu.version_d section.<br>
- const uint8_t *Verdef = Base + Sec->sh_offset;<br>
- for (unsigned I = 0; I != VerdefCount; ++I) {<br>
- auto *CurVerdef = reinterpret_cast<const typename ELFT::Verdef *>(Verdef);<br>
- Verdef += CurVerdef->vd_next;<br>
- unsigned VerdefIndex = CurVerdef->vd_ndx;<br>
- Verdefs.resize(VerdefIndex + 1);<br>
- Verdefs[VerdefIndex] = CurVerdef;<br>
+ const uint8_t *verdef = base + sec->sh_offset;<br>
+ for (unsigned i = 0; i != verdefCount; ++i) {<br>
+ auto *curVerdef = reinterpret_cast<const typename ELFT::Verdef *>(verdef);<br>
+ verdef += curVerdef->vd_next;<br>
+ unsigned verdefIndex = curVerdef->vd_ndx;<br>
+ verdefs.resize(verdefIndex + 1);<br>
+ verdefs[verdefIndex] = curVerdef;<br>
}<br>
- return Verdefs;<br>
+ return verdefs;<br>
}<br>
<br>
// We do not usually care about alignments of data in shared object<br>
@@ -1198,14 +1198,14 @@ static std::vector<const void *> parseVe<br>
// DSO symbol to point to .bss due to copy relocation, we need to keep<br>
// the original alignment requirements. We infer it in this function.<br>
template <typename ELFT><br>
-static uint64_t getAlignment(ArrayRef<typename ELFT::Shdr> Sections,<br>
- const typename ELFT::Sym &Sym) {<br>
- uint64_t Ret = UINT64_MAX;<br>
- if (Sym.st_value)<br>
- Ret = 1ULL << countTrailingZeros((uint64_t)Sym.st_value);<br>
- if (0 < Sym.st_shndx && Sym.st_shndx < Sections.size())<br>
- Ret = std::min<uint64_t>(Ret, Sections[Sym.st_shndx].sh_addralign);<br>
- return (Ret > UINT32_MAX) ? 0 : Ret;<br>
+static uint64_t getAlignment(ArrayRef<typename ELFT::Shdr> sections,<br>
+ const typename ELFT::Sym &sym) {<br>
+ uint64_t ret = UINT64_MAX;<br>
+ if (sym.st_value)<br>
+ ret = 1ULL << countTrailingZeros((uint64_t)sym.st_value);<br>
+ if (0 < sym.st_shndx && sym.st_shndx < sections.size())<br>
+ ret = std::min<uint64_t>(ret, sections[sym.st_shndx].sh_addralign);<br>
+ return (ret > UINT32_MAX) ? 0 : ret;<br>
}<br>
<br>
// Fully parse the shared object file.<br>
@@ -1230,156 +1230,156 @@ template <class ELFT> void SharedFile::p<br>
using Elf_Verdef = typename ELFT::Verdef;<br>
using Elf_Versym = typename ELFT::Versym;<br>
<br>
- ArrayRef<Elf_Dyn> DynamicTags;<br>
- const ELFFile<ELFT> Obj = this->getObj<ELFT>();<br>
- ArrayRef<Elf_Shdr> Sections = CHECK(Obj.sections(), this);<br>
+ ArrayRef<Elf_Dyn> dynamicTags;<br>
+ const ELFFile<ELFT> obj = this->getObj<ELFT>();<br>
+ ArrayRef<Elf_Shdr> sections = CHECK(obj.sections(), this);<br>
<br>
- const Elf_Shdr *VersymSec = nullptr;<br>
- const Elf_Shdr *VerdefSec = nullptr;<br>
+ const Elf_Shdr *versymSec = nullptr;<br>
+ const Elf_Shdr *verdefSec = nullptr;<br>
<br>
// Search for .dynsym, .dynamic, .symtab, .gnu.version and .gnu.version_d.<br>
- for (const Elf_Shdr &Sec : Sections) {<br>
- switch (Sec.sh_type) {<br>
+ for (const Elf_Shdr &sec : sections) {<br>
+ switch (sec.sh_type) {<br>
default:<br>
continue;<br>
case SHT_DYNAMIC:<br>
- DynamicTags =<br>
- CHECK(Obj.template getSectionContentsAsArray<Elf_Dyn>(&Sec), this);<br>
+ dynamicTags =<br>
+ CHECK(obj.template getSectionContentsAsArray<Elf_Dyn>(&sec), this);<br>
break;<br>
case SHT_GNU_versym:<br>
- VersymSec = &Sec;<br>
+ versymSec = &sec;<br>
break;<br>
case SHT_GNU_verdef:<br>
- VerdefSec = &Sec;<br>
+ verdefSec = &sec;<br>
break;<br>
}<br>
}<br>
<br>
- if (VersymSec && NumELFSyms == 0) {<br>
+ if (versymSec && numELFSyms == 0) {<br>
error("SHT_GNU_versym should be associated with symbol table");<br>
return;<br>
}<br>
<br>
// Search for a DT_SONAME tag to initialize this->SoName.<br>
- for (const Elf_Dyn &Dyn : DynamicTags) {<br>
- if (Dyn.d_tag == DT_NEEDED) {<br>
- uint64_t Val = Dyn.getVal();<br>
- if (Val >= this->StringTable.size())<br>
+ for (const Elf_Dyn &dyn : dynamicTags) {<br>
+ if (dyn.d_tag == DT_NEEDED) {<br>
+ uint64_t val = dyn.getVal();<br>
+ if (val >= this->stringTable.size())<br>
fatal(toString(this) + ": invalid DT_NEEDED entry");<br>
- DtNeeded.push_back(this->StringTable.data() + Val);<br>
- } else if (Dyn.d_tag == DT_SONAME) {<br>
- uint64_t Val = Dyn.getVal();<br>
- if (Val >= this->StringTable.size())<br>
+ dtNeeded.push_back(this->stringTable.data() + val);<br>
+ } else if (dyn.d_tag == DT_SONAME) {<br>
+ uint64_t val = dyn.getVal();<br>
+ if (val >= this->stringTable.size())<br>
fatal(toString(this) + ": invalid DT_SONAME entry");<br>
- SoName = this->StringTable.data() + Val;<br>
+ soName = this->stringTable.data() + val;<br>
}<br>
}<br>
<br>
// DSOs are uniquified not by filename but by soname.<br>
- DenseMap<StringRef, SharedFile *>::iterator It;<br>
- bool WasInserted;<br>
- std::tie(It, WasInserted) = Symtab->SoNames.try_emplace(SoName, this);<br>
+ DenseMap<StringRef, SharedFile *>::iterator it;<br>
+ bool wasInserted;<br>
+ std::tie(it, wasInserted) = symtab->soNames.try_emplace(soName, this);<br>
<br>
// If a DSO appears more than once on the command line with and without<br>
// --as-needed, --no-as-needed takes precedence over --as-needed because a<br>
// user can add an extra DSO with --no-as-needed to force it to be added to<br>
// the dependency list.<br>
- It->second->IsNeeded |= IsNeeded;<br>
- if (!WasInserted)<br>
+ it->second->isNeeded |= isNeeded;<br>
+ if (!wasInserted)<br>
return;<br>
<br>
- SharedFiles.push_back(this);<br>
+ sharedFiles.push_back(this);<br>
<br>
- Verdefs = parseVerdefs<ELFT>(Obj.base(), VerdefSec);<br>
+ verdefs = parseVerdefs<ELFT>(obj.base(), verdefSec);<br>
<br>
// Parse ".gnu.version" section which is a parallel array for the symbol<br>
// table. If a given file doesn't have a ".gnu.version" section, we use<br>
// VER_NDX_GLOBAL.<br>
- size_t Size = NumELFSyms - FirstGlobal;<br>
- std::vector<uint32_t> Versyms(Size, VER_NDX_GLOBAL);<br>
- if (VersymSec) {<br>
- ArrayRef<Elf_Versym> Versym =<br>
- CHECK(Obj.template getSectionContentsAsArray<Elf_Versym>(VersymSec),<br>
+ size_t size = numELFSyms - firstGlobal;<br>
+ std::vector<uint32_t> versyms(size, VER_NDX_GLOBAL);<br>
+ if (versymSec) {<br>
+ ArrayRef<Elf_Versym> versym =<br>
+ CHECK(obj.template getSectionContentsAsArray<Elf_Versym>(versymSec),<br>
this)<br>
- .slice(FirstGlobal);<br>
- for (size_t I = 0; I < Size; ++I)<br>
- Versyms[I] = Versym[I].vs_index;<br>
+ .slice(firstGlobal);<br>
+ for (size_t i = 0; i < size; ++i)<br>
+ versyms[i] = versym[i].vs_index;<br>
}<br>
<br>
// System libraries can have a lot of symbols with versions. Using a<br>
// fixed buffer for computing the versions name (foo@ver) can save a<br>
// lot of allocations.<br>
- SmallString<0> VersionedNameBuffer;<br>
+ SmallString<0> versionedNameBuffer;<br>
<br>
// Add symbols to the symbol table.<br>
- ArrayRef<Elf_Sym> Syms = this->getGlobalELFSyms<ELFT>();<br>
- for (size_t I = 0; I < Syms.size(); ++I) {<br>
- const Elf_Sym &Sym = Syms[I];<br>
+ ArrayRef<Elf_Sym> syms = this->getGlobalELFSyms<ELFT>();<br>
+ for (size_t i = 0; i < syms.size(); ++i) {<br>
+ const Elf_Sym &sym = syms[i];<br>
<br>
// ELF spec requires that all local symbols precede weak or global<br>
// symbols in each symbol table, and the index of first non-local symbol<br>
// is stored to sh_info. If a local symbol appears after some non-local<br>
// symbol, that's a violation of the spec.<br>
- StringRef Name = CHECK(Sym.getName(this->StringTable), this);<br>
- if (Sym.getBinding() == STB_LOCAL) {<br>
- warn("found local symbol '" + Name +<br>
+ StringRef name = CHECK(sym.getName(this->stringTable), this);<br>
+ if (sym.getBinding() == STB_LOCAL) {<br>
+ warn("found local symbol '" + name +<br>
"' in global part of symbol table in file " + toString(this));<br>
continue;<br>
}<br>
<br>
- if (Sym.isUndefined()) {<br>
- Symbol *S = Symtab->addSymbol(<br>
- Undefined{this, Name, Sym.getBinding(), Sym.st_other, Sym.getType()});<br>
- S->ExportDynamic = true;<br>
+ if (sym.isUndefined()) {<br>
+ Symbol *s = symtab->addSymbol(<br>
+ Undefined{this, name, sym.getBinding(), sym.st_other, sym.getType()});<br>
+ s->exportDynamic = true;<br>
continue;<br>
}<br>
<br>
// MIPS BFD linker puts _gp_disp symbol into DSO files and incorrectly<br>
// assigns VER_NDX_LOCAL to this section global symbol. Here is a<br>
// workaround for this bug.<br>
- uint32_t Idx = Versyms[I] & ~VERSYM_HIDDEN;<br>
- if (Config->EMachine == EM_MIPS && Idx == VER_NDX_LOCAL &&<br>
- Name == "_gp_disp")<br>
+ uint32_t idx = versyms[i] & ~VERSYM_HIDDEN;<br>
+ if (config->emachine == EM_MIPS && idx == VER_NDX_LOCAL &&<br>
+ name == "_gp_disp")<br>
continue;<br>
<br>
- uint32_t Alignment = getAlignment<ELFT>(Sections, Sym);<br>
- if (!(Versyms[I] & VERSYM_HIDDEN)) {<br>
- Symtab->addSymbol(SharedSymbol{*this, Name, Sym.getBinding(),<br>
- Sym.st_other, Sym.getType(), Sym.st_value,<br>
- Sym.st_size, Alignment, Idx});<br>
+ uint32_t alignment = getAlignment<ELFT>(sections, sym);<br>
+ if (!(versyms[i] & VERSYM_HIDDEN)) {<br>
+ symtab->addSymbol(SharedSymbol{*this, name, sym.getBinding(),<br>
+ sym.st_other, sym.getType(), sym.st_value,<br>
+ sym.st_size, alignment, idx});<br>
}<br>
<br>
// Also add the symbol with the versioned name to handle undefined symbols<br>
// with explicit versions.<br>
- if (Idx == VER_NDX_GLOBAL)<br>
+ if (idx == VER_NDX_GLOBAL)<br>
continue;<br>
<br>
- if (Idx >= Verdefs.size() || Idx == VER_NDX_LOCAL) {<br>
- error("corrupt input file: version definition index " + Twine(Idx) +<br>
- " for symbol " + Name + " is out of bounds\n>>> defined in " +<br>
+ if (idx >= verdefs.size() || idx == VER_NDX_LOCAL) {<br>
+ error("corrupt input file: version definition index " + Twine(idx) +<br>
+ " for symbol " + name + " is out of bounds\n>>> defined in " +<br>
toString(this));<br>
continue;<br>
}<br>
<br>
- StringRef VerName =<br>
- this->StringTable.data() +<br>
- reinterpret_cast<const Elf_Verdef *>(Verdefs[Idx])->getAux()->vda_name;<br>
- VersionedNameBuffer.clear();<br>
- Name = (Name + "@" + VerName).toStringRef(VersionedNameBuffer);<br>
- Symtab->addSymbol(SharedSymbol{*this, Saver.save(Name), Sym.getBinding(),<br>
- Sym.st_other, Sym.getType(), Sym.st_value,<br>
- Sym.st_size, Alignment, Idx});<br>
+ StringRef verName =<br>
+ this->stringTable.data() +<br>
+ reinterpret_cast<const Elf_Verdef *>(verdefs[idx])->getAux()->vda_name;<br>
+ versionedNameBuffer.clear();<br>
+ name = (name + "@" + verName).toStringRef(versionedNameBuffer);<br>
+ symtab->addSymbol(SharedSymbol{*this, Saver.save(name), sym.getBinding(),<br>
+ sym.st_other, sym.getType(), sym.st_value,<br>
+ sym.st_size, alignment, idx});<br>
}<br>
}<br>
<br>
-static ELFKind getBitcodeELFKind(const Triple &T) {<br>
- if (T.isLittleEndian())<br>
- return T.isArch64Bit() ? ELF64LEKind : ELF32LEKind;<br>
- return T.isArch64Bit() ? ELF64BEKind : ELF32BEKind;<br>
+static ELFKind getBitcodeELFKind(const Triple &t) {<br>
+ if (t.isLittleEndian())<br>
+ return t.isArch64Bit() ? ELF64LEKind : ELF32LEKind;<br>
+ return t.isArch64Bit() ? ELF64BEKind : ELF32BEKind;<br>
}<br>
<br>
-static uint8_t getBitcodeMachineKind(StringRef Path, const Triple &T) {<br>
- switch (T.getArch()) {<br>
+static uint8_t getBitcodeMachineKind(StringRef path, const Triple &t) {<br>
+ switch (t.getArch()) {<br>
case Triple::aarch64:<br>
return EM_AARCH64;<br>
case Triple::amdgcn:<br>
@@ -1406,24 +1406,24 @@ static uint8_t getBitcodeMachineKind(Str<br>
case Triple::riscv64:<br>
return EM_RISCV;<br>
case Triple::x86:<br>
- return T.isOSIAMCU() ? EM_IAMCU : EM_386;<br>
+ return t.isOSIAMCU() ? EM_IAMCU : EM_386;<br>
case Triple::x86_64:<br>
return EM_X86_64;<br>
default:<br>
- error(Path + ": could not infer e_machine from bitcode target triple " +<br>
- T.str());<br>
+ error(path + ": could not infer e_machine from bitcode target triple " +<br>
+ t.str());<br>
return EM_NONE;<br>
}<br>
}<br>
<br>
-BitcodeFile::BitcodeFile(MemoryBufferRef MB, StringRef ArchiveName,<br>
- uint64_t OffsetInArchive)<br>
- : InputFile(BitcodeKind, MB) {<br>
- this->ArchiveName = ArchiveName;<br>
-<br>
- std::string Path = MB.getBufferIdentifier().str();<br>
- if (Config->ThinLTOIndexOnly)<br>
- Path = replaceThinLTOSuffix(MB.getBufferIdentifier());<br>
+BitcodeFile::BitcodeFile(MemoryBufferRef mb, StringRef archiveName,<br>
+ uint64_t offsetInArchive)<br>
+ : InputFile(BitcodeKind, mb) {<br>
+ this->archiveName = archiveName;<br>
+<br>
+ std::string path = mb.getBufferIdentifier().str();<br>
+ if (config->thinLTOIndexOnly)<br>
+ path = replaceThinLTOSuffix(mb.getBufferIdentifier());<br>
<br>
// ThinLTO assumes that all MemoryBufferRefs given to it have a unique<br>
// name. If two archives define two members with the same name, this<br>
@@ -1431,21 +1431,21 @@ BitcodeFile::BitcodeFile(MemoryBufferRef<br>
// into consideration at LTO time (which very likely causes undefined<br>
// symbols later in the link stage). So we append file offset to make<br>
// filename unique.<br>
- StringRef Name = ArchiveName.empty()<br>
- ? Saver.save(Path)<br>
- : Saver.save(ArchiveName + "(" + Path + " at " +<br>
- utostr(OffsetInArchive) + ")");<br>
- MemoryBufferRef MBRef(MB.getBuffer(), Name);<br>
+ StringRef name = archiveName.empty()<br>
+ ? Saver.save(path)<br>
+ : Saver.save(archiveName + "(" + path + " at " +<br>
+ utostr(offsetInArchive) + ")");<br>
+ MemoryBufferRef mbref(mb.getBuffer(), name);<br>
<br>
- Obj = CHECK(lto::InputFile::create(MBRef), this);<br>
+ obj = CHECK(lto::InputFile::create(mbref), this);<br>
<br>
- Triple T(Obj->getTargetTriple());<br>
- EKind = getBitcodeELFKind(T);<br>
- EMachine = getBitcodeMachineKind(MB.getBufferIdentifier(), T);<br>
+ Triple t(obj->getTargetTriple());<br>
+ ekind = getBitcodeELFKind(t);<br>
+ emachine = getBitcodeMachineKind(mb.getBufferIdentifier(), t);<br>
}<br>
<br>
-static uint8_t mapVisibility(GlobalValue::VisibilityTypes GvVisibility) {<br>
- switch (GvVisibility) {<br>
+static uint8_t mapVisibility(GlobalValue::VisibilityTypes gvVisibility) {<br>
+ switch (gvVisibility) {<br>
case GlobalValue::DefaultVisibility:<br>
return STV_DEFAULT;<br>
case GlobalValue::HiddenVisibility:<br>
@@ -1457,169 +1457,169 @@ static uint8_t mapVisibility(GlobalValue<br>
}<br>
<br>
template <class ELFT><br>
-static Symbol *createBitcodeSymbol(const std::vector<bool> &KeptComdats,<br>
- const lto::InputFile::Symbol &ObjSym,<br>
- BitcodeFile &F) {<br>
- StringRef Name = Saver.save(ObjSym.getName());<br>
- uint8_t Binding = ObjSym.isWeak() ? STB_WEAK : STB_GLOBAL;<br>
- uint8_t Type = ObjSym.isTLS() ? STT_TLS : STT_NOTYPE;<br>
- uint8_t Visibility = mapVisibility(ObjSym.getVisibility());<br>
- bool CanOmitFromDynSym = ObjSym.canBeOmittedFromSymbolTable();<br>
-<br>
- int C = ObjSym.getComdatIndex();<br>
- if (ObjSym.isUndefined() || (C != -1 && !KeptComdats[C])) {<br>
- Undefined New(&F, Name, Binding, Visibility, Type);<br>
- if (CanOmitFromDynSym)<br>
- New.ExportDynamic = false;<br>
- return Symtab->addSymbol(New);<br>
- }<br>
-<br>
- if (ObjSym.isCommon())<br>
- return Symtab->addSymbol(<br>
- CommonSymbol{&F, Name, Binding, Visibility, STT_OBJECT,<br>
- ObjSym.getCommonAlignment(), ObjSym.getCommonSize()});<br>
-<br>
- Defined New(&F, Name, Binding, Visibility, Type, 0, 0, nullptr);<br>
- if (CanOmitFromDynSym)<br>
- New.ExportDynamic = false;<br>
- return Symtab->addSymbol(New);<br>
+static Symbol *createBitcodeSymbol(const std::vector<bool> &keptComdats,<br>
+ const lto::InputFile::Symbol &objSym,<br>
+ BitcodeFile &f) {<br>
+ StringRef name = Saver.save(objSym.getName());<br>
+ uint8_t binding = objSym.isWeak() ? STB_WEAK : STB_GLOBAL;<br>
+ uint8_t type = objSym.isTLS() ? STT_TLS : STT_NOTYPE;<br>
+ uint8_t visibility = mapVisibility(objSym.getVisibility());<br>
+ bool canOmitFromDynSym = objSym.canBeOmittedFromSymbolTable();<br>
+<br>
+ int c = objSym.getComdatIndex();<br>
+ if (objSym.isUndefined() || (c != -1 && !keptComdats[c])) {<br>
+ Undefined New(&f, name, binding, visibility, type);<br>
+ if (canOmitFromDynSym)<br>
+ New.exportDynamic = false;<br>
+ return symtab->addSymbol(New);<br>
+ }<br>
+<br>
+ if (objSym.isCommon())<br>
+ return symtab->addSymbol(<br>
+ CommonSymbol{&f, name, binding, visibility, STT_OBJECT,<br>
+ objSym.getCommonAlignment(), objSym.getCommonSize()});<br>
+<br>
+ Defined New(&f, name, binding, visibility, type, 0, 0, nullptr);<br>
+ if (canOmitFromDynSym)<br>
+ New.exportDynamic = false;<br>
+ return symtab->addSymbol(New);<br>
}<br>
<br>
template <class ELFT> void BitcodeFile::parse() {<br>
- std::vector<bool> KeptComdats;<br>
- for (StringRef S : Obj->getComdatTable())<br>
- KeptComdats.push_back(<br>
- Symtab->ComdatGroups.try_emplace(CachedHashStringRef(S), this).second);<br>
+ std::vector<bool> keptComdats;<br>
+ for (StringRef s : obj->getComdatTable())<br>
+ keptComdats.push_back(<br>
+ symtab->comdatGroups.try_emplace(CachedHashStringRef(s), this).second);<br>
<br>
- for (const lto::InputFile::Symbol &ObjSym : Obj->symbols())<br>
- Symbols.push_back(createBitcodeSymbol<ELFT>(KeptComdats, ObjSym, *this));<br>
+ for (const lto::InputFile::Symbol &objSym : obj->symbols())<br>
+ symbols.push_back(createBitcodeSymbol<ELFT>(keptComdats, objSym, *this));<br>
<br>
- for (auto L : Obj->getDependentLibraries())<br>
- addDependentLibrary(L, this);<br>
+ for (auto l : obj->getDependentLibraries())<br>
+ addDependentLibrary(l, this);<br>
}<br>
<br>
void BinaryFile::parse() {<br>
- ArrayRef<uint8_t> Data = arrayRefFromStringRef(MB.getBuffer());<br>
- auto *Section = make<InputSection>(this, SHF_ALLOC | SHF_WRITE, SHT_PROGBITS,<br>
- 8, Data, ".data");<br>
- Sections.push_back(Section);<br>
+ ArrayRef<uint8_t> data = arrayRefFromStringRef(mb.getBuffer());<br>
+ auto *section = make<InputSection>(this, SHF_ALLOC | SHF_WRITE, SHT_PROGBITS,<br>
+ 8, data, ".data");<br>
+ sections.push_back(section);<br>
<br>
// For each input file foo that is embedded to a result as a binary<br>
// blob, we define _binary_foo_{start,end,size} symbols, so that<br>
// user programs can access blobs by name. Non-alphanumeric<br>
// characters in a filename are replaced with underscore.<br>
- std::string S = "_binary_" + MB.getBufferIdentifier().str();<br>
- for (size_t I = 0; I < S.size(); ++I)<br>
- if (!isAlnum(S[I]))<br>
- S[I] = '_';<br>
-<br>
- Symtab->addSymbol(Defined{nullptr, Saver.save(S + "_start"), STB_GLOBAL,<br>
- STV_DEFAULT, STT_OBJECT, 0, 0, Section});<br>
- Symtab->addSymbol(Defined{nullptr, Saver.save(S + "_end"), STB_GLOBAL,<br>
- STV_DEFAULT, STT_OBJECT, Data.size(), 0, Section});<br>
- Symtab->addSymbol(Defined{nullptr, Saver.save(S + "_size"), STB_GLOBAL,<br>
- STV_DEFAULT, STT_OBJECT, Data.size(), 0, nullptr});<br>
-}<br>
-<br>
-InputFile *elf::createObjectFile(MemoryBufferRef MB, StringRef ArchiveName,<br>
- uint64_t OffsetInArchive) {<br>
- if (isBitcode(MB))<br>
- return make<BitcodeFile>(MB, ArchiveName, OffsetInArchive);<br>
+ std::string s = "_binary_" + mb.getBufferIdentifier().str();<br>
+ for (size_t i = 0; i < s.size(); ++i)<br>
+ if (!isAlnum(s[i]))<br>
+ s[i] = '_';<br>
+<br>
+ symtab->addSymbol(Defined{nullptr, Saver.save(s + "_start"), STB_GLOBAL,<br>
+ STV_DEFAULT, STT_OBJECT, 0, 0, section});<br>
+ symtab->addSymbol(Defined{nullptr, Saver.save(s + "_end"), STB_GLOBAL,<br>
+ STV_DEFAULT, STT_OBJECT, data.size(), 0, section});<br>
+ symtab->addSymbol(Defined{nullptr, Saver.save(s + "_size"), STB_GLOBAL,<br>
+ STV_DEFAULT, STT_OBJECT, data.size(), 0, nullptr});<br>
+}<br>
+<br>
+InputFile *elf::createObjectFile(MemoryBufferRef mb, StringRef archiveName,<br>
+ uint64_t offsetInArchive) {<br>
+ if (isBitcode(mb))<br>
+ return make<BitcodeFile>(mb, archiveName, offsetInArchive);<br>
<br>
- switch (getELFKind(MB, ArchiveName)) {<br>
+ switch (getELFKind(mb, archiveName)) {<br>
case ELF32LEKind:<br>
- return make<ObjFile<ELF32LE>>(MB, ArchiveName);<br>
+ return make<ObjFile<ELF32LE>>(mb, archiveName);<br>
case ELF32BEKind:<br>
- return make<ObjFile<ELF32BE>>(MB, ArchiveName);<br>
+ return make<ObjFile<ELF32BE>>(mb, archiveName);<br>
case ELF64LEKind:<br>
- return make<ObjFile<ELF64LE>>(MB, ArchiveName);<br>
+ return make<ObjFile<ELF64LE>>(mb, archiveName);<br>
case ELF64BEKind:<br>
- return make<ObjFile<ELF64BE>>(MB, ArchiveName);<br>
+ return make<ObjFile<ELF64BE>>(mb, archiveName);<br>
default:<br>
llvm_unreachable("getELFKind");<br>
}<br>
}<br>
<br>
void LazyObjFile::fetch() {<br>
- if (MB.getBuffer().empty())<br>
+ if (mb.getBuffer().empty())<br>
return;<br>
<br>
- InputFile *File = createObjectFile(MB, ArchiveName, OffsetInArchive);<br>
- File->GroupId = GroupId;<br>
+ InputFile *file = createObjectFile(mb, archiveName, offsetInArchive);<br>
+ file->groupId = groupId;<br>
<br>
- MB = {};<br>
+ mb = {};<br>
<br>
// Copy symbol vector so that the new InputFile doesn't have to<br>
// insert the same defined symbols to the symbol table again.<br>
- File->Symbols = std::move(Symbols);<br>
+ file->symbols = std::move(symbols);<br>
<br>
- parseFile(File);<br>
+ parseFile(file);<br>
}<br>
<br>
template <class ELFT> void LazyObjFile::parse() {<br>
using Elf_Sym = typename ELFT::Sym;<br>
<br>
// A lazy object file wraps either a bitcode file or an ELF file.<br>
- if (isBitcode(this->MB)) {<br>
- std::unique_ptr<lto::InputFile> Obj =<br>
- CHECK(lto::InputFile::create(this->MB), this);<br>
- for (const lto::InputFile::Symbol &Sym : Obj->symbols()) {<br>
- if (Sym.isUndefined())<br>
+ if (isBitcode(this->mb)) {<br>
+ std::unique_ptr<lto::InputFile> obj =<br>
+ CHECK(lto::InputFile::create(this->mb), this);<br>
+ for (const lto::InputFile::Symbol &sym : obj->symbols()) {<br>
+ if (sym.isUndefined())<br>
continue;<br>
- Symtab->addSymbol(LazyObject{*this, Saver.save(Sym.getName())});<br>
+ symtab->addSymbol(LazyObject{*this, Saver.save(sym.getName())});<br>
}<br>
return;<br>
}<br>
<br>
- if (getELFKind(this->MB, ArchiveName) != Config->EKind) {<br>
- error("incompatible file: " + this->MB.getBufferIdentifier());<br>
+ if (getELFKind(this->mb, archiveName) != config->ekind) {<br>
+ error("incompatible file: " + this->mb.getBufferIdentifier());<br>
return;<br>
}<br>
<br>
// Find a symbol table.<br>
- ELFFile<ELFT> Obj = check(ELFFile<ELFT>::create(MB.getBuffer()));<br>
- ArrayRef<typename ELFT::Shdr> Sections = CHECK(Obj.sections(), this);<br>
+ ELFFile<ELFT> obj = check(ELFFile<ELFT>::create(mb.getBuffer()));<br>
+ ArrayRef<typename ELFT::Shdr> sections = CHECK(obj.sections(), this);<br>
<br>
- for (const typename ELFT::Shdr &Sec : Sections) {<br>
- if (Sec.sh_type != SHT_SYMTAB)<br>
+ for (const typename ELFT::Shdr &sec : sections) {<br>
+ if (sec.sh_type != SHT_SYMTAB)<br>
continue;<br>
<br>
// A symbol table is found.<br>
- ArrayRef<Elf_Sym> ESyms = CHECK(Obj.symbols(&Sec), this);<br>
- uint32_t FirstGlobal = Sec.sh_info;<br>
- StringRef Strtab = CHECK(Obj.getStringTableForSymtab(Sec, Sections), this);<br>
- this->Symbols.resize(ESyms.size());<br>
+ ArrayRef<Elf_Sym> eSyms = CHECK(obj.symbols(&sec), this);<br>
+ uint32_t firstGlobal = sec.sh_info;<br>
+ StringRef strtab = CHECK(obj.getStringTableForSymtab(sec, sections), this);<br>
+ this->symbols.resize(eSyms.size());<br>
<br>
// Get existing symbols or insert placeholder symbols.<br>
- for (size_t I = FirstGlobal, End = ESyms.size(); I != End; ++I)<br>
- if (ESyms[I].st_shndx != SHN_UNDEF)<br>
- this->Symbols[I] = Symtab->insert(CHECK(ESyms[I].getName(Strtab), this));<br>
+ for (size_t i = firstGlobal, end = eSyms.size(); i != end; ++i)<br>
+ if (eSyms[i].st_shndx != SHN_UNDEF)<br>
+ this->symbols[i] = symtab->insert(CHECK(eSyms[i].getName(strtab), this));<br>
<br>
// Replace existing symbols with LazyObject symbols.<br>
//<br>
// resolve() may trigger this->fetch() if an existing symbol is an<br>
// undefined symbol. If that happens, this LazyObjFile has served<br>
// its purpose, and we can exit from the loop early.<br>
- for (Symbol *Sym : this->Symbols) {<br>
- if (!Sym)<br>
+ for (Symbol *sym : this->symbols) {<br>
+ if (!sym)<br>
continue;<br>
- Sym->resolve(LazyObject{*this, Sym->getName()});<br>
+ sym->resolve(LazyObject{*this, sym->getName()});<br>
<br>
// MemoryBuffer is emptied if this file is instantiated as ObjFile.<br>
- if (MB.getBuffer().empty())<br>
+ if (mb.getBuffer().empty())<br>
return;<br>
}<br>
return;<br>
}<br>
}<br>
<br>
-std::string elf::replaceThinLTOSuffix(StringRef Path) {<br>
- StringRef Suffix = Config->ThinLTOObjectSuffixReplace.first;<br>
- StringRef Repl = Config->ThinLTOObjectSuffixReplace.second;<br>
-<br>
- if (Path.consume_back(Suffix))<br>
- return (Path + Repl).str();<br>
- return Path;<br>
+std::string elf::replaceThinLTOSuffix(StringRef path) {<br>
+ StringRef suffix = config->thinLTOObjectSuffixReplace.first;<br>
+ StringRef repl = config->thinLTOObjectSuffixReplace.second;<br>
+<br>
+ if (path.consume_back(suffix))<br>
+ return (path + repl).str();<br>
+ return path;<br>
}<br>
<br>
template void BitcodeFile::parse<ELF32LE>();<br>
<br>
Modified: lld/trunk/ELF/InputFiles.h<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_ELF_InputFiles.h-3Frev-3D365595-26r1-3D365594-26r2-3D365595-26view-3Ddiff&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=8CMbPezr9q-cnBldZ16ej1bZmpQKIDw24JFdc6xGuvU&e=" rel="noreferrer" target="_blank">https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_ELF_InputFiles.h-3Frev-3D365595-26r1-3D365594-26r2-3D365595-26view-3Ddiff&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=8CMbPezr9q-cnBldZ16ej1bZmpQKIDw24JFdc6xGuvU&e=</a> <br>
==============================================================================<br>
--- lld/trunk/ELF/InputFiles.h (original)<br>
+++ lld/trunk/ELF/InputFiles.h Tue Jul 9 22:00:37 2019<br>
@@ -39,7 +39,7 @@ class InputSectionBase;<br>
}<br>
<br>
// Returns "<internal>", "foo.a(bar.o)" or "baz.o".<br>
-std::string toString(const elf::InputFile *F);<br>
+std::string toString(const elf::InputFile *f);<br>
<br>
namespace elf {<br>
<br>
@@ -49,13 +49,13 @@ class Symbol;<br>
<br>
// If -reproduce option is given, all input files are written<br>
// to this tar archive.<br>
-extern std::unique_ptr<llvm::TarWriter> Tar;<br>
+extern std::unique_ptr<llvm::TarWriter> tar;<br>
<br>
// Opens a given file.<br>
-llvm::Optional<MemoryBufferRef> readFile(StringRef Path);<br>
+llvm::Optional<MemoryBufferRef> readFile(StringRef path);<br>
<br>
// Add symbols in File to the symbol table.<br>
-void parseFile(InputFile *File);<br>
+void parseFile(InputFile *file);<br>
<br>
// The root class of input files.<br>
class InputFile {<br>
@@ -69,21 +69,21 @@ public:<br>
BinaryKind,<br>
};<br>
<br>
- Kind kind() const { return FileKind; }<br>
+ Kind kind() const { return fileKind; }<br>
<br>
bool isElf() const {<br>
- Kind K = kind();<br>
- return K == ObjKind || K == SharedKind;<br>
+ Kind k = kind();<br>
+ return k == ObjKind || k == SharedKind;<br>
}<br>
<br>
- StringRef getName() const { return MB.getBufferIdentifier(); }<br>
- MemoryBufferRef MB;<br>
+ StringRef getName() const { return mb.getBufferIdentifier(); }<br>
+ MemoryBufferRef mb;<br>
<br>
// Returns sections. It is a runtime error to call this function<br>
// on files that don't have the notion of sections.<br>
ArrayRef<InputSectionBase *> getSections() const {<br>
- assert(FileKind == ObjKind || FileKind == BinaryKind);<br>
- return Sections;<br>
+ assert(fileKind == ObjKind || fileKind == BinaryKind);<br>
+ return sections;<br>
}<br>
<br>
// Returns object file symbols. It is a runtime error to call this<br>
@@ -91,35 +91,35 @@ public:<br>
ArrayRef<Symbol *> getSymbols() { return getMutableSymbols(); }<br>
<br>
MutableArrayRef<Symbol *> getMutableSymbols() {<br>
- assert(FileKind == BinaryKind || FileKind == ObjKind ||<br>
- FileKind == BitcodeKind);<br>
- return Symbols;<br>
+ assert(fileKind == BinaryKind || fileKind == ObjKind ||<br>
+ fileKind == BitcodeKind);<br>
+ return symbols;<br>
}<br>
<br>
// Filename of .a which contained this file. If this file was<br>
// not in an archive file, it is the empty string. We use this<br>
// string for creating error messages.<br>
- std::string ArchiveName;<br>
+ std::string archiveName;<br>
<br>
// If this is an architecture-specific file, the following members<br>
// have ELF type (i.e. ELF{32,64}{LE,BE}) and target machine type.<br>
- ELFKind EKind = ELFNoneKind;<br>
- uint16_t EMachine = llvm::ELF::EM_NONE;<br>
- uint8_t OSABI = 0;<br>
- uint8_t ABIVersion = 0;<br>
+ ELFKind ekind = ELFNoneKind;<br>
+ uint16_t emachine = llvm::ELF::EM_NONE;<br>
+ uint8_t osabi = 0;<br>
+ uint8_t abiVersion = 0;<br>
<br>
// Cache for toString(). Only toString() should use this member.<br>
- mutable std::string ToStringCache;<br>
+ mutable std::string toStringCache;<br>
<br>
- std::string getSrcMsg(const Symbol &Sym, InputSectionBase &Sec,<br>
- uint64_t Offset);<br>
+ std::string getSrcMsg(const Symbol &sym, InputSectionBase &sec,<br>
+ uint64_t offset);<br>
<br>
// True if this is an argument for --just-symbols. Usually false.<br>
- bool JustSymbols = false;<br>
+ bool justSymbols = false;<br>
<br>
// OutSecOff of .got2 in the current file. This is used by PPC32 -fPIC/-fPIE<br>
// to compute offsets in PLT call stubs.<br>
- uint32_t PPC32Got2OutSecOff = 0;<br>
+ uint32_t ppc32Got2OutSecOff = 0;<br>
<br>
// On PPC64 we need to keep track of which files contain small code model<br>
// relocations that access the .toc section. To minimize the chance of a<br>
@@ -130,56 +130,56 @@ public:<br>
// code model relocations support immediates in the range [-0x8000, 0x7FFC],<br>
// making the addressable range relative to the toc pointer<br>
// [.got, .got + 0xFFFC].<br>
- bool PPC64SmallCodeModelTocRelocs = false;<br>
+ bool ppc64SmallCodeModelTocRelocs = false;<br>
<br>
// GroupId is used for --warn-backrefs which is an optional error<br>
// checking feature. All files within the same --{start,end}-group or<br>
// --{start,end}-lib get the same group ID. Otherwise, each file gets a new<br>
// group ID. For more info, see checkDependency() in SymbolTable.cpp.<br>
- uint32_t GroupId;<br>
- static bool IsInGroup;<br>
- static uint32_t NextGroupId;<br>
+ uint32_t groupId;<br>
+ static bool isInGroup;<br>
+ static uint32_t nextGroupId;<br>
<br>
// Index of MIPS GOT built for this file.<br>
- llvm::Optional<size_t> MipsGotIndex;<br>
+ llvm::Optional<size_t> mipsGotIndex;<br>
<br>
- std::vector<Symbol *> Symbols;<br>
+ std::vector<Symbol *> symbols;<br>
<br>
protected:<br>
- InputFile(Kind K, MemoryBufferRef M);<br>
- std::vector<InputSectionBase *> Sections;<br>
+ InputFile(Kind k, MemoryBufferRef m);<br>
+ std::vector<InputSectionBase *> sections;<br>
<br>
private:<br>
- const Kind FileKind;<br>
+ const Kind fileKind;<br>
};<br>
<br>
class ELFFileBase : public InputFile {<br>
public:<br>
- ELFFileBase(Kind K, MemoryBufferRef M);<br>
- static bool classof(const InputFile *F) { return F->isElf(); }<br>
+ ELFFileBase(Kind k, MemoryBufferRef m);<br>
+ static bool classof(const InputFile *f) { return f->isElf(); }<br>
<br>
template <typename ELFT> llvm::object::ELFFile<ELFT> getObj() const {<br>
- return check(llvm::object::ELFFile<ELFT>::create(MB.getBuffer()));<br>
+ return check(llvm::object::ELFFile<ELFT>::create(mb.getBuffer()));<br>
}<br>
<br>
- StringRef getStringTable() const { return StringTable; }<br>
+ StringRef getStringTable() const { return stringTable; }<br>
<br>
template <typename ELFT> typename ELFT::SymRange getELFSyms() const {<br>
return typename ELFT::SymRange(<br>
- reinterpret_cast<const typename ELFT::Sym *>(ELFSyms), NumELFSyms);<br>
+ reinterpret_cast<const typename ELFT::Sym *>(elfSyms), numELFSyms);<br>
}<br>
template <typename ELFT> typename ELFT::SymRange getGlobalELFSyms() const {<br>
- return getELFSyms<ELFT>().slice(FirstGlobal);<br>
+ return getELFSyms<ELFT>().slice(firstGlobal);<br>
}<br>
<br>
protected:<br>
// Initializes this class's member variables.<br>
template <typename ELFT> void init();<br>
<br>
- const void *ELFSyms = nullptr;<br>
- size_t NumELFSyms = 0;<br>
- uint32_t FirstGlobal = 0;<br>
- StringRef StringTable;<br>
+ const void *elfSyms = nullptr;<br>
+ size_t numELFSyms = 0;<br>
+ uint32_t firstGlobal = 0;<br>
+ StringRef stringTable;<br>
};<br>
<br>
// .o file.<br>
@@ -192,7 +192,7 @@ template <class ELFT> class ObjFile : pu<br>
using Elf_CGProfile = typename ELFT::CGProfile;<br>
<br>
public:<br>
- static bool classof(const InputFile *F) { return F->kind() == ObjKind; }<br>
+ static bool classof(const InputFile *f) { return f->kind() == ObjKind; }<br>
<br>
llvm::object::ELFFile<ELFT> getObj() const {<br>
return this->ELFFileBase::getObj<ELFT>();<br>
@@ -201,67 +201,67 @@ public:<br>
ArrayRef<Symbol *> getLocalSymbols();<br>
ArrayRef<Symbol *> getGlobalSymbols();<br>
<br>
- ObjFile(MemoryBufferRef M, StringRef ArchiveName) : ELFFileBase(ObjKind, M) {<br>
- this->ArchiveName = ArchiveName;<br>
+ ObjFile(MemoryBufferRef m, StringRef archiveName) : ELFFileBase(ObjKind, m) {<br>
+ this->archiveName = archiveName;<br>
}<br>
<br>
- void parse(bool IgnoreComdats = false);<br>
+ void parse(bool ignoreComdats = false);<br>
<br>
- StringRef getShtGroupSignature(ArrayRef<Elf_Shdr> Sections,<br>
- const Elf_Shdr &Sec);<br>
+ StringRef getShtGroupSignature(ArrayRef<Elf_Shdr> sections,<br>
+ const Elf_Shdr &sec);<br>
<br>
- Symbol &getSymbol(uint32_t SymbolIndex) const {<br>
- if (SymbolIndex >= this->Symbols.size())<br>
+ Symbol &getSymbol(uint32_t symbolIndex) const {<br>
+ if (symbolIndex >= this->symbols.size())<br>
fatal(toString(this) + ": invalid symbol index");<br>
- return *this->Symbols[SymbolIndex];<br>
+ return *this->symbols[symbolIndex];<br>
}<br>
<br>
- uint32_t getSectionIndex(const Elf_Sym &Sym) const;<br>
+ uint32_t getSectionIndex(const Elf_Sym &sym) const;<br>
<br>
- template <typename RelT> Symbol &getRelocTargetSym(const RelT &Rel) const {<br>
- uint32_t SymIndex = Rel.getSymbol(Config->IsMips64EL);<br>
- return getSymbol(SymIndex);<br>
+ template <typename RelT> Symbol &getRelocTargetSym(const RelT &rel) const {<br>
+ uint32_t symIndex = rel.getSymbol(config->isMips64EL);<br>
+ return getSymbol(symIndex);<br>
}<br>
<br>
llvm::Optional<llvm::DILineInfo> getDILineInfo(InputSectionBase *, uint64_t);<br>
- llvm::Optional<std::pair<std::string, unsigned>> getVariableLoc(StringRef Name);<br>
+ llvm::Optional<std::pair<std::string, unsigned>> getVariableLoc(StringRef name);<br>
<br>
// MIPS GP0 value defined by this file. This value represents the gp value<br>
// used to create the relocatable object and required to support<br>
// R_MIPS_GPREL16 / R_MIPS_GPREL32 relocations.<br>
- uint32_t MipsGp0 = 0;<br>
+ uint32_t mipsGp0 = 0;<br>
<br>
- uint32_t AndFeatures = 0;<br>
+ uint32_t andFeatures = 0;<br>
<br>
// Name of source file obtained from STT_FILE symbol value,<br>
// or empty string if there is no such symbol in object file<br>
// symbol table.<br>
- StringRef SourceFile;<br>
+ StringRef sourceFile;<br>
<br>
// True if the file defines functions compiled with<br>
// -fsplit-stack. Usually false.<br>
- bool SplitStack = false;<br>
+ bool splitStack = false;<br>
<br>
// True if the file defines functions compiled with -fsplit-stack,<br>
// but had one or more functions with the no_split_stack attribute.<br>
- bool SomeNoSplitStack = false;<br>
+ bool someNoSplitStack = false;<br>
<br>
// Pointer to this input file's .llvm_addrsig section, if it has one.<br>
- const Elf_Shdr *AddrsigSec = nullptr;<br>
+ const Elf_Shdr *addrsigSec = nullptr;<br>
<br>
// SHT_LLVM_CALL_GRAPH_PROFILE table<br>
- ArrayRef<Elf_CGProfile> CGProfile;<br>
+ ArrayRef<Elf_CGProfile> cgProfile;<br>
<br>
private:<br>
- void initializeSections(bool IgnoreComdats);<br>
+ void initializeSections(bool ignoreComdats);<br>
void initializeSymbols();<br>
void initializeJustSymbols();<br>
void initializeDwarf();<br>
- InputSectionBase *getRelocTarget(const Elf_Shdr &Sec);<br>
- InputSectionBase *createInputSection(const Elf_Shdr &Sec);<br>
- StringRef getSectionName(const Elf_Shdr &Sec);<br>
+ InputSectionBase *getRelocTarget(const Elf_Shdr &sec);<br>
+ InputSectionBase *createInputSection(const Elf_Shdr &sec);<br>
+ StringRef getSectionName(const Elf_Shdr &sec);<br>
<br>
- bool shouldMerge(const Elf_Shdr &Sec);<br>
+ bool shouldMerge(const Elf_Shdr &sec);<br>
<br>
// Each ELF symbol contains a section index which the symbol belongs to.<br>
// However, because the number of bits dedicated for that is limited, a<br>
@@ -275,24 +275,24 @@ private:<br>
//<br>
// The following variable contains the contents of .symtab_shndx.<br>
// If the section does not exist (which is common), the array is empty.<br>
- ArrayRef<Elf_Word> ShndxTable;<br>
+ ArrayRef<Elf_Word> shndxTable;<br>
<br>
// .shstrtab contents.<br>
- StringRef SectionStringTable;<br>
+ StringRef sectionStringTable;<br>
<br>
// Debugging information to retrieve source file and line for error<br>
// reporting. Linker may find reasonable number of errors in a<br>
// single object file, so we cache debugging information in order to<br>
// parse it only once for each object file we link.<br>
- std::unique_ptr<llvm::DWARFContext> Dwarf;<br>
- std::vector<const llvm::DWARFDebugLine::LineTable *> LineTables;<br>
+ std::unique_ptr<llvm::DWARFContext> dwarf;<br>
+ std::vector<const llvm::DWARFDebugLine::LineTable *> lineTables;<br>
struct VarLoc {<br>
- const llvm::DWARFDebugLine::LineTable *LT;<br>
- unsigned File;<br>
- unsigned Line;<br>
+ const llvm::DWARFDebugLine::LineTable *lt;<br>
+ unsigned file;<br>
+ unsigned line;<br>
};<br>
- llvm::DenseMap<StringRef, VarLoc> VariableLoc;<br>
- llvm::once_flag InitDwarfLine;<br>
+ llvm::DenseMap<StringRef, VarLoc> variableLoc;<br>
+ llvm::once_flag initDwarfLine;<br>
};<br>
<br>
// LazyObjFile is analogous to ArchiveFile in the sense that<br>
@@ -304,100 +304,100 @@ private:<br>
// archive file semantics.<br>
class LazyObjFile : public InputFile {<br>
public:<br>
- LazyObjFile(MemoryBufferRef M, StringRef ArchiveName,<br>
- uint64_t OffsetInArchive)<br>
- : InputFile(LazyObjKind, M), OffsetInArchive(OffsetInArchive) {<br>
- this->ArchiveName = ArchiveName;<br>
+ LazyObjFile(MemoryBufferRef m, StringRef archiveName,<br>
+ uint64_t offsetInArchive)<br>
+ : InputFile(LazyObjKind, m), offsetInArchive(offsetInArchive) {<br>
+ this->archiveName = archiveName;<br>
}<br>
<br>
- static bool classof(const InputFile *F) { return F->kind() == LazyObjKind; }<br>
+ static bool classof(const InputFile *f) { return f->kind() == LazyObjKind; }<br>
<br>
template <class ELFT> void parse();<br>
void fetch();<br>
<br>
private:<br>
- uint64_t OffsetInArchive;<br>
+ uint64_t offsetInArchive;<br>
};<br>
<br>
// An ArchiveFile object represents a .a file.<br>
class ArchiveFile : public InputFile {<br>
public:<br>
- explicit ArchiveFile(std::unique_ptr<Archive> &&File);<br>
- static bool classof(const InputFile *F) { return F->kind() == ArchiveKind; }<br>
+ explicit ArchiveFile(std::unique_ptr<Archive> &&file);<br>
+ static bool classof(const InputFile *f) { return f->kind() == ArchiveKind; }<br>
void parse();<br>
<br>
// Pulls out an object file that contains a definition for Sym and<br>
// returns it. If the same file was instantiated before, this<br>
// function does nothing (so we don't instantiate the same file<br>
// more than once.)<br>
- void fetch(const Archive::Symbol &Sym);<br>
+ void fetch(const Archive::Symbol &sym);<br>
<br>
private:<br>
- std::unique_ptr<Archive> File;<br>
- llvm::DenseSet<uint64_t> Seen;<br>
+ std::unique_ptr<Archive> file;<br>
+ llvm::DenseSet<uint64_t> seen;<br>
};<br>
<br>
class BitcodeFile : public InputFile {<br>
public:<br>
- BitcodeFile(MemoryBufferRef M, StringRef ArchiveName,<br>
- uint64_t OffsetInArchive);<br>
- static bool classof(const InputFile *F) { return F->kind() == BitcodeKind; }<br>
+ BitcodeFile(MemoryBufferRef m, StringRef archiveName,<br>
+ uint64_t offsetInArchive);<br>
+ static bool classof(const InputFile *f) { return f->kind() == BitcodeKind; }<br>
template <class ELFT> void parse();<br>
- std::unique_ptr<llvm::lto::InputFile> Obj;<br>
+ std::unique_ptr<llvm::lto::InputFile> obj;<br>
};<br>
<br>
// .so file.<br>
class SharedFile : public ELFFileBase {<br>
public:<br>
- SharedFile(MemoryBufferRef M, StringRef DefaultSoName)<br>
- : ELFFileBase(SharedKind, M), SoName(DefaultSoName),<br>
- IsNeeded(!Config->AsNeeded) {}<br>
+ SharedFile(MemoryBufferRef m, StringRef defaultSoName)<br>
+ : ELFFileBase(SharedKind, m), soName(defaultSoName),<br>
+ isNeeded(!config->asNeeded) {}<br>
<br>
// This is actually a vector of Elf_Verdef pointers.<br>
- std::vector<const void *> Verdefs;<br>
+ std::vector<const void *> verdefs;<br>
<br>
// If the output file needs Elf_Verneed data structures for this file, this is<br>
// a vector of Elf_Vernaux version identifiers that map onto the entries in<br>
// Verdefs, otherwise it is empty.<br>
- std::vector<unsigned> Vernauxs;<br>
+ std::vector<unsigned> vernauxs;<br>
<br>
- static unsigned VernauxNum;<br>
+ static unsigned vernauxNum;<br>
<br>
- std::vector<StringRef> DtNeeded;<br>
- std::string SoName;<br>
+ std::vector<StringRef> dtNeeded;<br>
+ std::string soName;<br>
<br>
- static bool classof(const InputFile *F) { return F->kind() == SharedKind; }<br>
+ static bool classof(const InputFile *f) { return f->kind() == SharedKind; }<br>
<br>
template <typename ELFT> void parse();<br>
<br>
// Used for --no-allow-shlib-undefined.<br>
- bool AllNeededIsKnown;<br>
+ bool allNeededIsKnown;<br>
<br>
// Used for --as-needed<br>
- bool IsNeeded;<br>
+ bool isNeeded;<br>
};<br>
<br>
class BinaryFile : public InputFile {<br>
public:<br>
- explicit BinaryFile(MemoryBufferRef M) : InputFile(BinaryKind, M) {}<br>
- static bool classof(const InputFile *F) { return F->kind() == BinaryKind; }<br>
+ explicit BinaryFile(MemoryBufferRef m) : InputFile(BinaryKind, m) {}<br>
+ static bool classof(const InputFile *f) { return f->kind() == BinaryKind; }<br>
void parse();<br>
};<br>
<br>
-InputFile *createObjectFile(MemoryBufferRef MB, StringRef ArchiveName = "",<br>
- uint64_t OffsetInArchive = 0);<br>
+InputFile *createObjectFile(MemoryBufferRef mb, StringRef archiveName = "",<br>
+ uint64_t offsetInArchive = 0);<br>
<br>
-inline bool isBitcode(MemoryBufferRef MB) {<br>
- return identify_magic(MB.getBuffer()) == llvm::file_magic::bitcode;<br>
+inline bool isBitcode(MemoryBufferRef mb) {<br>
+ return identify_magic(mb.getBuffer()) == llvm::file_magic::bitcode;<br>
}<br>
<br>
-std::string replaceThinLTOSuffix(StringRef Path);<br>
+std::string replaceThinLTOSuffix(StringRef path);<br>
<br>
-extern std::vector<BinaryFile *> BinaryFiles;<br>
-extern std::vector<BitcodeFile *> BitcodeFiles;<br>
-extern std::vector<LazyObjFile *> LazyObjFiles;<br>
-extern std::vector<InputFile *> ObjectFiles;<br>
-extern std::vector<SharedFile *> SharedFiles;<br>
+extern std::vector<BinaryFile *> binaryFiles;<br>
+extern std::vector<BitcodeFile *> bitcodeFiles;<br>
+extern std::vector<LazyObjFile *> lazyObjFiles;<br>
+extern std::vector<InputFile *> objectFiles;<br>
+extern std::vector<SharedFile *> sharedFiles;<br>
<br>
} // namespace elf<br>
} // namespace lld<br>
<br>
Modified: lld/trunk/ELF/InputSection.cpp<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_ELF_InputSection.cpp-3Frev-3D365595-26r1-3D365594-26r2-3D365595-26view-3Ddiff&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=ogECe1ENEqw6TBvmzsmn7KY1fMM6AT2g3Mu1gdOE09A&e=" rel="noreferrer" target="_blank">https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_ELF_InputSection.cpp-3Frev-3D365595-26r1-3D365594-26r2-3D365595-26view-3Ddiff&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=ogECe1ENEqw6TBvmzsmn7KY1fMM6AT2g3Mu1gdOE09A&e=</a> <br>
==============================================================================<br>
--- lld/trunk/ELF/InputSection.cpp (original)<br>
+++ lld/trunk/ELF/InputSection.cpp Tue Jul 9 22:00:37 2019<br>
@@ -40,52 +40,52 @@ using namespace llvm::sys;<br>
using namespace lld;<br>
using namespace lld::elf;<br>
<br>
-std::vector<InputSectionBase *> elf::InputSections;<br>
+std::vector<InputSectionBase *> elf::inputSections;<br>
<br>
// Returns a string to construct an error message.<br>
-std::string lld::toString(const InputSectionBase *Sec) {<br>
- return (toString(Sec->File) + ":(" + Sec->Name + ")").str();<br>
+std::string lld::toString(const InputSectionBase *sec) {<br>
+ return (toString(sec->file) + ":(" + sec->name + ")").str();<br>
}<br>
<br>
template <class ELFT><br>
-static ArrayRef<uint8_t> getSectionContents(ObjFile<ELFT> &File,<br>
- const typename ELFT::Shdr &Hdr) {<br>
- if (Hdr.sh_type == SHT_NOBITS)<br>
- return makeArrayRef<uint8_t>(nullptr, Hdr.sh_size);<br>
- return check(File.getObj().getSectionContents(&Hdr));<br>
+static ArrayRef<uint8_t> getSectionContents(ObjFile<ELFT> &file,<br>
+ const typename ELFT::Shdr &hdr) {<br>
+ if (hdr.sh_type == SHT_NOBITS)<br>
+ return makeArrayRef<uint8_t>(nullptr, hdr.sh_size);<br>
+ return check(file.getObj().getSectionContents(&hdr));<br>
}<br>
<br>
-InputSectionBase::InputSectionBase(InputFile *File, uint64_t Flags,<br>
- uint32_t Type, uint64_t Entsize,<br>
- uint32_t Link, uint32_t Info,<br>
- uint32_t Alignment, ArrayRef<uint8_t> Data,<br>
- StringRef Name, Kind SectionKind)<br>
- : SectionBase(SectionKind, Name, Flags, Entsize, Alignment, Type, Info,<br>
- Link),<br>
- File(File), RawData(Data) {<br>
+InputSectionBase::InputSectionBase(InputFile *file, uint64_t flags,<br>
+ uint32_t type, uint64_t entsize,<br>
+ uint32_t link, uint32_t info,<br>
+ uint32_t alignment, ArrayRef<uint8_t> data,<br>
+ StringRef name, Kind sectionKind)<br>
+ : SectionBase(sectionKind, name, flags, entsize, alignment, type, info,<br>
+ link),<br>
+ file(file), rawData(data) {<br>
// In order to reduce memory allocation, we assume that mergeable<br>
// sections are smaller than 4 GiB, which is not an unreasonable<br>
// assumption as of 2017.<br>
- if (SectionKind == SectionBase::Merge && RawData.size() > UINT32_MAX)<br>
+ if (sectionKind == SectionBase::Merge && rawData.size() > UINT32_MAX)<br>
error(toString(this) + ": section too large");<br>
<br>
- NumRelocations = 0;<br>
- AreRelocsRela = false;<br>
+ numRelocations = 0;<br>
+ areRelocsRela = false;<br>
<br>
// The ELF spec states that a value of 0 means the section has<br>
// no alignment constraits.<br>
- uint32_t V = std::max<uint32_t>(Alignment, 1);<br>
- if (!isPowerOf2_64(V))<br>
+ uint32_t v = std::max<uint32_t>(alignment, 1);<br>
+ if (!isPowerOf2_64(v))<br>
fatal(toString(this) + ": sh_addralign is not a power of 2");<br>
- this->Alignment = V;<br>
+ this->alignment = v;<br>
<br>
// In ELF, each section can be compressed by zlib, and if compressed,<br>
// section name may be mangled by appending "z" (e.g. ".zdebug_info").<br>
// If that's the case, demangle section name so that we can handle a<br>
// section as if it weren't compressed.<br>
- if ((Flags & SHF_COMPRESSED) || Name.startswith(".zdebug")) {<br>
+ if ((flags & SHF_COMPRESSED) || name.startswith(".zdebug")) {<br>
if (!zlib::isAvailable())<br>
- error(toString(File) + ": contains a compressed section, " +<br>
+ error(toString(file) + ": contains a compressed section, " +<br>
"but zlib is not available");<br>
parseCompressedHeader();<br>
}<br>
@@ -94,11 +94,11 @@ InputSectionBase::InputSectionBase(Input<br>
// Drop SHF_GROUP bit unless we are producing a re-linkable object file.<br>
// SHF_GROUP is a marker that a section belongs to some comdat group.<br>
// That flag doesn't make sense in an executable.<br>
-static uint64_t getFlags(uint64_t Flags) {<br>
- Flags &= ~(uint64_t)SHF_INFO_LINK;<br>
- if (!Config->Relocatable)<br>
- Flags &= ~(uint64_t)SHF_GROUP;<br>
- return Flags;<br>
+static uint64_t getFlags(uint64_t flags) {<br>
+ flags &= ~(uint64_t)SHF_INFO_LINK;<br>
+ if (!config->relocatable)<br>
+ flags &= ~(uint64_t)SHF_GROUP;<br>
+ return flags;<br>
}<br>
<br>
// GNU assembler 2.24 and LLVM 4.0.0's MC (the newest release as of<br>
@@ -111,99 +111,99 @@ static uint64_t getFlags(uint64_t Flags)<br>
//<br>
// This function forces SHT_{INIT,FINI}_ARRAY so that we can handle<br>
// incorrect inputs as if they were correct from the beginning.<br>
-static uint64_t getType(uint64_t Type, StringRef Name) {<br>
- if (Type == SHT_PROGBITS && Name.startswith(".init_array."))<br>
+static uint64_t getType(uint64_t type, StringRef name) {<br>
+ if (type == SHT_PROGBITS && name.startswith(".init_array."))<br>
return SHT_INIT_ARRAY;<br>
- if (Type == SHT_PROGBITS && Name.startswith(".fini_array."))<br>
+ if (type == SHT_PROGBITS && name.startswith(".fini_array."))<br>
return SHT_FINI_ARRAY;<br>
- return Type;<br>
+ return type;<br>
}<br>
<br>
template <class ELFT><br>
-InputSectionBase::InputSectionBase(ObjFile<ELFT> &File,<br>
- const typename ELFT::Shdr &Hdr,<br>
- StringRef Name, Kind SectionKind)<br>
- : InputSectionBase(&File, getFlags(Hdr.sh_flags),<br>
- getType(Hdr.sh_type, Name), Hdr.sh_entsize, Hdr.sh_link,<br>
- Hdr.sh_info, Hdr.sh_addralign,<br>
- getSectionContents(File, Hdr), Name, SectionKind) {<br>
+InputSectionBase::InputSectionBase(ObjFile<ELFT> &file,<br>
+ const typename ELFT::Shdr &hdr,<br>
+ StringRef name, Kind sectionKind)<br>
+ : InputSectionBase(&file, getFlags(hdr.sh_flags),<br>
+ getType(hdr.sh_type, name), hdr.sh_entsize, hdr.sh_link,<br>
+ hdr.sh_info, hdr.sh_addralign,<br>
+ getSectionContents(file, hdr), name, sectionKind) {<br>
// We reject object files having insanely large alignments even though<br>
// they are allowed by the spec. I think 4GB is a reasonable limitation.<br>
// We might want to relax this in the future.<br>
- if (Hdr.sh_addralign > UINT32_MAX)<br>
- fatal(toString(&File) + ": section sh_addralign is too large");<br>
+ if (hdr.sh_addralign > UINT32_MAX)<br>
+ fatal(toString(&file) + ": section sh_addralign is too large");<br>
}<br>
<br>
size_t InputSectionBase::getSize() const {<br>
- if (auto *S = dyn_cast<SyntheticSection>(this))<br>
- return S->getSize();<br>
- if (UncompressedSize >= 0)<br>
- return UncompressedSize;<br>
- return RawData.size();<br>
+ if (auto *s = dyn_cast<SyntheticSection>(this))<br>
+ return s->getSize();<br>
+ if (uncompressedSize >= 0)<br>
+ return uncompressedSize;<br>
+ return rawData.size();<br>
}<br>
<br>
void InputSectionBase::uncompress() const {<br>
- size_t Size = UncompressedSize;<br>
- char *UncompressedBuf;<br>
+ size_t size = uncompressedSize;<br>
+ char *uncompressedBuf;<br>
{<br>
- static std::mutex Mu;<br>
- std::lock_guard<std::mutex> Lock(Mu);<br>
- UncompressedBuf = BAlloc.Allocate<char>(Size);<br>
+ static std::mutex mu;<br>
+ std::lock_guard<std::mutex> lock(mu);<br>
+ uncompressedBuf = BAlloc.Allocate<char>(size);<br>
}<br>
<br>
- if (Error E = zlib::uncompress(toStringRef(RawData), UncompressedBuf, Size))<br>
+ if (Error e = zlib::uncompress(toStringRef(rawData), uncompressedBuf, size))<br>
fatal(toString(this) +<br>
- ": uncompress failed: " + llvm::toString(std::move(E)));<br>
- RawData = makeArrayRef((uint8_t *)UncompressedBuf, Size);<br>
- UncompressedSize = -1;<br>
+ ": uncompress failed: " + llvm::toString(std::move(e)));<br>
+ rawData = makeArrayRef((uint8_t *)uncompressedBuf, size);<br>
+ uncompressedSize = -1;<br>
}<br>
<br>
uint64_t InputSectionBase::getOffsetInFile() const {<br>
- const uint8_t *FileStart = (const uint8_t *)File->MB.getBufferStart();<br>
- const uint8_t *SecStart = data().begin();<br>
- return SecStart - FileStart;<br>
+ const uint8_t *fileStart = (const uint8_t *)file->mb.getBufferStart();<br>
+ const uint8_t *secStart = data().begin();<br>
+ return secStart - fileStart;<br>
}<br>
<br>
-uint64_t SectionBase::getOffset(uint64_t Offset) const {<br>
+uint64_t SectionBase::getOffset(uint64_t offset) const {<br>
switch (kind()) {<br>
case Output: {<br>
- auto *OS = cast<OutputSection>(this);<br>
+ auto *os = cast<OutputSection>(this);<br>
// For output sections we treat offset -1 as the end of the section.<br>
- return Offset == uint64_t(-1) ? OS->Size : Offset;<br>
+ return offset == uint64_t(-1) ? os->size : offset;<br>
}<br>
case Regular:<br>
case Synthetic:<br>
- return cast<InputSection>(this)->getOffset(Offset);<br>
+ return cast<InputSection>(this)->getOffset(offset);<br>
case EHFrame:<br>
// The file crtbeginT.o has relocations pointing to the start of an empty<br>
// .eh_frame that is known to be the first in the link. It does that to<br>
// identify the start of the output .eh_frame.<br>
- return Offset;<br>
+ return offset;<br>
case Merge:<br>
- const MergeInputSection *MS = cast<MergeInputSection>(this);<br>
- if (InputSection *IS = MS->getParent())<br>
- return IS->getOffset(MS->getParentOffset(Offset));<br>
- return MS->getParentOffset(Offset);<br>
+ const MergeInputSection *ms = cast<MergeInputSection>(this);<br>
+ if (InputSection *isec = ms->getParent())<br>
+ return isec->getOffset(ms->getParentOffset(offset));<br>
+ return ms->getParentOffset(offset);<br>
}<br>
llvm_unreachable("invalid section kind");<br>
}<br>
<br>
-uint64_t SectionBase::getVA(uint64_t Offset) const {<br>
- const OutputSection *Out = getOutputSection();<br>
- return (Out ? Out->Addr : 0) + getOffset(Offset);<br>
+uint64_t SectionBase::getVA(uint64_t offset) const {<br>
+ const OutputSection *out = getOutputSection();<br>
+ return (out ? out->addr : 0) + getOffset(offset);<br>
}<br>
<br>
OutputSection *SectionBase::getOutputSection() {<br>
- InputSection *Sec;<br>
- if (auto *IS = dyn_cast<InputSection>(this))<br>
- Sec = IS;<br>
- else if (auto *MS = dyn_cast<MergeInputSection>(this))<br>
- Sec = MS->getParent();<br>
- else if (auto *EH = dyn_cast<EhInputSection>(this))<br>
- Sec = EH->getParent();<br>
+ InputSection *sec;<br>
+ if (auto *isec = dyn_cast<InputSection>(this))<br>
+ sec = isec;<br>
+ else if (auto *ms = dyn_cast<MergeInputSection>(this))<br>
+ sec = ms->getParent();<br>
+ else if (auto *eh = dyn_cast<EhInputSection>(this))<br>
+ sec = eh->getParent();<br>
else<br>
return cast<OutputSection>(this);<br>
- return Sec ? Sec->getParent() : nullptr;<br>
+ return sec ? sec->getParent() : nullptr;<br>
}<br>
<br>
// When a section is compressed, `RawData` consists with a header followed<br>
@@ -214,109 +214,109 @@ void InputSectionBase::parseCompressedHe<br>
using Chdr32 = typename ELF32LE::Chdr;<br>
<br>
// Old-style header<br>
- if (Name.startswith(".zdebug")) {<br>
- if (!toStringRef(RawData).startswith("ZLIB")) {<br>
+ if (name.startswith(".zdebug")) {<br>
+ if (!toStringRef(rawData).startswith("ZLIB")) {<br>
error(toString(this) + ": corrupted compressed section header");<br>
return;<br>
}<br>
- RawData = RawData.slice(4);<br>
+ rawData = rawData.slice(4);<br>
<br>
- if (RawData.size() < 8) {<br>
+ if (rawData.size() < 8) {<br>
error(toString(this) + ": corrupted compressed section header");<br>
return;<br>
}<br>
<br>
- UncompressedSize = read64be(RawData.data());<br>
- RawData = RawData.slice(8);<br>
+ uncompressedSize = read64be(rawData.data());<br>
+ rawData = rawData.slice(8);<br>
<br>
// Restore the original section name.<br>
// (e.g. ".zdebug_info" -> ".debug_info")<br>
- Name = Saver.save("." + Name.substr(2));<br>
+ name = Saver.save("." + name.substr(2));<br>
return;<br>
}<br>
<br>
- assert(Flags & SHF_COMPRESSED);<br>
- Flags &= ~(uint64_t)SHF_COMPRESSED;<br>
+ assert(flags & SHF_COMPRESSED);<br>
+ flags &= ~(uint64_t)SHF_COMPRESSED;<br>
<br>
// New-style 64-bit header<br>
- if (Config->Is64) {<br>
- if (RawData.size() < sizeof(Chdr64)) {<br>
+ if (config->is64) {<br>
+ if (rawData.size() < sizeof(Chdr64)) {<br>
error(toString(this) + ": corrupted compressed section");<br>
return;<br>
}<br>
<br>
- auto *Hdr = reinterpret_cast<const Chdr64 *>(RawData.data());<br>
- if (Hdr->ch_type != ELFCOMPRESS_ZLIB) {<br>
+ auto *hdr = reinterpret_cast<const Chdr64 *>(rawData.data());<br>
+ if (hdr->ch_type != ELFCOMPRESS_ZLIB) {<br>
error(toString(this) + ": unsupported compression type");<br>
return;<br>
}<br>
<br>
- UncompressedSize = Hdr->ch_size;<br>
- Alignment = std::max<uint32_t>(Hdr->ch_addralign, 1);<br>
- RawData = RawData.slice(sizeof(*Hdr));<br>
+ uncompressedSize = hdr->ch_size;<br>
+ alignment = std::max<uint32_t>(hdr->ch_addralign, 1);<br>
+ rawData = rawData.slice(sizeof(*hdr));<br>
return;<br>
}<br>
<br>
// New-style 32-bit header<br>
- if (RawData.size() < sizeof(Chdr32)) {<br>
+ if (rawData.size() < sizeof(Chdr32)) {<br>
error(toString(this) + ": corrupted compressed section");<br>
return;<br>
}<br>
<br>
- auto *Hdr = reinterpret_cast<const Chdr32 *>(RawData.data());<br>
- if (Hdr->ch_type != ELFCOMPRESS_ZLIB) {<br>
+ auto *hdr = reinterpret_cast<const Chdr32 *>(rawData.data());<br>
+ if (hdr->ch_type != ELFCOMPRESS_ZLIB) {<br>
error(toString(this) + ": unsupported compression type");<br>
return;<br>
}<br>
<br>
- UncompressedSize = Hdr->ch_size;<br>
- Alignment = std::max<uint32_t>(Hdr->ch_addralign, 1);<br>
- RawData = RawData.slice(sizeof(*Hdr));<br>
+ uncompressedSize = hdr->ch_size;<br>
+ alignment = std::max<uint32_t>(hdr->ch_addralign, 1);<br>
+ rawData = rawData.slice(sizeof(*hdr));<br>
}<br>
<br>
InputSection *InputSectionBase::getLinkOrderDep() const {<br>
- assert(Link);<br>
- assert(Flags & SHF_LINK_ORDER);<br>
- return cast<InputSection>(File->getSections()[Link]);<br>
+ assert(link);<br>
+ assert(flags & SHF_LINK_ORDER);<br>
+ return cast<InputSection>(file->getSections()[link]);<br>
}<br>
<br>
// Find a function symbol that encloses a given location.<br>
template <class ELFT><br>
-Defined *InputSectionBase::getEnclosingFunction(uint64_t Offset) {<br>
- for (Symbol *B : File->getSymbols())<br>
- if (Defined *D = dyn_cast<Defined>(B))<br>
- if (D->Section == this && D->Type == STT_FUNC && D->Value <= Offset &&<br>
- Offset < D->Value + D->Size)<br>
- return D;<br>
+Defined *InputSectionBase::getEnclosingFunction(uint64_t offset) {<br>
+ for (Symbol *b : file->getSymbols())<br>
+ if (Defined *d = dyn_cast<Defined>(b))<br>
+ if (d->section == this && d->type == STT_FUNC && d->value <= offset &&<br>
+ offset < d->value + d->size)<br>
+ return d;<br>
return nullptr;<br>
}<br>
<br>
// Returns a source location string. Used to construct an error message.<br>
template <class ELFT><br>
-std::string InputSectionBase::getLocation(uint64_t Offset) {<br>
- std::string SecAndOffset = (Name + "+0x" + utohexstr(Offset)).str();<br>
+std::string InputSectionBase::getLocation(uint64_t offset) {<br>
+ std::string secAndOffset = (name + "+0x" + utohexstr(offset)).str();<br>
<br>
// We don't have file for synthetic sections.<br>
if (getFile<ELFT>() == nullptr)<br>
- return (Config->OutputFile + ":(" + SecAndOffset + ")")<br>
+ return (config->outputFile + ":(" + secAndOffset + ")")<br>
.str();<br>
<br>
// First check if we can get desired values from debugging information.<br>
- if (Optional<DILineInfo> Info = getFile<ELFT>()->getDILineInfo(this, Offset))<br>
- return Info->FileName + ":" + std::to_string(Info->Line) + ":(" +<br>
- SecAndOffset + ")";<br>
+ if (Optional<DILineInfo> info = getFile<ELFT>()->getDILineInfo(this, offset))<br>
+ return info->FileName + ":" + std::to_string(info->Line) + ":(" +<br>
+ secAndOffset + ")";<br>
<br>
// File->SourceFile contains STT_FILE symbol that contains a<br>
// source file name. If it's missing, we use an object file name.<br>
- std::string SrcFile = getFile<ELFT>()->SourceFile;<br>
- if (SrcFile.empty())<br>
- SrcFile = toString(File);<br>
+ std::string srcFile = getFile<ELFT>()->sourceFile;<br>
+ if (srcFile.empty())<br>
+ srcFile = toString(file);<br>
<br>
- if (Defined *D = getEnclosingFunction<ELFT>(Offset))<br>
- return SrcFile + ":(function " + toString(*D) + ": " + SecAndOffset + ")";<br>
+ if (Defined *d = getEnclosingFunction<ELFT>(offset))<br>
+ return srcFile + ":(function " + toString(*d) + ": " + secAndOffset + ")";<br>
<br>
// If there's no symbol, print out the offset in the section.<br>
- return (SrcFile + ":(" + SecAndOffset + ")");<br>
+ return (srcFile + ":(" + secAndOffset + ")");<br>
}<br>
<br>
// This function is intended to be used for constructing an error message.<br>
@@ -325,8 +325,8 @@ std::string InputSectionBase::getLocatio<br>
// foo.c:42 (/home/alice/possibly/very/long/path/foo.c:42)<br>
//<br>
// Returns an empty string if there's no way to get line info.<br>
-std::string InputSectionBase::getSrcMsg(const Symbol &Sym, uint64_t Offset) {<br>
- return File->getSrcMsg(Sym, *this, Offset);<br>
+std::string InputSectionBase::getSrcMsg(const Symbol &sym, uint64_t offset) {<br>
+ return file->getSrcMsg(sym, *this, offset);<br>
}<br>
<br>
// Returns a filename string along with an optional section name. This<br>
@@ -338,96 +338,96 @@ std::string InputSectionBase::getSrcMsg(<br>
// or<br>
//<br>
// path/to/foo.o:(function bar) in archive path/to/bar.a<br>
-std::string InputSectionBase::getObjMsg(uint64_t Off) {<br>
- std::string Filename = File->getName();<br>
+std::string InputSectionBase::getObjMsg(uint64_t off) {<br>
+ std::string filename = file->getName();<br>
<br>
- std::string Archive;<br>
- if (!File->ArchiveName.empty())<br>
- Archive = " in archive " + File->ArchiveName;<br>
+ std::string archive;<br>
+ if (!file->archiveName.empty())<br>
+ archive = " in archive " + file->archiveName;<br>
<br>
// Find a symbol that encloses a given location.<br>
- for (Symbol *B : File->getSymbols())<br>
- if (auto *D = dyn_cast<Defined>(B))<br>
- if (D->Section == this && D->Value <= Off && Off < D->Value + D->Size)<br>
- return Filename + ":(" + toString(*D) + ")" + Archive;<br>
+ for (Symbol *b : file->getSymbols())<br>
+ if (auto *d = dyn_cast<Defined>(b))<br>
+ if (d->section == this && d->value <= off && off < d->value + d->size)<br>
+ return filename + ":(" + toString(*d) + ")" + archive;<br>
<br>
// If there's no symbol, print out the offset in the section.<br>
- return (Filename + ":(" + Name + "+0x" + utohexstr(Off) + ")" + Archive)<br>
+ return (filename + ":(" + name + "+0x" + utohexstr(off) + ")" + archive)<br>
.str();<br>
}<br>
<br>
-InputSection InputSection::Discarded(nullptr, 0, 0, 0, ArrayRef<uint8_t>(), "");<br>
+InputSection InputSection::discarded(nullptr, 0, 0, 0, ArrayRef<uint8_t>(), "");<br>
<br>
-InputSection::InputSection(InputFile *F, uint64_t Flags, uint32_t Type,<br>
- uint32_t Alignment, ArrayRef<uint8_t> Data,<br>
- StringRef Name, Kind K)<br>
- : InputSectionBase(F, Flags, Type,<br>
- /*Entsize*/ 0, /*Link*/ 0, /*Info*/ 0, Alignment, Data,<br>
- Name, K) {}<br>
+InputSection::InputSection(InputFile *f, uint64_t flags, uint32_t type,<br>
+ uint32_t alignment, ArrayRef<uint8_t> data,<br>
+ StringRef name, Kind k)<br>
+ : InputSectionBase(f, flags, type,<br>
+ /*Entsize*/ 0, /*Link*/ 0, /*Info*/ 0, alignment, data,<br>
+ name, k) {}<br>
<br>
template <class ELFT><br>
-InputSection::InputSection(ObjFile<ELFT> &F, const typename ELFT::Shdr &Header,<br>
- StringRef Name)<br>
- : InputSectionBase(F, Header, Name, InputSectionBase::Regular) {}<br>
-<br>
-bool InputSection::classof(const SectionBase *S) {<br>
- return S->kind() == SectionBase::Regular ||<br>
- S->kind() == SectionBase::Synthetic;<br>
+InputSection::InputSection(ObjFile<ELFT> &f, const typename ELFT::Shdr &header,<br>
+ StringRef name)<br>
+ : InputSectionBase(f, header, name, InputSectionBase::Regular) {}<br>
+<br>
+bool InputSection::classof(const SectionBase *s) {<br>
+ return s->kind() == SectionBase::Regular ||<br>
+ s->kind() == SectionBase::Synthetic;<br>
}<br>
<br>
OutputSection *InputSection::getParent() const {<br>
- return cast_or_null<OutputSection>(Parent);<br>
+ return cast_or_null<OutputSection>(parent);<br>
}<br>
<br>
// Copy SHT_GROUP section contents. Used only for the -r option.<br>
-template <class ELFT> void InputSection::copyShtGroup(uint8_t *Buf) {<br>
+template <class ELFT> void InputSection::copyShtGroup(uint8_t *buf) {<br>
// ELFT::Word is the 32-bit integral type in the target endianness.<br>
using u32 = typename ELFT::Word;<br>
- ArrayRef<u32> From = getDataAs<u32>();<br>
- auto *To = reinterpret_cast<u32 *>(Buf);<br>
+ ArrayRef<u32> from = getDataAs<u32>();<br>
+ auto *to = reinterpret_cast<u32 *>(buf);<br>
<br>
// The first entry is not a section number but a flag.<br>
- *To++ = From[0];<br>
+ *to++ = from[0];<br>
<br>
// Adjust section numbers because section numbers in an input object<br>
// files are different in the output.<br>
- ArrayRef<InputSectionBase *> Sections = File->getSections();<br>
- for (uint32_t Idx : From.slice(1))<br>
- *To++ = Sections[Idx]->getOutputSection()->SectionIndex;<br>
+ ArrayRef<InputSectionBase *> sections = file->getSections();<br>
+ for (uint32_t idx : from.slice(1))<br>
+ *to++ = sections[idx]->getOutputSection()->sectionIndex;<br>
}<br>
<br>
InputSectionBase *InputSection::getRelocatedSection() const {<br>
- if (!File || (Type != SHT_RELA && Type != SHT_REL))<br>
+ if (!file || (type != SHT_RELA && type != SHT_REL))<br>
return nullptr;<br>
- ArrayRef<InputSectionBase *> Sections = File->getSections();<br>
- return Sections[Info];<br>
+ ArrayRef<InputSectionBase *> sections = file->getSections();<br>
+ return sections[info];<br>
}<br>
<br>
// This is used for -r and --emit-relocs. We can't use memcpy to copy<br>
// relocations because we need to update symbol table offset and section index<br>
// for each relocation. So we copy relocations one by one.<br>
template <class ELFT, class RelTy><br>
-void InputSection::copyRelocations(uint8_t *Buf, ArrayRef<RelTy> Rels) {<br>
- InputSectionBase *Sec = getRelocatedSection();<br>
+void InputSection::copyRelocations(uint8_t *buf, ArrayRef<RelTy> rels) {<br>
+ InputSectionBase *sec = getRelocatedSection();<br>
<br>
- for (const RelTy &Rel : Rels) {<br>
- RelType Type = Rel.getType(Config->IsMips64EL);<br>
- const ObjFile<ELFT> *File = getFile<ELFT>();<br>
- Symbol &Sym = File->getRelocTargetSym(Rel);<br>
+ for (const RelTy &rel : rels) {<br>
+ RelType type = rel.getType(config->isMips64EL);<br>
+ const ObjFile<ELFT> *file = getFile<ELFT>();<br>
+ Symbol &sym = file->getRelocTargetSym(rel);<br>
<br>
- auto *P = reinterpret_cast<typename ELFT::Rela *>(Buf);<br>
- Buf += sizeof(RelTy);<br>
+ auto *p = reinterpret_cast<typename ELFT::Rela *>(buf);<br>
+ buf += sizeof(RelTy);<br>
<br>
if (RelTy::IsRela)<br>
- P->r_addend = getAddend<ELFT>(Rel);<br>
+ p->r_addend = getAddend<ELFT>(rel);<br>
<br>
// Output section VA is zero for -r, so r_offset is an offset within the<br>
// section, but for --emit-relocs it is an virtual address.<br>
- P->r_offset = Sec->getVA(Rel.r_offset);<br>
- P->setSymbolAndType(In.SymTab->getSymbolIndex(&Sym), Type,<br>
- Config->IsMips64EL);<br>
+ p->r_offset = sec->getVA(rel.r_offset);<br>
+ p->setSymbolAndType(in.symTab->getSymbolIndex(&sym), type,<br>
+ config->isMips64EL);<br>
<br>
- if (Sym.Type == STT_SECTION) {<br>
+ if (sym.type == STT_SECTION) {<br>
// We combine multiple section symbols into only one per<br>
// section. This means we have to update the addend. That is<br>
// trivial for Elf_Rela, but for Elf_Rel we have to write to the<br>
@@ -440,34 +440,34 @@ void InputSection::copyRelocations(uint8<br>
// on .gcc_except_table and debug sections.<br>
//<br>
// See the comment in maybeReportUndefined for PPC64 .toc .<br>
- auto *D = dyn_cast<Defined>(&Sym);<br>
- if (!D) {<br>
- if (!Sec->Name.startswith(".debug") &&<br>
- !Sec->Name.startswith(".zdebug") && Sec->Name != ".eh_frame" &&<br>
- Sec->Name != ".gcc_except_table" && Sec->Name != ".toc") {<br>
- uint32_t SecIdx = cast<Undefined>(Sym).DiscardedSecIdx;<br>
- Elf_Shdr_Impl<ELFT> Sec =<br>
- CHECK(File->getObj().sections(), File)[SecIdx];<br>
+ auto *d = dyn_cast<Defined>(&sym);<br>
+ if (!d) {<br>
+ if (!sec->name.startswith(".debug") &&<br>
+ !sec->name.startswith(".zdebug") && sec->name != ".eh_frame" &&<br>
+ sec->name != ".gcc_except_table" && sec->name != ".toc") {<br>
+ uint32_t secIdx = cast<Undefined>(sym).discardedSecIdx;<br>
+ Elf_Shdr_Impl<ELFT> sec =<br>
+ CHECK(file->getObj().sections(), file)[secIdx];<br>
warn("relocation refers to a discarded section: " +<br>
- CHECK(File->getObj().getSectionName(&Sec), File) +<br>
- "\n>>> referenced by " + getObjMsg(P->r_offset));<br>
+ CHECK(file->getObj().getSectionName(&sec), file) +<br>
+ "\n>>> referenced by " + getObjMsg(p->r_offset));<br>
}<br>
- P->setSymbolAndType(0, 0, false);<br>
+ p->setSymbolAndType(0, 0, false);<br>
continue;<br>
}<br>
- SectionBase *Section = D->Section->Repl;<br>
- if (!Section->isLive()) {<br>
- P->setSymbolAndType(0, 0, false);<br>
+ SectionBase *section = d->section->repl;<br>
+ if (!section->isLive()) {<br>
+ p->setSymbolAndType(0, 0, false);<br>
continue;<br>
}<br>
<br>
- int64_t Addend = getAddend<ELFT>(Rel);<br>
- const uint8_t *BufLoc = Sec->data().begin() + Rel.r_offset;<br>
+ int64_t addend = getAddend<ELFT>(rel);<br>
+ const uint8_t *bufLoc = sec->data().begin() + rel.r_offset;<br>
if (!RelTy::IsRela)<br>
- Addend = Target->getImplicitAddend(BufLoc, Type);<br>
+ addend = target->getImplicitAddend(bufLoc, type);<br>
<br>
- if (Config->EMachine == EM_MIPS && Config->Relocatable &&<br>
- Target->getRelExpr(Type, Sym, BufLoc) == R_MIPS_GOTREL) {<br>
+ if (config->emachine == EM_MIPS && config->relocatable &&<br>
+ target->getRelExpr(type, sym, bufLoc) == R_MIPS_GOTREL) {<br>
// Some MIPS relocations depend on "gp" value. By default,<br>
// this value has 0x7ff0 offset from a .got section. But<br>
// relocatable files produced by a complier or a linker<br>
@@ -479,13 +479,13 @@ void InputSection::copyRelocations(uint8<br>
// individual "gp" values used by each input object file.<br>
// As a workaround we add the "gp" value to the relocation<br>
// addend and save it back to the file.<br>
- Addend += Sec->getFile<ELFT>()->MipsGp0;<br>
+ addend += sec->getFile<ELFT>()->mipsGp0;<br>
}<br>
<br>
if (RelTy::IsRela)<br>
- P->r_addend = Sym.getVA(Addend) - Section->getOutputSection()->Addr;<br>
- else if (Config->Relocatable && Type != Target->NoneRel)<br>
- Sec->Relocations.push_back({R_ABS, Type, Rel.r_offset, Addend, &Sym});<br>
+ p->r_addend = sym.getVA(addend) - section->getOutputSection()->addr;<br>
+ else if (config->relocatable && type != target->noneRel)<br>
+ sec->relocations.push_back({R_ABS, type, rel.r_offset, addend, &sym});<br>
}<br>
}<br>
}<br>
@@ -495,13 +495,13 @@ void InputSection::copyRelocations(uint8<br>
// this context is the address of the place P. A further special case is that<br>
// branch relocations to an undefined weak reference resolve to the next<br>
// instruction.<br>
-static uint32_t getARMUndefinedRelativeWeakVA(RelType Type, uint32_t A,<br>
- uint32_t P) {<br>
- switch (Type) {<br>
+static uint32_t getARMUndefinedRelativeWeakVA(RelType type, uint32_t a,<br>
+ uint32_t p) {<br>
+ switch (type) {<br>
// Unresolved branch relocations to weak references resolve to next<br>
// instruction, this will be either 2 or 4 bytes on from P.<br>
case R_ARM_THM_JUMP11:<br>
- return P + 2 + A;<br>
+ return p + 2 + a;<br>
case R_ARM_CALL:<br>
case R_ARM_JUMP24:<br>
case R_ARM_PC24:<br>
@@ -509,10 +509,10 @@ static uint32_t getARMUndefinedRelativeW<br>
case R_ARM_PREL31:<br>
case R_ARM_THM_JUMP19:<br>
case R_ARM_THM_JUMP24:<br>
- return P + 4 + A;<br>
+ return p + 4 + a;<br>
case R_ARM_THM_CALL:<br>
// We don't want an interworking BLX to ARM<br>
- return P + 5 + A;<br>
+ return p + 5 + a;<br>
// Unresolved non branch pc-relative relocations<br>
// R_ARM_TARGET2 which can be resolved relatively is not present as it never<br>
// targets a weak-reference.<br>
@@ -521,29 +521,29 @@ static uint32_t getARMUndefinedRelativeW<br>
case R_ARM_REL32:<br>
case R_ARM_THM_MOVW_PREL_NC:<br>
case R_ARM_THM_MOVT_PREL:<br>
- return P + A;<br>
+ return p + a;<br>
}<br>
llvm_unreachable("ARM pc-relative relocation expected\n");<br>
}<br>
<br>
// The comment above getARMUndefinedRelativeWeakVA applies to this function.<br>
-static uint64_t getAArch64UndefinedRelativeWeakVA(uint64_t Type, uint64_t A,<br>
- uint64_t P) {<br>
- switch (Type) {<br>
+static uint64_t getAArch64UndefinedRelativeWeakVA(uint64_t type, uint64_t a,<br>
+ uint64_t p) {<br>
+ switch (type) {<br>
// Unresolved branch relocations to weak references resolve to next<br>
// instruction, this is 4 bytes on from P.<br>
case R_AARCH64_CALL26:<br>
case R_AARCH64_CONDBR19:<br>
case R_AARCH64_JUMP26:<br>
case R_AARCH64_TSTBR14:<br>
- return P + 4 + A;<br>
+ return p + 4 + a;<br>
// Unresolved non branch pc-relative relocations<br>
case R_AARCH64_PREL16:<br>
case R_AARCH64_PREL32:<br>
case R_AARCH64_PREL64:<br>
case R_AARCH64_ADR_PREL_LO21:<br>
case R_AARCH64_LD_PREL_LO19:<br>
- return P + A;<br>
+ return p + a;<br>
}<br>
llvm_unreachable("AArch64 pc-relative relocation expected\n");<br>
}<br>
@@ -555,11 +555,11 @@ static uint64_t getAArch64UndefinedRelat<br>
// The procedure call standard only defines a Read Write Position Independent<br>
// RWPI variant so in practice we should expect the static base to be the base<br>
// of the RW segment.<br>
-static uint64_t getARMStaticBase(const Symbol &Sym) {<br>
- OutputSection *OS = Sym.getOutputSection();<br>
- if (!OS || !OS->PtLoad || !OS->PtLoad->FirstSec)<br>
- fatal("SBREL relocation to " + Sym.getName() + " without static base");<br>
- return OS->PtLoad->FirstSec->Addr;<br>
+static uint64_t getARMStaticBase(const Symbol &sym) {<br>
+ OutputSection *os = sym.getOutputSection();<br>
+ if (!os || !os->ptLoad || !os->ptLoad->firstSec)<br>
+ fatal("SBREL relocation to " + sym.getName() + " without static base");<br>
+ return os->ptLoad->firstSec->addr;<br>
}<br>
<br>
// For R_RISCV_PC_INDIRECT (R_RISCV_PCREL_LO12_{I,S}), the symbol actually<br>
@@ -568,115 +568,115 @@ static uint64_t getARMStaticBase(const S<br>
//<br>
// This function returns the R_RISCV_PCREL_HI20 relocation from<br>
// R_RISCV_PCREL_LO12's symbol and addend.<br>
-static Relocation *getRISCVPCRelHi20(const Symbol *Sym, uint64_t Addend) {<br>
- const Defined *D = cast<Defined>(Sym);<br>
- if (!D->Section) {<br>
+static Relocation *getRISCVPCRelHi20(const Symbol *sym, uint64_t addend) {<br>
+ const Defined *d = cast<Defined>(sym);<br>
+ if (!d->section) {<br>
error("R_RISCV_PCREL_LO12 relocation points to an absolute symbol: " +<br>
- Sym->getName());<br>
+ sym->getName());<br>
return nullptr;<br>
}<br>
- InputSection *IS = cast<InputSection>(D->Section);<br>
+ InputSection *isec = cast<InputSection>(d->section);<br>
<br>
- if (Addend != 0)<br>
+ if (addend != 0)<br>
warn("Non-zero addend in R_RISCV_PCREL_LO12 relocation to " +<br>
- IS->getObjMsg(D->Value) + " is ignored");<br>
+ isec->getObjMsg(d->value) + " is ignored");<br>
<br>
// Relocations are sorted by offset, so we can use std::equal_range to do<br>
// binary search.<br>
- Relocation R;<br>
- R.Offset = D->Value;<br>
- auto Range =<br>
- std::equal_range(IS->Relocations.begin(), IS->Relocations.end(), R,<br>
- [](const Relocation &LHS, const Relocation &RHS) {<br>
- return LHS.Offset < RHS.Offset;<br>
+ Relocation r;<br>
+ r.offset = d->value;<br>
+ auto range =<br>
+ std::equal_range(isec->relocations.begin(), isec->relocations.end(), r,<br>
+ [](const Relocation &lhs, const Relocation &rhs) {<br>
+ return lhs.offset < rhs.offset;<br>
});<br>
<br>
- for (auto It = Range.first; It != Range.second; ++It)<br>
- if (It->Type == R_RISCV_PCREL_HI20 || It->Type == R_RISCV_GOT_HI20 ||<br>
- It->Type == R_RISCV_TLS_GD_HI20 || It->Type == R_RISCV_TLS_GOT_HI20)<br>
- return &*It;<br>
+ for (auto it = range.first; it != range.second; ++it)<br>
+ if (it->type == R_RISCV_PCREL_HI20 || it->type == R_RISCV_GOT_HI20 ||<br>
+ it->type == R_RISCV_TLS_GD_HI20 || it->type == R_RISCV_TLS_GOT_HI20)<br>
+ return &*it;<br>
<br>
- error("R_RISCV_PCREL_LO12 relocation points to " + IS->getObjMsg(D->Value) +<br>
+ error("R_RISCV_PCREL_LO12 relocation points to " + isec->getObjMsg(d->value) +<br>
" without an associated R_RISCV_PCREL_HI20 relocation");<br>
return nullptr;<br>
}<br>
<br>
// A TLS symbol's virtual address is relative to the TLS segment. Add a<br>
// target-specific adjustment to produce a thread-pointer-relative offset.<br>
-static int64_t getTlsTpOffset(const Symbol &S) {<br>
+static int64_t getTlsTpOffset(const Symbol &s) {<br>
// On targets that support TLSDESC, _TLS_MODULE_BASE_@tpoff = 0.<br>
- if (&S == ElfSym::TlsModuleBase)<br>
+ if (&s == ElfSym::tlsModuleBase)<br>
return 0;<br>
<br>
- switch (Config->EMachine) {<br>
+ switch (config->emachine) {<br>
case EM_ARM:<br>
case EM_AARCH64:<br>
// Variant 1. The thread pointer points to a TCB with a fixed 2-word size,<br>
// followed by a variable amount of alignment padding, followed by the TLS<br>
// segment.<br>
- return S.getVA(0) + alignTo(Config->Wordsize * 2, Out::TlsPhdr->p_align);<br>
+ return s.getVA(0) + alignTo(config->wordsize * 2, Out::tlsPhdr->p_align);<br>
case EM_386:<br>
case EM_X86_64:<br>
// Variant 2. The TLS segment is located just before the thread pointer.<br>
- return S.getVA(0) - alignTo(Out::TlsPhdr->p_memsz, Out::TlsPhdr->p_align);<br>
+ return s.getVA(0) - alignTo(Out::tlsPhdr->p_memsz, Out::tlsPhdr->p_align);<br>
case EM_PPC:<br>
case EM_PPC64:<br>
// The thread pointer points to a fixed offset from the start of the<br>
// executable's TLS segment. An offset of 0x7000 allows a signed 16-bit<br>
// offset to reach 0x1000 of TCB/thread-library data and 0xf000 of the<br>
// program's TLS segment.<br>
- return S.getVA(0) - 0x7000;<br>
+ return s.getVA(0) - 0x7000;<br>
case EM_RISCV:<br>
- return S.getVA(0);<br>
+ return s.getVA(0);<br>
default:<br>
llvm_unreachable("unhandled Config->EMachine");<br>
}<br>
}<br>
<br>
-static uint64_t getRelocTargetVA(const InputFile *File, RelType Type, int64_t A,<br>
- uint64_t P, const Symbol &Sym, RelExpr Expr) {<br>
- switch (Expr) {<br>
+static uint64_t getRelocTargetVA(const InputFile *file, RelType type, int64_t a,<br>
+ uint64_t p, const Symbol &sym, RelExpr expr) {<br>
+ switch (expr) {<br>
case R_ABS:<br>
case R_DTPREL:<br>
case R_RELAX_TLS_LD_TO_LE_ABS:<br>
case R_RELAX_GOT_PC_NOPIC:<br>
case R_RISCV_ADD:<br>
- return Sym.getVA(A);<br>
+ return sym.getVA(a);<br>
case R_ADDEND:<br>
- return A;<br>
+ return a;<br>
case R_ARM_SBREL:<br>
- return Sym.getVA(A) - getARMStaticBase(Sym);<br>
+ return sym.getVA(a) - getARMStaticBase(sym);<br>
case R_GOT:<br>
case R_RELAX_TLS_GD_TO_IE_ABS:<br>
- return Sym.getGotVA() + A;<br>
+ return sym.getGotVA() + a;<br>
case R_GOTONLY_PC:<br>
- return In.Got->getVA() + A - P;<br>
+ return in.got->getVA() + a - p;<br>
case R_GOTPLTONLY_PC:<br>
- return In.GotPlt->getVA() + A - P;<br>
+ return in.gotPlt->getVA() + a - p;<br>
case R_GOTREL:<br>
case R_PPC64_RELAX_TOC:<br>
- return Sym.getVA(A) - In.Got->getVA();<br>
+ return sym.getVA(a) - in.got->getVA();<br>
case R_GOTPLTREL:<br>
- return Sym.getVA(A) - In.GotPlt->getVA();<br>
+ return sym.getVA(a) - in.gotPlt->getVA();<br>
case R_GOTPLT:<br>
case R_RELAX_TLS_GD_TO_IE_GOTPLT:<br>
- return Sym.getGotVA() + A - In.GotPlt->getVA();<br>
+ return sym.getGotVA() + a - in.gotPlt->getVA();<br>
case R_TLSLD_GOT_OFF:<br>
case R_GOT_OFF:<br>
case R_RELAX_TLS_GD_TO_IE_GOT_OFF:<br>
- return Sym.getGotOffset() + A;<br>
+ return sym.getGotOffset() + a;<br>
case R_AARCH64_GOT_PAGE_PC:<br>
case R_AARCH64_RELAX_TLS_GD_TO_IE_PAGE_PC:<br>
- return getAArch64Page(Sym.getGotVA() + A) - getAArch64Page(P);<br>
+ return getAArch64Page(sym.getGotVA() + a) - getAArch64Page(p);<br>
case R_GOT_PC:<br>
case R_RELAX_TLS_GD_TO_IE:<br>
- return Sym.getGotVA() + A - P;<br>
+ return sym.getGotVA() + a - p;<br>
case R_HEXAGON_GOT:<br>
- return Sym.getGotVA() - In.GotPlt->getVA();<br>
+ return sym.getGotVA() - in.gotPlt->getVA();<br>
case R_MIPS_GOTREL:<br>
- return Sym.getVA(A) - In.MipsGot->getGp(File);<br>
+ return sym.getVA(a) - in.mipsGot->getGp(file);<br>
case R_MIPS_GOT_GP:<br>
- return In.MipsGot->getGp(File) + A;<br>
+ return in.mipsGot->getGp(file) + a;<br>
case R_MIPS_GOT_GP_PC: {<br>
// R_MIPS_LO16 expression has R_MIPS_GOT_GP_PC type iif the target<br>
// is _gp_disp symbol. In that case we should use the following<br>
@@ -685,76 +685,76 @@ static uint64_t getRelocTargetVA(const I<br>
// microMIPS variants of these relocations use slightly different<br>
// expressions: AHL + GP - P + 3 for %lo() and AHL + GP - P - 1 for %hi()<br>
// to correctly handle less-sugnificant bit of the microMIPS symbol.<br>
- uint64_t V = In.MipsGot->getGp(File) + A - P;<br>
- if (Type == R_MIPS_LO16 || Type == R_MICROMIPS_LO16)<br>
- V += 4;<br>
- if (Type == R_MICROMIPS_LO16 || Type == R_MICROMIPS_HI16)<br>
- V -= 1;<br>
- return V;<br>
+ uint64_t v = in.mipsGot->getGp(file) + a - p;<br>
+ if (type == R_MIPS_LO16 || type == R_MICROMIPS_LO16)<br>
+ v += 4;<br>
+ if (type == R_MICROMIPS_LO16 || type == R_MICROMIPS_HI16)<br>
+ v -= 1;<br>
+ return v;<br>
}<br>
case R_MIPS_GOT_LOCAL_PAGE:<br>
// If relocation against MIPS local symbol requires GOT entry, this entry<br>
// should be initialized by 'page address'. This address is high 16-bits<br>
// of sum the symbol's value and the addend.<br>
- return In.MipsGot->getVA() + In.MipsGot->getPageEntryOffset(File, Sym, A) -<br>
- In.MipsGot->getGp(File);<br>
+ return in.mipsGot->getVA() + in.mipsGot->getPageEntryOffset(file, sym, a) -<br>
+ in.mipsGot->getGp(file);<br>
case R_MIPS_GOT_OFF:<br>
case R_MIPS_GOT_OFF32:<br>
// In case of MIPS if a GOT relocation has non-zero addend this addend<br>
// should be applied to the GOT entry content not to the GOT entry offset.<br>
// That is why we use separate expression type.<br>
- return In.MipsGot->getVA() + In.MipsGot->getSymEntryOffset(File, Sym, A) -<br>
- In.MipsGot->getGp(File);<br>
+ return in.mipsGot->getVA() + in.mipsGot->getSymEntryOffset(file, sym, a) -<br>
+ in.mipsGot->getGp(file);<br>
case R_MIPS_TLSGD:<br>
- return In.MipsGot->getVA() + In.MipsGot->getGlobalDynOffset(File, Sym) -<br>
- In.MipsGot->getGp(File);<br>
+ return in.mipsGot->getVA() + in.mipsGot->getGlobalDynOffset(file, sym) -<br>
+ in.mipsGot->getGp(file);<br>
case R_MIPS_TLSLD:<br>
- return In.MipsGot->getVA() + In.MipsGot->getTlsIndexOffset(File) -<br>
- In.MipsGot->getGp(File);<br>
+ return in.mipsGot->getVA() + in.mipsGot->getTlsIndexOffset(file) -<br>
+ in.mipsGot->getGp(file);<br>
case R_AARCH64_PAGE_PC: {<br>
- uint64_t Val = Sym.isUndefWeak() ? P + A : Sym.getVA(A);<br>
- return getAArch64Page(Val) - getAArch64Page(P);<br>
+ uint64_t val = sym.isUndefWeak() ? p + a : sym.getVA(a);<br>
+ return getAArch64Page(val) - getAArch64Page(p);<br>
}<br>
case R_RISCV_PC_INDIRECT: {<br>
- if (const Relocation *HiRel = getRISCVPCRelHi20(&Sym, A))<br>
- return getRelocTargetVA(File, HiRel->Type, HiRel->Addend, Sym.getVA(),<br>
- *HiRel->Sym, HiRel->Expr);<br>
+ if (const Relocation *hiRel = getRISCVPCRelHi20(&sym, a))<br>
+ return getRelocTargetVA(file, hiRel->type, hiRel->addend, sym.getVA(),<br>
+ *hiRel->sym, hiRel->expr);<br>
return 0;<br>
}<br>
case R_PC: {<br>
- uint64_t Dest;<br>
- if (Sym.isUndefWeak()) {<br>
+ uint64_t dest;<br>
+ if (sym.isUndefWeak()) {<br>
// On ARM and AArch64 a branch to an undefined weak resolves to the<br>
// next instruction, otherwise the place.<br>
- if (Config->EMachine == EM_ARM)<br>
- Dest = getARMUndefinedRelativeWeakVA(Type, A, P);<br>
- else if (Config->EMachine == EM_AARCH64)<br>
- Dest = getAArch64UndefinedRelativeWeakVA(Type, A, P);<br>
- else if (Config->EMachine == EM_PPC)<br>
- Dest = P;<br>
+ if (config->emachine == EM_ARM)<br>
+ dest = getARMUndefinedRelativeWeakVA(type, a, p);<br>
+ else if (config->emachine == EM_AARCH64)<br>
+ dest = getAArch64UndefinedRelativeWeakVA(type, a, p);<br>
+ else if (config->emachine == EM_PPC)<br>
+ dest = p;<br>
else<br>
- Dest = Sym.getVA(A);<br>
+ dest = sym.getVA(a);<br>
} else {<br>
- Dest = Sym.getVA(A);<br>
+ dest = sym.getVA(a);<br>
}<br>
- return Dest - P;<br>
+ return dest - p;<br>
}<br>
case R_PLT:<br>
- return Sym.getPltVA() + A;<br>
+ return sym.getPltVA() + a;<br>
case R_PLT_PC:<br>
case R_PPC64_CALL_PLT:<br>
- return Sym.getPltVA() + A - P;<br>
+ return sym.getPltVA() + a - p;<br>
case R_PPC32_PLTREL:<br>
// R_PPC_PLTREL24 uses the addend (usually 0 or 0x8000) to indicate r30<br>
// stores _GLOBAL_OFFSET_TABLE_ or .got2+0x8000. The addend is ignored for<br>
// target VA compuation.<br>
- return Sym.getPltVA() - P;<br>
+ return sym.getPltVA() - p;<br>
case R_PPC64_CALL: {<br>
- uint64_t SymVA = Sym.getVA(A);<br>
+ uint64_t symVA = sym.getVA(a);<br>
// If we have an undefined weak symbol, we might get here with a symbol<br>
// address of zero. That could overflow, but the code must be unreachable,<br>
// so don't bother doing anything at all.<br>
- if (!SymVA)<br>
+ if (!symVA)<br>
return 0;<br>
<br>
// PPC64 V2 ABI describes two entry points to a function. The global entry<br>
@@ -763,12 +763,12 @@ static uint64_t getRelocTargetVA(const I<br>
// the callee. For local calls the caller and callee share the same<br>
// TOC base and so the TOC pointer initialization code should be skipped by<br>
// branching to the local entry point.<br>
- return SymVA - P + getPPC64GlobalEntryToLocalEntryOffset(Sym.StOther);<br>
+ return symVA - p + getPPC64GlobalEntryToLocalEntryOffset(sym.stOther);<br>
}<br>
case R_PPC64_TOCBASE:<br>
- return getPPC64TocBase() + A;<br>
+ return getPPC64TocBase() + a;<br>
case R_RELAX_GOT_PC:<br>
- return Sym.getVA(A) - P;<br>
+ return sym.getVA(a) - p;<br>
case R_RELAX_TLS_GD_TO_LE:<br>
case R_RELAX_TLS_IE_TO_LE:<br>
case R_RELAX_TLS_LD_TO_LE:<br>
@@ -777,35 +777,35 @@ static uint64_t getRelocTargetVA(const I<br>
// --noinhibit-exec, even a non-weak undefined reference may reach here.<br>
// Just return A, which matches R_ABS, and the behavior of some dynamic<br>
// loaders.<br>
- if (Sym.isUndefined())<br>
- return A;<br>
- return getTlsTpOffset(Sym) + A;<br>
+ if (sym.isUndefined())<br>
+ return a;<br>
+ return getTlsTpOffset(sym) + a;<br>
case R_RELAX_TLS_GD_TO_LE_NEG:<br>
case R_NEG_TLS:<br>
- if (Sym.isUndefined())<br>
- return A;<br>
- return -getTlsTpOffset(Sym) + A;<br>
+ if (sym.isUndefined())<br>
+ return a;<br>
+ return -getTlsTpOffset(sym) + a;<br>
case R_SIZE:<br>
- return Sym.getSize() + A;<br>
+ return sym.getSize() + a;<br>
case R_TLSDESC:<br>
- return In.Got->getGlobalDynAddr(Sym) + A;<br>
+ return in.got->getGlobalDynAddr(sym) + a;<br>
case R_TLSDESC_PC:<br>
- return In.Got->getGlobalDynAddr(Sym) + A - P;<br>
+ return in.got->getGlobalDynAddr(sym) + a - p;<br>
case R_AARCH64_TLSDESC_PAGE:<br>
- return getAArch64Page(In.Got->getGlobalDynAddr(Sym) + A) -<br>
- getAArch64Page(P);<br>
+ return getAArch64Page(in.got->getGlobalDynAddr(sym) + a) -<br>
+ getAArch64Page(p);<br>
case R_TLSGD_GOT:<br>
- return In.Got->getGlobalDynOffset(Sym) + A;<br>
+ return in.got->getGlobalDynOffset(sym) + a;<br>
case R_TLSGD_GOTPLT:<br>
- return In.Got->getVA() + In.Got->getGlobalDynOffset(Sym) + A - In.GotPlt->getVA();<br>
+ return in.got->getVA() + in.got->getGlobalDynOffset(sym) + a - in.gotPlt->getVA();<br>
case R_TLSGD_PC:<br>
- return In.Got->getGlobalDynAddr(Sym) + A - P;<br>
+ return in.got->getGlobalDynAddr(sym) + a - p;<br>
case R_TLSLD_GOTPLT:<br>
- return In.Got->getVA() + In.Got->getTlsIndexOff() + A - In.GotPlt->getVA();<br>
+ return in.got->getVA() + in.got->getTlsIndexOff() + a - in.gotPlt->getVA();<br>
case R_TLSLD_GOT:<br>
- return In.Got->getTlsIndexOff() + A;<br>
+ return in.got->getTlsIndexOff() + a;<br>
case R_TLSLD_PC:<br>
- return In.Got->getTlsIndexVA() + A - P;<br>
+ return in.got->getTlsIndexVA() + a - p;<br>
default:<br>
llvm_unreachable("invalid expression");<br>
}<br>
@@ -819,36 +819,36 @@ static uint64_t getRelocTargetVA(const I<br>
// So, we handle relocations for non-alloc sections directly in this<br>
// function as a performance optimization.<br>
template <class ELFT, class RelTy><br>
-void InputSection::relocateNonAlloc(uint8_t *Buf, ArrayRef<RelTy> Rels) {<br>
- const unsigned Bits = sizeof(typename ELFT::uint) * 8;<br>
+void InputSection::relocateNonAlloc(uint8_t *buf, ArrayRef<RelTy> rels) {<br>
+ const unsigned bits = sizeof(typename ELFT::uint) * 8;<br>
<br>
- for (const RelTy &Rel : Rels) {<br>
- RelType Type = Rel.getType(Config->IsMips64EL);<br>
+ for (const RelTy &rel : rels) {<br>
+ RelType type = rel.getType(config->isMips64EL);<br>
<br>
// GCC 8.0 or earlier have a bug that they emit R_386_GOTPC relocations<br>
// against _GLOBAL_OFFSET_TABLE_ for .debug_info. The bug has been fixed<br>
// in 2017 (<a href="https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82630" rel="noreferrer" target="_blank">https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82630</a>), but we<br>
// need to keep this bug-compatible code for a while.<br>
- if (Config->EMachine == EM_386 && Type == R_386_GOTPC)<br>
+ if (config->emachine == EM_386 && type == R_386_GOTPC)<br>
continue;<br>
<br>
- uint64_t Offset = getOffset(Rel.r_offset);<br>
- uint8_t *BufLoc = Buf + Offset;<br>
- int64_t Addend = getAddend<ELFT>(Rel);<br>
+ uint64_t offset = getOffset(rel.r_offset);<br>
+ uint8_t *bufLoc = buf + offset;<br>
+ int64_t addend = getAddend<ELFT>(rel);<br>
if (!RelTy::IsRela)<br>
- Addend += Target->getImplicitAddend(BufLoc, Type);<br>
+ addend += target->getImplicitAddend(bufLoc, type);<br>
<br>
- Symbol &Sym = getFile<ELFT>()->getRelocTargetSym(Rel);<br>
- RelExpr Expr = Target->getRelExpr(Type, Sym, BufLoc);<br>
- if (Expr == R_NONE)<br>
+ Symbol &sym = getFile<ELFT>()->getRelocTargetSym(rel);<br>
+ RelExpr expr = target->getRelExpr(type, sym, bufLoc);<br>
+ if (expr == R_NONE)<br>
continue;<br>
<br>
- if (Expr != R_ABS && Expr != R_DTPREL && Expr != R_RISCV_ADD) {<br>
- std::string Msg = getLocation<ELFT>(Offset) +<br>
- ": has non-ABS relocation " + toString(Type) +<br>
- " against symbol '" + toString(Sym) + "'";<br>
- if (Expr != R_PC) {<br>
- error(Msg);<br>
+ if (expr != R_ABS && expr != R_DTPREL && expr != R_RISCV_ADD) {<br>
+ std::string msg = getLocation<ELFT>(offset) +<br>
+ ": has non-ABS relocation " + toString(type) +<br>
+ " against symbol '" + toString(sym) + "'";<br>
+ if (expr != R_PC) {<br>
+ error(msg);<br>
return;<br>
}<br>
<br>
@@ -859,16 +859,16 @@ void InputSection::relocateNonAlloc(uint<br>
// relocations without any errors and relocate them as if they were at<br>
// address 0. For bug-compatibilty, we accept them with warnings. We<br>
// know Steel Bank Common Lisp as of 2018 have this bug.<br>
- warn(Msg);<br>
- Target->relocateOne(BufLoc, Type,<br>
- SignExtend64<Bits>(Sym.getVA(Addend - Offset)));<br>
+ warn(msg);<br>
+ target->relocateOne(bufLoc, type,<br>
+ SignExtend64<bits>(sym.getVA(addend - offset)));<br>
continue;<br>
}<br>
<br>
- if (Sym.isTls() && !Out::TlsPhdr)<br>
- Target->relocateOne(BufLoc, Type, 0);<br>
+ if (sym.isTls() && !Out::tlsPhdr)<br>
+ target->relocateOne(bufLoc, type, 0);<br>
else<br>
- Target->relocateOne(BufLoc, Type, SignExtend64<Bits>(Sym.getVA(Addend)));<br>
+ target->relocateOne(bufLoc, type, SignExtend64<bits>(sym.getVA(addend)));<br>
}<br>
}<br>
<br>
@@ -877,100 +877,100 @@ void InputSection::relocateNonAlloc(uint<br>
// relocations aimed to update addends. They are handled in relocateAlloc()<br>
// for allocatable sections, and this function does the same for<br>
// non-allocatable sections, such as sections with debug information.<br>
-static void relocateNonAllocForRelocatable(InputSection *Sec, uint8_t *Buf) {<br>
- const unsigned Bits = Config->Is64 ? 64 : 32;<br>
+static void relocateNonAllocForRelocatable(InputSection *sec, uint8_t *buf) {<br>
+ const unsigned bits = config->is64 ? 64 : 32;<br>
<br>
- for (const Relocation &Rel : Sec->Relocations) {<br>
+ for (const Relocation &rel : sec->relocations) {<br>
// InputSection::copyRelocations() adds only R_ABS relocations.<br>
- assert(Rel.Expr == R_ABS);<br>
- uint8_t *BufLoc = Buf + Rel.Offset + Sec->OutSecOff;<br>
- uint64_t TargetVA = SignExtend64(Rel.Sym->getVA(Rel.Addend), Bits);<br>
- Target->relocateOne(BufLoc, Rel.Type, TargetVA);<br>
+ assert(rel.expr == R_ABS);<br>
+ uint8_t *bufLoc = buf + rel.offset + sec->outSecOff;<br>
+ uint64_t targetVA = SignExtend64(rel.sym->getVA(rel.addend), bits);<br>
+ target->relocateOne(bufLoc, rel.type, targetVA);<br>
}<br>
}<br>
<br>
template <class ELFT><br>
-void InputSectionBase::relocate(uint8_t *Buf, uint8_t *BufEnd) {<br>
- if (Flags & SHF_EXECINSTR)<br>
- adjustSplitStackFunctionPrologues<ELFT>(Buf, BufEnd);<br>
+void InputSectionBase::relocate(uint8_t *buf, uint8_t *bufEnd) {<br>
+ if (flags & SHF_EXECINSTR)<br>
+ adjustSplitStackFunctionPrologues<ELFT>(buf, bufEnd);<br>
<br>
- if (Flags & SHF_ALLOC) {<br>
- relocateAlloc(Buf, BufEnd);<br>
+ if (flags & SHF_ALLOC) {<br>
+ relocateAlloc(buf, bufEnd);<br>
return;<br>
}<br>
<br>
- auto *Sec = cast<InputSection>(this);<br>
- if (Config->Relocatable)<br>
- relocateNonAllocForRelocatable(Sec, Buf);<br>
- else if (Sec->AreRelocsRela)<br>
- Sec->relocateNonAlloc<ELFT>(Buf, Sec->template relas<ELFT>());<br>
+ auto *sec = cast<InputSection>(this);<br>
+ if (config->relocatable)<br>
+ relocateNonAllocForRelocatable(sec, buf);<br>
+ else if (sec->areRelocsRela)<br>
+ sec->relocateNonAlloc<ELFT>(buf, sec->template relas<ELFT>());<br>
else<br>
- Sec->relocateNonAlloc<ELFT>(Buf, Sec->template rels<ELFT>());<br>
+ sec->relocateNonAlloc<ELFT>(buf, sec->template rels<ELFT>());<br>
}<br>
<br>
-void InputSectionBase::relocateAlloc(uint8_t *Buf, uint8_t *BufEnd) {<br>
- assert(Flags & SHF_ALLOC);<br>
- const unsigned Bits = Config->Wordsize * 8;<br>
-<br>
- for (const Relocation &Rel : Relocations) {<br>
- uint64_t Offset = Rel.Offset;<br>
- if (auto *Sec = dyn_cast<InputSection>(this))<br>
- Offset += Sec->OutSecOff;<br>
- uint8_t *BufLoc = Buf + Offset;<br>
- RelType Type = Rel.Type;<br>
-<br>
- uint64_t AddrLoc = getOutputSection()->Addr + Offset;<br>
- RelExpr Expr = Rel.Expr;<br>
- uint64_t TargetVA = SignExtend64(<br>
- getRelocTargetVA(File, Type, Rel.Addend, AddrLoc, *Rel.Sym, Expr),<br>
- Bits);<br>
+void InputSectionBase::relocateAlloc(uint8_t *buf, uint8_t *bufEnd) {<br>
+ assert(flags & SHF_ALLOC);<br>
+ const unsigned bits = config->wordsize * 8;<br>
+<br>
+ for (const Relocation &rel : relocations) {<br>
+ uint64_t offset = rel.offset;<br>
+ if (auto *sec = dyn_cast<InputSection>(this))<br>
+ offset += sec->outSecOff;<br>
+ uint8_t *bufLoc = buf + offset;<br>
+ RelType type = rel.type;<br>
+<br>
+ uint64_t addrLoc = getOutputSection()->addr + offset;<br>
+ RelExpr expr = rel.expr;<br>
+ uint64_t targetVA = SignExtend64(<br>
+ getRelocTargetVA(file, type, rel.addend, addrLoc, *rel.sym, expr),<br>
+ bits);<br>
<br>
- switch (Expr) {<br>
+ switch (expr) {<br>
case R_RELAX_GOT_PC:<br>
case R_RELAX_GOT_PC_NOPIC:<br>
- Target->relaxGot(BufLoc, Type, TargetVA);<br>
+ target->relaxGot(bufLoc, type, targetVA);<br>
break;<br>
case R_PPC64_RELAX_TOC:<br>
- if (!tryRelaxPPC64TocIndirection(Type, Rel, BufLoc))<br>
- Target->relocateOne(BufLoc, Type, TargetVA);<br>
+ if (!tryRelaxPPC64TocIndirection(type, rel, bufLoc))<br>
+ target->relocateOne(bufLoc, type, targetVA);<br>
break;<br>
case R_RELAX_TLS_IE_TO_LE:<br>
- Target->relaxTlsIeToLe(BufLoc, Type, TargetVA);<br>
+ target->relaxTlsIeToLe(bufLoc, type, targetVA);<br>
break;<br>
case R_RELAX_TLS_LD_TO_LE:<br>
case R_RELAX_TLS_LD_TO_LE_ABS:<br>
- Target->relaxTlsLdToLe(BufLoc, Type, TargetVA);<br>
+ target->relaxTlsLdToLe(bufLoc, type, targetVA);<br>
break;<br>
case R_RELAX_TLS_GD_TO_LE:<br>
case R_RELAX_TLS_GD_TO_LE_NEG:<br>
- Target->relaxTlsGdToLe(BufLoc, Type, TargetVA);<br>
+ target->relaxTlsGdToLe(bufLoc, type, targetVA);<br>
break;<br>
case R_AARCH64_RELAX_TLS_GD_TO_IE_PAGE_PC:<br>
case R_RELAX_TLS_GD_TO_IE:<br>
case R_RELAX_TLS_GD_TO_IE_ABS:<br>
case R_RELAX_TLS_GD_TO_IE_GOT_OFF:<br>
case R_RELAX_TLS_GD_TO_IE_GOTPLT:<br>
- Target->relaxTlsGdToIe(BufLoc, Type, TargetVA);<br>
+ target->relaxTlsGdToIe(bufLoc, type, targetVA);<br>
break;<br>
case R_PPC64_CALL:<br>
// If this is a call to __tls_get_addr, it may be part of a TLS<br>
// sequence that has been relaxed and turned into a nop. In this<br>
// case, we don't want to handle it as a call.<br>
- if (read32(BufLoc) == 0x60000000) // nop<br>
+ if (read32(bufLoc) == 0x60000000) // nop<br>
break;<br>
<br>
// Patch a nop (0x60000000) to a ld.<br>
- if (Rel.Sym->NeedsTocRestore) {<br>
- if (BufLoc + 8 > BufEnd || read32(BufLoc + 4) != 0x60000000) {<br>
- error(getErrorLocation(BufLoc) + "call lacks nop, can't restore toc");<br>
+ if (rel.sym->needsTocRestore) {<br>
+ if (bufLoc + 8 > bufEnd || read32(bufLoc + 4) != 0x60000000) {<br>
+ error(getErrorLocation(bufLoc) + "call lacks nop, can't restore toc");<br>
break;<br>
}<br>
- write32(BufLoc + 4, 0xe8410018); // ld %r2, 24(%r1)<br>
+ write32(bufLoc + 4, 0xe8410018); // ld %r2, 24(%r1)<br>
}<br>
- Target->relocateOne(BufLoc, Type, TargetVA);<br>
+ target->relocateOne(bufLoc, type, targetVA);<br>
break;<br>
default:<br>
- Target->relocateOne(BufLoc, Type, TargetVA);<br>
+ target->relocateOne(bufLoc, type, targetVA);<br>
break;<br>
}<br>
}<br>
@@ -979,44 +979,44 @@ void InputSectionBase::relocateAlloc(uin<br>
// For each function-defining prologue, find any calls to __morestack,<br>
// and replace them with calls to __morestack_non_split.<br>
static void switchMorestackCallsToMorestackNonSplit(<br>
- DenseSet<Defined *> &Prologues, std::vector<Relocation *> &MorestackCalls) {<br>
+ DenseSet<Defined *> &prologues, std::vector<Relocation *> &morestackCalls) {<br>
<br>
// If the target adjusted a function's prologue, all calls to<br>
// __morestack inside that function should be switched to<br>
// __morestack_non_split.<br>
- Symbol *MoreStackNonSplit = Symtab->find("__morestack_non_split");<br>
- if (!MoreStackNonSplit) {<br>
+ Symbol *moreStackNonSplit = symtab->find("__morestack_non_split");<br>
+ if (!moreStackNonSplit) {<br>
error("Mixing split-stack objects requires a definition of "<br>
"__morestack_non_split");<br>
return;<br>
}<br>
<br>
// Sort both collections to compare addresses efficiently.<br>
- llvm::sort(MorestackCalls, [](const Relocation *L, const Relocation *R) {<br>
- return L->Offset < R->Offset;<br>
+ llvm::sort(morestackCalls, [](const Relocation *l, const Relocation *r) {<br>
+ return l->offset < r->offset;<br>
});<br>
- std::vector<Defined *> Functions(Prologues.begin(), Prologues.end());<br>
- llvm::sort(Functions, [](const Defined *L, const Defined *R) {<br>
- return L->Value < R->Value;<br>
+ std::vector<Defined *> functions(prologues.begin(), prologues.end());<br>
+ llvm::sort(functions, [](const Defined *l, const Defined *r) {<br>
+ return l->value < r->value;<br>
});<br>
<br>
- auto It = MorestackCalls.begin();<br>
- for (Defined *F : Functions) {<br>
+ auto it = morestackCalls.begin();<br>
+ for (Defined *f : functions) {<br>
// Find the first call to __morestack within the function.<br>
- while (It != MorestackCalls.end() && (*It)->Offset < F->Value)<br>
- ++It;<br>
+ while (it != morestackCalls.end() && (*it)->offset < f->value)<br>
+ ++it;<br>
// Adjust all calls inside the function.<br>
- while (It != MorestackCalls.end() && (*It)->Offset < F->Value + F->Size) {<br>
- (*It)->Sym = MoreStackNonSplit;<br>
- ++It;<br>
+ while (it != morestackCalls.end() && (*it)->offset < f->value + f->size) {<br>
+ (*it)->sym = moreStackNonSplit;<br>
+ ++it;<br>
}<br>
}<br>
}<br>
<br>
-static bool enclosingPrologueAttempted(uint64_t Offset,<br>
- const DenseSet<Defined *> &Prologues) {<br>
- for (Defined *F : Prologues)<br>
- if (F->Value <= Offset && Offset < F->Value + F->Size)<br>
+static bool enclosingPrologueAttempted(uint64_t offset,<br>
+ const DenseSet<Defined *> &prologues) {<br>
+ for (Defined *f : prologues)<br>
+ if (f->value <= offset && offset < f->value + f->size)<br>
return true;<br>
return false;<br>
}<br>
@@ -1026,30 +1026,30 @@ static bool enclosingPrologueAttempted(u<br>
// adjusted to ensure that the called function will have enough stack<br>
// available. Find those functions, and adjust their prologues.<br>
template <class ELFT><br>
-void InputSectionBase::adjustSplitStackFunctionPrologues(uint8_t *Buf,<br>
- uint8_t *End) {<br>
- if (!getFile<ELFT>()->SplitStack)<br>
+void InputSectionBase::adjustSplitStackFunctionPrologues(uint8_t *buf,<br>
+ uint8_t *end) {<br>
+ if (!getFile<ELFT>()->splitStack)<br>
return;<br>
- DenseSet<Defined *> Prologues;<br>
- std::vector<Relocation *> MorestackCalls;<br>
+ DenseSet<Defined *> prologues;<br>
+ std::vector<Relocation *> morestackCalls;<br>
<br>
- for (Relocation &Rel : Relocations) {<br>
+ for (Relocation &rel : relocations) {<br>
// Local symbols can't possibly be cross-calls, and should have been<br>
// resolved long before this line.<br>
- if (Rel.Sym->isLocal())<br>
+ if (rel.sym->isLocal())<br>
continue;<br>
<br>
// Ignore calls into the split-stack api.<br>
- if (Rel.Sym->getName().startswith("__morestack")) {<br>
- if (Rel.Sym->getName().equals("__morestack"))<br>
- MorestackCalls.push_back(&Rel);<br>
+ if (rel.sym->getName().startswith("__morestack")) {<br>
+ if (rel.sym->getName().equals("__morestack"))<br>
+ morestackCalls.push_back(&rel);<br>
continue;<br>
}<br>
<br>
// A relocation to non-function isn't relevant. Sometimes<br>
// __morestack is not marked as a function, so this check comes<br>
// after the name check.<br>
- if (Rel.Sym->Type != STT_FUNC)<br>
+ if (rel.sym->type != STT_FUNC)<br>
continue;<br>
<br>
// If the callee's-file was compiled with split stack, nothing to do. In<br>
@@ -1057,117 +1057,117 @@ void InputSectionBase::adjustSplitStackF<br>
// being produced". So an "undefined" symbol might be provided by a shared<br>
// library. It is not possible to tell how such symbols were compiled, so be<br>
// conservative.<br>
- if (Defined *D = dyn_cast<Defined>(Rel.Sym))<br>
- if (InputSection *IS = cast_or_null<InputSection>(D->Section))<br>
- if (!IS || !IS->getFile<ELFT>() || IS->getFile<ELFT>()->SplitStack)<br>
+ if (Defined *d = dyn_cast<Defined>(rel.sym))<br>
+ if (InputSection *isec = cast_or_null<InputSection>(d->section))<br>
+ if (!isec || !isec->getFile<ELFT>() || isec->getFile<ELFT>()->splitStack)<br>
continue;<br>
<br>
- if (enclosingPrologueAttempted(Rel.Offset, Prologues))<br>
+ if (enclosingPrologueAttempted(rel.offset, prologues))<br>
continue;<br>
<br>
- if (Defined *F = getEnclosingFunction<ELFT>(Rel.Offset)) {<br>
- Prologues.insert(F);<br>
- if (Target->adjustPrologueForCrossSplitStack(Buf + getOffset(F->Value),<br>
- End, F->StOther))<br>
+ if (Defined *f = getEnclosingFunction<ELFT>(rel.offset)) {<br>
+ prologues.insert(f);<br>
+ if (target->adjustPrologueForCrossSplitStack(buf + getOffset(f->value),<br>
+ end, f->stOther))<br>
continue;<br>
- if (!getFile<ELFT>()->SomeNoSplitStack)<br>
- error(lld::toString(this) + ": " + F->getName() +<br>
- " (with -fsplit-stack) calls " + Rel.Sym->getName() +<br>
+ if (!getFile<ELFT>()->someNoSplitStack)<br>
+ error(lld::toString(this) + ": " + f->getName() +<br>
+ " (with -fsplit-stack) calls " + rel.sym->getName() +<br>
" (without -fsplit-stack), but couldn't adjust its prologue");<br>
}<br>
}<br>
<br>
- if (Target->NeedsMoreStackNonSplit)<br>
- switchMorestackCallsToMorestackNonSplit(Prologues, MorestackCalls);<br>
+ if (target->needsMoreStackNonSplit)<br>
+ switchMorestackCallsToMorestackNonSplit(prologues, morestackCalls);<br>
}<br>
<br>
-template <class ELFT> void InputSection::writeTo(uint8_t *Buf) {<br>
- if (Type == SHT_NOBITS)<br>
+template <class ELFT> void InputSection::writeTo(uint8_t *buf) {<br>
+ if (type == SHT_NOBITS)<br>
return;<br>
<br>
- if (auto *S = dyn_cast<SyntheticSection>(this)) {<br>
- S->writeTo(Buf + OutSecOff);<br>
+ if (auto *s = dyn_cast<SyntheticSection>(this)) {<br>
+ s->writeTo(buf + outSecOff);<br>
return;<br>
}<br>
<br>
// If -r or --emit-relocs is given, then an InputSection<br>
// may be a relocation section.<br>
- if (Type == SHT_RELA) {<br>
- copyRelocations<ELFT>(Buf + OutSecOff, getDataAs<typename ELFT::Rela>());<br>
+ if (type == SHT_RELA) {<br>
+ copyRelocations<ELFT>(buf + outSecOff, getDataAs<typename ELFT::Rela>());<br>
return;<br>
}<br>
- if (Type == SHT_REL) {<br>
- copyRelocations<ELFT>(Buf + OutSecOff, getDataAs<typename ELFT::Rel>());<br>
+ if (type == SHT_REL) {<br>
+ copyRelocations<ELFT>(buf + outSecOff, getDataAs<typename ELFT::Rel>());<br>
return;<br>
}<br>
<br>
// If -r is given, we may have a SHT_GROUP section.<br>
- if (Type == SHT_GROUP) {<br>
- copyShtGroup<ELFT>(Buf + OutSecOff);<br>
+ if (type == SHT_GROUP) {<br>
+ copyShtGroup<ELFT>(buf + outSecOff);<br>
return;<br>
}<br>
<br>
// If this is a compressed section, uncompress section contents directly<br>
// to the buffer.<br>
- if (UncompressedSize >= 0) {<br>
- size_t Size = UncompressedSize;<br>
- if (Error E = zlib::uncompress(toStringRef(RawData),<br>
- (char *)(Buf + OutSecOff), Size))<br>
+ if (uncompressedSize >= 0) {<br>
+ size_t size = uncompressedSize;<br>
+ if (Error e = zlib::uncompress(toStringRef(rawData),<br>
+ (char *)(buf + outSecOff), size))<br>
fatal(toString(this) +<br>
- ": uncompress failed: " + llvm::toString(std::move(E)));<br>
- uint8_t *BufEnd = Buf + OutSecOff + Size;<br>
- relocate<ELFT>(Buf, BufEnd);<br>
+ ": uncompress failed: " + llvm::toString(std::move(e)));<br>
+ uint8_t *bufEnd = buf + outSecOff + size;<br>
+ relocate<ELFT>(buf, bufEnd);<br>
return;<br>
}<br>
<br>
// Copy section contents from source object file to output file<br>
// and then apply relocations.<br>
- memcpy(Buf + OutSecOff, data().data(), data().size());<br>
- uint8_t *BufEnd = Buf + OutSecOff + data().size();<br>
- relocate<ELFT>(Buf, BufEnd);<br>
+ memcpy(buf + outSecOff, data().data(), data().size());<br>
+ uint8_t *bufEnd = buf + outSecOff + data().size();<br>
+ relocate<ELFT>(buf, bufEnd);<br>
}<br>
<br>
-void InputSection::replace(InputSection *Other) {<br>
- Alignment = std::max(Alignment, Other->Alignment);<br>
+void InputSection::replace(InputSection *other) {<br>
+ alignment = std::max(alignment, other->alignment);<br>
<br>
// When a section is replaced with another section that was allocated to<br>
// another partition, the replacement section (and its associated sections)<br>
// need to be placed in the main partition so that both partitions will be<br>
// able to access it.<br>
- if (Partition != Other->Partition) {<br>
- Partition = 1;<br>
- for (InputSection *IS : DependentSections)<br>
- IS->Partition = 1;<br>
+ if (partition != other->partition) {<br>
+ partition = 1;<br>
+ for (InputSection *isec : dependentSections)<br>
+ isec->partition = 1;<br>
}<br>
<br>
- Other->Repl = Repl;<br>
- Other->markDead();<br>
+ other->repl = repl;<br>
+ other->markDead();<br>
}<br>
<br>
template <class ELFT><br>
-EhInputSection::EhInputSection(ObjFile<ELFT> &F,<br>
- const typename ELFT::Shdr &Header,<br>
- StringRef Name)<br>
- : InputSectionBase(F, Header, Name, InputSectionBase::EHFrame) {}<br>
+EhInputSection::EhInputSection(ObjFile<ELFT> &f,<br>
+ const typename ELFT::Shdr &header,<br>
+ StringRef name)<br>
+ : InputSectionBase(f, header, name, InputSectionBase::EHFrame) {}<br>
<br>
SyntheticSection *EhInputSection::getParent() const {<br>
- return cast_or_null<SyntheticSection>(Parent);<br>
+ return cast_or_null<SyntheticSection>(parent);<br>
}<br>
<br>
// Returns the index of the first relocation that points to a region between<br>
// Begin and Begin+Size.<br>
template <class IntTy, class RelTy><br>
-static unsigned getReloc(IntTy Begin, IntTy Size, const ArrayRef<RelTy> &Rels,<br>
- unsigned &RelocI) {<br>
+static unsigned getReloc(IntTy begin, IntTy size, const ArrayRef<RelTy> &rels,<br>
+ unsigned &relocI) {<br>
// Start search from RelocI for fast access. That works because the<br>
// relocations are sorted in .eh_frame.<br>
- for (unsigned N = Rels.size(); RelocI < N; ++RelocI) {<br>
- const RelTy &Rel = Rels[RelocI];<br>
- if (Rel.r_offset < Begin)<br>
+ for (unsigned n = rels.size(); relocI < n; ++relocI) {<br>
+ const RelTy &rel = rels[relocI];<br>
+ if (rel.r_offset < begin)<br>
continue;<br>
<br>
- if (Rel.r_offset < Begin + Size)<br>
- return RelocI;<br>
+ if (rel.r_offset < begin + size)<br>
+ return relocI;<br>
return -1;<br>
}<br>
return -1;<br>
@@ -1176,84 +1176,84 @@ static unsigned getReloc(IntTy Begin, In<br>
// .eh_frame is a sequence of CIE or FDE records.<br>
// This function splits an input section into records and returns them.<br>
template <class ELFT> void EhInputSection::split() {<br>
- if (AreRelocsRela)<br>
+ if (areRelocsRela)<br>
split<ELFT>(relas<ELFT>());<br>
else<br>
split<ELFT>(rels<ELFT>());<br>
}<br>
<br>
template <class ELFT, class RelTy><br>
-void EhInputSection::split(ArrayRef<RelTy> Rels) {<br>
- unsigned RelI = 0;<br>
- for (size_t Off = 0, End = data().size(); Off != End;) {<br>
- size_t Size = readEhRecordSize(this, Off);<br>
- Pieces.emplace_back(Off, this, Size, getReloc(Off, Size, Rels, RelI));<br>
+void EhInputSection::split(ArrayRef<RelTy> rels) {<br>
+ unsigned relI = 0;<br>
+ for (size_t off = 0, end = data().size(); off != end;) {<br>
+ size_t size = readEhRecordSize(this, off);<br>
+ pieces.emplace_back(off, this, size, getReloc(off, size, rels, relI));<br>
// The empty record is the end marker.<br>
- if (Size == 4)<br>
+ if (size == 4)<br>
break;<br>
- Off += Size;<br>
+ off += size;<br>
}<br>
}<br>
<br>
-static size_t findNull(StringRef S, size_t EntSize) {<br>
+static size_t findNull(StringRef s, size_t entSize) {<br>
// Optimize the common case.<br>
- if (EntSize == 1)<br>
- return S.find(0);<br>
+ if (entSize == 1)<br>
+ return s.find(0);<br>
<br>
- for (unsigned I = 0, N = S.size(); I != N; I += EntSize) {<br>
- const char *B = S.begin() + I;<br>
- if (std::all_of(B, B + EntSize, [](char C) { return C == 0; }))<br>
- return I;<br>
+ for (unsigned i = 0, n = s.size(); i != n; i += entSize) {<br>
+ const char *b = s.begin() + i;<br>
+ if (std::all_of(b, b + entSize, [](char c) { return c == 0; }))<br>
+ return i;<br>
}<br>
return StringRef::npos;<br>
}<br>
<br>
SyntheticSection *MergeInputSection::getParent() const {<br>
- return cast_or_null<SyntheticSection>(Parent);<br>
+ return cast_or_null<SyntheticSection>(parent);<br>
}<br>
<br>
// Split SHF_STRINGS section. Such section is a sequence of<br>
// null-terminated strings.<br>
-void MergeInputSection::splitStrings(ArrayRef<uint8_t> Data, size_t EntSize) {<br>
- size_t Off = 0;<br>
- bool IsAlloc = Flags & SHF_ALLOC;<br>
- StringRef S = toStringRef(Data);<br>
-<br>
- while (!S.empty()) {<br>
- size_t End = findNull(S, EntSize);<br>
- if (End == StringRef::npos)<br>
+void MergeInputSection::splitStrings(ArrayRef<uint8_t> data, size_t entSize) {<br>
+ size_t off = 0;<br>
+ bool isAlloc = flags & SHF_ALLOC;<br>
+ StringRef s = toStringRef(data);<br>
+<br>
+ while (!s.empty()) {<br>
+ size_t end = findNull(s, entSize);<br>
+ if (end == StringRef::npos)<br>
fatal(toString(this) + ": string is not null terminated");<br>
- size_t Size = End + EntSize;<br>
+ size_t size = end + entSize;<br>
<br>
- Pieces.emplace_back(Off, xxHash64(S.substr(0, Size)), !IsAlloc);<br>
- S = S.substr(Size);<br>
- Off += Size;<br>
+ pieces.emplace_back(off, xxHash64(s.substr(0, size)), !isAlloc);<br>
+ s = s.substr(size);<br>
+ off += size;<br>
}<br>
}<br>
<br>
// Split non-SHF_STRINGS section. Such section is a sequence of<br>
// fixed size records.<br>
-void MergeInputSection::splitNonStrings(ArrayRef<uint8_t> Data,<br>
- size_t EntSize) {<br>
- size_t Size = Data.size();<br>
- assert((Size % EntSize) == 0);<br>
- bool IsAlloc = Flags & SHF_ALLOC;<br>
+void MergeInputSection::splitNonStrings(ArrayRef<uint8_t> data,<br>
+ size_t entSize) {<br>
+ size_t size = data.size();<br>
+ assert((size % entSize) == 0);<br>
+ bool isAlloc = flags & SHF_ALLOC;<br>
<br>
- for (size_t I = 0; I != Size; I += EntSize)<br>
- Pieces.emplace_back(I, xxHash64(Data.slice(I, EntSize)), !IsAlloc);<br>
+ for (size_t i = 0; i != size; i += entSize)<br>
+ pieces.emplace_back(i, xxHash64(data.slice(i, entSize)), !isAlloc);<br>
}<br>
<br>
template <class ELFT><br>
-MergeInputSection::MergeInputSection(ObjFile<ELFT> &F,<br>
- const typename ELFT::Shdr &Header,<br>
- StringRef Name)<br>
- : InputSectionBase(F, Header, Name, InputSectionBase::Merge) {}<br>
-<br>
-MergeInputSection::MergeInputSection(uint64_t Flags, uint32_t Type,<br>
- uint64_t Entsize, ArrayRef<uint8_t> Data,<br>
- StringRef Name)<br>
- : InputSectionBase(nullptr, Flags, Type, Entsize, /*Link*/ 0, /*Info*/ 0,<br>
- /*Alignment*/ Entsize, Data, Name, SectionBase::Merge) {}<br>
+MergeInputSection::MergeInputSection(ObjFile<ELFT> &f,<br>
+ const typename ELFT::Shdr &header,<br>
+ StringRef name)<br>
+ : InputSectionBase(f, header, name, InputSectionBase::Merge) {}<br>
+<br>
+MergeInputSection::MergeInputSection(uint64_t flags, uint32_t type,<br>
+ uint64_t entsize, ArrayRef<uint8_t> data,<br>
+ StringRef name)<br>
+ : InputSectionBase(nullptr, flags, type, entsize, /*Link*/ 0, /*Info*/ 0,<br>
+ /*Alignment*/ entsize, data, name, SectionBase::Merge) {}<br>
<br>
// This function is called after we obtain a complete list of input sections<br>
// that need to be linked. This is responsible to split section contents<br>
@@ -1262,35 +1262,35 @@ MergeInputSection::MergeInputSection(uin<br>
// Note that this function is called from parallelForEach. This must be<br>
// thread-safe (i.e. no memory allocation from the pools).<br>
void MergeInputSection::splitIntoPieces() {<br>
- assert(Pieces.empty());<br>
+ assert(pieces.empty());<br>
<br>
- if (Flags & SHF_STRINGS)<br>
- splitStrings(data(), Entsize);<br>
+ if (flags & SHF_STRINGS)<br>
+ splitStrings(data(), entsize);<br>
else<br>
- splitNonStrings(data(), Entsize);<br>
+ splitNonStrings(data(), entsize);<br>
}<br>
<br>
-SectionPiece *MergeInputSection::getSectionPiece(uint64_t Offset) {<br>
- if (this->data().size() <= Offset)<br>
+SectionPiece *MergeInputSection::getSectionPiece(uint64_t offset) {<br>
+ if (this->data().size() <= offset)<br>
fatal(toString(this) + ": offset is outside the section");<br>
<br>
// If Offset is not at beginning of a section piece, it is not in the map.<br>
// In that case we need to do a binary search of the original section piece vector.<br>
- auto It = partition_point(<br>
- Pieces, [=](SectionPiece P) { return P.InputOff <= Offset; });<br>
- return &It[-1];<br>
+ auto it = partition_point(<br>
+ pieces, [=](SectionPiece p) { return p.inputOff <= offset; });<br>
+ return &it[-1];<br>
}<br>
<br>
// Returns the offset in an output section for a given input offset.<br>
// Because contents of a mergeable section is not contiguous in output,<br>
// it is not just an addition to a base output offset.<br>
-uint64_t MergeInputSection::getParentOffset(uint64_t Offset) const {<br>
+uint64_t MergeInputSection::getParentOffset(uint64_t offset) const {<br>
// If Offset is not at beginning of a section piece, it is not in the map.<br>
// In that case we need to search from the original section piece vector.<br>
- const SectionPiece &Piece =<br>
- *(const_cast<MergeInputSection *>(this)->getSectionPiece (Offset));<br>
- uint64_t Addend = Offset - Piece.InputOff;<br>
- return Piece.OutputOff + Addend;<br>
+ const SectionPiece &piece =<br>
+ *(const_cast<MergeInputSection *>(this)->getSectionPiece (offset));<br>
+ uint64_t addend = offset - piece.inputOff;<br>
+ return piece.outputOff + addend;<br>
}<br>
<br>
template InputSection::InputSection(ObjFile<ELF32LE> &, const ELF32LE::Shdr &,<br>
<br>
Modified: lld/trunk/ELF/InputSection.h<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_ELF_InputSection.h-3Frev-3D365595-26r1-3D365594-26r2-3D365595-26view-3Ddiff&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=U1bo6cxsqKIfaBAaPZKJZGg_AjRoMj8NDFVsNavasVA&e=" rel="noreferrer" target="_blank">https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_ELF_InputSection.h-3Frev-3D365595-26r1-3D365594-26r2-3D365595-26view-3Ddiff&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=U1bo6cxsqKIfaBAaPZKJZGg_AjRoMj8NDFVsNavasVA&e=</a> <br>
==============================================================================<br>
--- lld/trunk/ELF/InputSection.h (original)<br>
+++ lld/trunk/ELF/InputSection.h Tue Jul 9 22:00:37 2019<br>
@@ -31,7 +31,7 @@ class MergeSyntheticSection;<br>
template <class ELFT> class ObjFile;<br>
class OutputSection;<br>
<br>
-extern std::vector<Partition> Partitions;<br>
+extern std::vector<Partition> partitions;<br>
<br>
// This is the base class of all sections that lld handles. Some are sections in<br>
// input files, some are sections in the produced output file and some exist<br>
@@ -41,18 +41,18 @@ class SectionBase {<br>
public:<br>
enum Kind { Regular, EHFrame, Merge, Synthetic, Output };<br>
<br>
- Kind kind() const { return (Kind)SectionKind; }<br>
+ Kind kind() const { return (Kind)sectionKind; }<br>
<br>
- StringRef Name;<br>
+ StringRef name;<br>
<br>
// This pointer points to the "real" instance of this instance.<br>
// Usually Repl == this. However, if ICF merges two sections,<br>
// Repl pointer of one section points to another section. So,<br>
// if you need to get a pointer to this instance, do not use<br>
// this but instead this->Repl.<br>
- SectionBase *Repl;<br>
+ SectionBase *repl;<br>
<br>
- unsigned SectionKind : 3;<br>
+ unsigned sectionKind : 3;<br>
<br>
// The next three bit fields are only used by InputSectionBase, but we<br>
// put them here so the struct packs better.<br>
@@ -68,26 +68,26 @@ public:<br>
// .foo takes all .text sections, and .bar becomes empty. To achieve<br>
// this, we need to memorize whether a section has been placed or<br>
// not for each input section.<br>
- unsigned Assigned : 1;<br>
+ unsigned assigned : 1;<br>
<br>
- unsigned Bss : 1;<br>
+ unsigned bss : 1;<br>
<br>
// Set for sections that should not be folded by ICF.<br>
- unsigned KeepUnique : 1;<br>
+ unsigned keepUnique : 1;<br>
<br>
// The 1-indexed partition that this section is assigned to by the garbage<br>
// collector, or 0 if this section is dead. Normally there is only one<br>
// partition, so this will either be 0 or 1.<br>
- uint8_t Partition;<br>
+ uint8_t partition;<br>
elf::Partition &getPartition() const;<br>
<br>
// These corresponds to the fields in Elf_Shdr.<br>
- uint32_t Alignment;<br>
- uint64_t Flags;<br>
- uint64_t Entsize;<br>
- uint32_t Type;<br>
- uint32_t Link;<br>
- uint32_t Info;<br>
+ uint32_t alignment;<br>
+ uint64_t flags;<br>
+ uint64_t entsize;<br>
+ uint32_t type;<br>
+ uint32_t link;<br>
+ uint32_t info;<br>
<br>
OutputSection *getOutputSection();<br>
const OutputSection *getOutputSection() const {<br>
@@ -96,55 +96,55 @@ public:<br>
<br>
// Translate an offset in the input section to an offset in the output<br>
// section.<br>
- uint64_t getOffset(uint64_t Offset) const;<br>
+ uint64_t getOffset(uint64_t offset) const;<br>
<br>
- uint64_t getVA(uint64_t Offset = 0) const;<br>
+ uint64_t getVA(uint64_t offset = 0) const;<br>
<br>
- bool isLive() const { return Partition != 0; }<br>
- void markLive() { Partition = 1; }<br>
- void markDead() { Partition = 0; }<br>
+ bool isLive() const { return partition != 0; }<br>
+ void markLive() { partition = 1; }<br>
+ void markDead() { partition = 0; }<br>
<br>
protected:<br>
- SectionBase(Kind SectionKind, StringRef Name, uint64_t Flags,<br>
- uint64_t Entsize, uint64_t Alignment, uint32_t Type,<br>
- uint32_t Info, uint32_t Link)<br>
- : Name(Name), Repl(this), SectionKind(SectionKind), Assigned(false),<br>
- Bss(false), KeepUnique(false), Partition(0), Alignment(Alignment),<br>
- Flags(Flags), Entsize(Entsize), Type(Type), Link(Link), Info(Info) {}<br>
+ SectionBase(Kind sectionKind, StringRef name, uint64_t flags,<br>
+ uint64_t entsize, uint64_t alignment, uint32_t type,<br>
+ uint32_t info, uint32_t link)<br>
+ : name(name), repl(this), sectionKind(sectionKind), assigned(false),<br>
+ bss(false), keepUnique(false), partition(0), alignment(alignment),<br>
+ flags(flags), entsize(entsize), type(type), link(link), info(info) {}<br>
};<br>
<br>
// This corresponds to a section of an input file.<br>
class InputSectionBase : public SectionBase {<br>
public:<br>
template <class ELFT><br>
- InputSectionBase(ObjFile<ELFT> &File, const typename ELFT::Shdr &Header,<br>
- StringRef Name, Kind SectionKind);<br>
+ InputSectionBase(ObjFile<ELFT> &file, const typename ELFT::Shdr &header,<br>
+ StringRef name, Kind sectionKind);<br>
<br>
- InputSectionBase(InputFile *File, uint64_t Flags, uint32_t Type,<br>
- uint64_t Entsize, uint32_t Link, uint32_t Info,<br>
- uint32_t Alignment, ArrayRef<uint8_t> Data, StringRef Name,<br>
- Kind SectionKind);<br>
+ InputSectionBase(InputFile *file, uint64_t flags, uint32_t type,<br>
+ uint64_t entsize, uint32_t link, uint32_t info,<br>
+ uint32_t alignment, ArrayRef<uint8_t> data, StringRef name,<br>
+ Kind sectionKind);<br>
<br>
- static bool classof(const SectionBase *S) { return S->kind() != Output; }<br>
+ static bool classof(const SectionBase *s) { return s->kind() != Output; }<br>
<br>
// Relocations that refer to this section.<br>
- unsigned NumRelocations : 31;<br>
- unsigned AreRelocsRela : 1;<br>
- const void *FirstRelocation = nullptr;<br>
+ unsigned numRelocations : 31;<br>
+ unsigned areRelocsRela : 1;<br>
+ const void *firstRelocation = nullptr;<br>
<br>
// The file which contains this section. Its dynamic type is always<br>
// ObjFile<ELFT>, but in order to avoid ELFT, we use InputFile as<br>
// its static type.<br>
- InputFile *File;<br>
+ InputFile *file;<br>
<br>
template <class ELFT> ObjFile<ELFT> *getFile() const {<br>
- return cast_or_null<ObjFile<ELFT>>(File);<br>
+ return cast_or_null<ObjFile<ELFT>>(file);<br>
}<br>
<br>
ArrayRef<uint8_t> data() const {<br>
- if (UncompressedSize >= 0)<br>
+ if (uncompressedSize >= 0)<br>
uncompress();<br>
- return RawData;<br>
+ return rawData;<br>
}<br>
<br>
uint64_t getOffsetInFile() const;<br>
@@ -153,24 +153,24 @@ public:<br>
// like .eh_frame and merge sections are first combined into a<br>
// synthetic section that is then added to an output section. In all<br>
// cases this points one level up.<br>
- SectionBase *Parent = nullptr;<br>
+ SectionBase *parent = nullptr;<br>
<br>
template <class ELFT> ArrayRef<typename ELFT::Rel> rels() const {<br>
- assert(!AreRelocsRela);<br>
+ assert(!areRelocsRela);<br>
return llvm::makeArrayRef(<br>
- static_cast<const typename ELFT::Rel *>(FirstRelocation),<br>
- NumRelocations);<br>
+ static_cast<const typename ELFT::Rel *>(firstRelocation),<br>
+ numRelocations);<br>
}<br>
<br>
template <class ELFT> ArrayRef<typename ELFT::Rela> relas() const {<br>
- assert(AreRelocsRela);<br>
+ assert(areRelocsRela);<br>
return llvm::makeArrayRef(<br>
- static_cast<const typename ELFT::Rela *>(FirstRelocation),<br>
- NumRelocations);<br>
+ static_cast<const typename ELFT::Rela *>(firstRelocation),<br>
+ numRelocations);<br>
}<br>
<br>
// InputSections that are dependent on us (reverse dependency for GC)<br>
- llvm::TinyPtrVector<InputSection *> DependentSections;<br>
+ llvm::TinyPtrVector<InputSection *> dependentSections;<br>
<br>
// Returns the size of this section (even if this is a common or BSS.)<br>
size_t getSize() const;<br>
@@ -180,23 +180,23 @@ public:<br>
// Get the function symbol that encloses this offset from within the<br>
// section.<br>
template <class ELFT><br>
- Defined *getEnclosingFunction(uint64_t Offset);<br>
+ Defined *getEnclosingFunction(uint64_t offset);<br>
<br>
// Returns a source location string. Used to construct an error message.<br>
- template <class ELFT> std::string getLocation(uint64_t Offset);<br>
- std::string getSrcMsg(const Symbol &Sym, uint64_t Offset);<br>
- std::string getObjMsg(uint64_t Offset);<br>
+ template <class ELFT> std::string getLocation(uint64_t offset);<br>
+ std::string getSrcMsg(const Symbol &sym, uint64_t offset);<br>
+ std::string getObjMsg(uint64_t offset);<br>
<br>
// Each section knows how to relocate itself. These functions apply<br>
// relocations, assuming that Buf points to this section's copy in<br>
// the mmap'ed output buffer.<br>
- template <class ELFT> void relocate(uint8_t *Buf, uint8_t *BufEnd);<br>
- void relocateAlloc(uint8_t *Buf, uint8_t *BufEnd);<br>
+ template <class ELFT> void relocate(uint8_t *buf, uint8_t *bufEnd);<br>
+ void relocateAlloc(uint8_t *buf, uint8_t *bufEnd);<br>
<br>
// The native ELF reloc data type is not very convenient to handle.<br>
// So we convert ELF reloc records to our own records in Relocations.cpp.<br>
// This vector contains such "cooked" relocations.<br>
- std::vector<Relocation> Relocations;<br>
+ std::vector<Relocation> relocations;<br>
<br>
// A function compiled with -fsplit-stack calling a function<br>
// compiled without -fsplit-stack needs its prologue adjusted. Find<br>
@@ -204,26 +204,26 @@ public:<br>
// to relocation. See <a href="https://gcc.gnu.org/wiki/SplitStacks" rel="noreferrer" target="_blank">https://gcc.gnu.org/wiki/SplitStacks</a> for more<br>
// information.<br>
template <typename ELFT><br>
- void adjustSplitStackFunctionPrologues(uint8_t *Buf, uint8_t *End);<br>
+ void adjustSplitStackFunctionPrologues(uint8_t *buf, uint8_t *end);<br>
<br>
<br>
template <typename T> llvm::ArrayRef<T> getDataAs() const {<br>
- size_t S = data().size();<br>
- assert(S % sizeof(T) == 0);<br>
- return llvm::makeArrayRef<T>((const T *)data().data(), S / sizeof(T));<br>
+ size_t s = data().size();<br>
+ assert(s % sizeof(T) == 0);<br>
+ return llvm::makeArrayRef<T>((const T *)data().data(), s / sizeof(T));<br>
}<br>
<br>
protected:<br>
void parseCompressedHeader();<br>
void uncompress() const;<br>
<br>
- mutable ArrayRef<uint8_t> RawData;<br>
+ mutable ArrayRef<uint8_t> rawData;<br>
<br>
// This field stores the uncompressed size of the compressed data in RawData,<br>
// or -1 if RawData is not compressed (either because the section wasn't<br>
// compressed in the first place, or because we ended up uncompressing it).<br>
// Since the feature is not used often, this is usually -1.<br>
- mutable int64_t UncompressedSize = -1;<br>
+ mutable int64_t uncompressedSize = -1;<br>
};<br>
<br>
// SectionPiece represents a piece of splittable section contents.<br>
@@ -231,13 +231,13 @@ protected:<br>
// have to be as compact as possible, which is why we don't store the size (can<br>
// be found by looking at the next one).<br>
struct SectionPiece {<br>
- SectionPiece(size_t Off, uint32_t Hash, bool Live)<br>
- : InputOff(Off), Live(Live || !Config->GcSections), Hash(Hash >> 1) {}<br>
+ SectionPiece(size_t off, uint32_t hash, bool live)<br>
+ : inputOff(off), live(live || !config->gcSections), hash(hash >> 1) {}<br>
<br>
- uint32_t InputOff;<br>
- uint32_t Live : 1;<br>
- uint32_t Hash : 31;<br>
- uint64_t OutputOff = 0;<br>
+ uint32_t inputOff;<br>
+ uint32_t live : 1;<br>
+ uint32_t hash : 31;<br>
+ uint64_t outputOff = 0;<br>
};<br>
<br>
static_assert(sizeof(SectionPiece) == 16, "SectionPiece is too big");<br>
@@ -246,74 +246,74 @@ static_assert(sizeof(SectionPiece) == 16<br>
class MergeInputSection : public InputSectionBase {<br>
public:<br>
template <class ELFT><br>
- MergeInputSection(ObjFile<ELFT> &F, const typename ELFT::Shdr &Header,<br>
- StringRef Name);<br>
- MergeInputSection(uint64_t Flags, uint32_t Type, uint64_t Entsize,<br>
- ArrayRef<uint8_t> Data, StringRef Name);<br>
+ MergeInputSection(ObjFile<ELFT> &f, const typename ELFT::Shdr &header,<br>
+ StringRef name);<br>
+ MergeInputSection(uint64_t flags, uint32_t type, uint64_t entsize,<br>
+ ArrayRef<uint8_t> data, StringRef name);<br>
<br>
- static bool classof(const SectionBase *S) { return S->kind() == Merge; }<br>
+ static bool classof(const SectionBase *s) { return s->kind() == Merge; }<br>
void splitIntoPieces();<br>
<br>
// Translate an offset in the input section to an offset in the parent<br>
// MergeSyntheticSection.<br>
- uint64_t getParentOffset(uint64_t Offset) const;<br>
+ uint64_t getParentOffset(uint64_t offset) const;<br>
<br>
// Splittable sections are handled as a sequence of data<br>
// rather than a single large blob of data.<br>
- std::vector<SectionPiece> Pieces;<br>
+ std::vector<SectionPiece> pieces;<br>
<br>
// Returns I'th piece's data. This function is very hot when<br>
// string merging is enabled, so we want to inline.<br>
LLVM_ATTRIBUTE_ALWAYS_INLINE<br>
- llvm::CachedHashStringRef getData(size_t I) const {<br>
- size_t Begin = Pieces[I].InputOff;<br>
- size_t End =<br>
- (Pieces.size() - 1 == I) ? data().size() : Pieces[I + 1].InputOff;<br>
- return {toStringRef(data().slice(Begin, End - Begin)), Pieces[I].Hash};<br>
+ llvm::CachedHashStringRef getData(size_t i) const {<br>
+ size_t begin = pieces[i].inputOff;<br>
+ size_t end =<br>
+ (pieces.size() - 1 == i) ? data().size() : pieces[i + 1].inputOff;<br>
+ return {toStringRef(data().slice(begin, end - begin)), pieces[i].hash};<br>
}<br>
<br>
// Returns the SectionPiece at a given input section offset.<br>
- SectionPiece *getSectionPiece(uint64_t Offset);<br>
- const SectionPiece *getSectionPiece(uint64_t Offset) const {<br>
- return const_cast<MergeInputSection *>(this)->getSectionPiece(Offset);<br>
+ SectionPiece *getSectionPiece(uint64_t offset);<br>
+ const SectionPiece *getSectionPiece(uint64_t offset) const {<br>
+ return const_cast<MergeInputSection *>(this)->getSectionPiece(offset);<br>
}<br>
<br>
SyntheticSection *getParent() const;<br>
<br>
private:<br>
- void splitStrings(ArrayRef<uint8_t> A, size_t Size);<br>
- void splitNonStrings(ArrayRef<uint8_t> A, size_t Size);<br>
+ void splitStrings(ArrayRef<uint8_t> a, size_t size);<br>
+ void splitNonStrings(ArrayRef<uint8_t> a, size_t size);<br>
};<br>
<br>
struct EhSectionPiece {<br>
- EhSectionPiece(size_t Off, InputSectionBase *Sec, uint32_t Size,<br>
- unsigned FirstRelocation)<br>
- : InputOff(Off), Sec(Sec), Size(Size), FirstRelocation(FirstRelocation) {}<br>
+ EhSectionPiece(size_t off, InputSectionBase *sec, uint32_t size,<br>
+ unsigned firstRelocation)<br>
+ : inputOff(off), sec(sec), size(size), firstRelocation(firstRelocation) {}<br>
<br>
ArrayRef<uint8_t> data() {<br>
- return {Sec->data().data() + this->InputOff, Size};<br>
+ return {sec->data().data() + this->inputOff, size};<br>
}<br>
<br>
- size_t InputOff;<br>
- ssize_t OutputOff = -1;<br>
- InputSectionBase *Sec;<br>
- uint32_t Size;<br>
- unsigned FirstRelocation;<br>
+ size_t inputOff;<br>
+ ssize_t outputOff = -1;<br>
+ InputSectionBase *sec;<br>
+ uint32_t size;<br>
+ unsigned firstRelocation;<br>
};<br>
<br>
// This corresponds to a .eh_frame section of an input file.<br>
class EhInputSection : public InputSectionBase {<br>
public:<br>
template <class ELFT><br>
- EhInputSection(ObjFile<ELFT> &F, const typename ELFT::Shdr &Header,<br>
- StringRef Name);<br>
- static bool classof(const SectionBase *S) { return S->kind() == EHFrame; }<br>
+ EhInputSection(ObjFile<ELFT> &f, const typename ELFT::Shdr &header,<br>
+ StringRef name);<br>
+ static bool classof(const SectionBase *s) { return s->kind() == EHFrame; }<br>
template <class ELFT> void split();<br>
- template <class ELFT, class RelTy> void split(ArrayRef<RelTy> Rels);<br>
+ template <class ELFT, class RelTy> void split(ArrayRef<RelTy> rels);<br>
<br>
// Splittable sections are handled as a sequence of data<br>
// rather than a single large blob of data.<br>
- std::vector<EhSectionPiece> Pieces;<br>
+ std::vector<EhSectionPiece> pieces;<br>
<br>
SyntheticSection *getParent() const;<br>
};<br>
@@ -324,17 +324,17 @@ public:<br>
// .eh_frame. It also includes the synthetic sections themselves.<br>
class InputSection : public InputSectionBase {<br>
public:<br>
- InputSection(InputFile *F, uint64_t Flags, uint32_t Type, uint32_t Alignment,<br>
- ArrayRef<uint8_t> Data, StringRef Name, Kind K = Regular);<br>
+ InputSection(InputFile *f, uint64_t flags, uint32_t type, uint32_t alignment,<br>
+ ArrayRef<uint8_t> data, StringRef name, Kind k = Regular);<br>
template <class ELFT><br>
- InputSection(ObjFile<ELFT> &F, const typename ELFT::Shdr &Header,<br>
- StringRef Name);<br>
+ InputSection(ObjFile<ELFT> &f, const typename ELFT::Shdr &header,<br>
+ StringRef name);<br>
<br>
// Write this section to a mmap'ed file, assuming Buf is pointing to<br>
// beginning of the output section.<br>
- template <class ELFT> void writeTo(uint8_t *Buf);<br>
+ template <class ELFT> void writeTo(uint8_t *buf);<br>
<br>
- uint64_t getOffset(uint64_t Offset) const { return OutSecOff + Offset; }<br>
+ uint64_t getOffset(uint64_t offset) const { return outSecOff + offset; }<br>
<br>
OutputSection *getParent() const;<br>
<br>
@@ -342,32 +342,32 @@ public:<br>
// OutputSection's InputSection list, and is used when ordering SHF_LINK_ORDER<br>
// sections. After assignAddresses is called, it represents the offset from<br>
// the beginning of the output section this section was assigned to.<br>
- uint64_t OutSecOff = 0;<br>
+ uint64_t outSecOff = 0;<br>
<br>
- static bool classof(const SectionBase *S);<br>
+ static bool classof(const SectionBase *s);<br>
<br>
InputSectionBase *getRelocatedSection() const;<br>
<br>
template <class ELFT, class RelTy><br>
- void relocateNonAlloc(uint8_t *Buf, llvm::ArrayRef<RelTy> Rels);<br>
+ void relocateNonAlloc(uint8_t *buf, llvm::ArrayRef<RelTy> rels);<br>
<br>
// Used by ICF.<br>
- uint32_t Class[2] = {0, 0};<br>
+ uint32_t eqClass[2] = {0, 0};<br>
<br>
// Called by ICF to merge two input sections.<br>
- void replace(InputSection *Other);<br>
+ void replace(InputSection *other);<br>
<br>
- static InputSection Discarded;<br>
+ static InputSection discarded;<br>
<br>
private:<br>
template <class ELFT, class RelTy><br>
- void copyRelocations(uint8_t *Buf, llvm::ArrayRef<RelTy> Rels);<br>
+ void copyRelocations(uint8_t *buf, llvm::ArrayRef<RelTy> rels);<br>
<br>
- template <class ELFT> void copyShtGroup(uint8_t *Buf);<br>
+ template <class ELFT> void copyShtGroup(uint8_t *buf);<br>
};<br>
<br>
// The list of all input sections.<br>
-extern std::vector<InputSectionBase *> InputSections;<br>
+extern std::vector<InputSectionBase *> inputSections;<br>
<br>
} // namespace elf<br>
<br>
<br>
Modified: lld/trunk/ELF/LTO.cpp<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_ELF_LTO.cpp-3Frev-3D365595-26r1-3D365594-26r2-3D365595-26view-3Ddiff&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=kWO89q-63tIMsJ1yeTt9RdnxdsWktkbPp3oNiQlj-zI&e=" rel="noreferrer" target="_blank">https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_ELF_LTO.cpp-3Frev-3D365595-26r1-3D365594-26r2-3D365595-26view-3Ddiff&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=kWO89q-63tIMsJ1yeTt9RdnxdsWktkbPp3oNiQlj-zI&e=</a> <br>
==============================================================================<br>
--- lld/trunk/ELF/LTO.cpp (original)<br>
+++ lld/trunk/ELF/LTO.cpp Tue Jul 9 22:00:37 2019<br>
@@ -47,135 +47,135 @@ using namespace lld::elf;<br>
<br>
// Creates an empty file to store a list of object files for final<br>
// linking of distributed ThinLTO.<br>
-static std::unique_ptr<raw_fd_ostream> openFile(StringRef File) {<br>
- std::error_code EC;<br>
- auto Ret =<br>
- llvm::make_unique<raw_fd_ostream>(File, EC, sys::fs::OpenFlags::F_None);<br>
- if (EC) {<br>
- error("cannot open " + File + ": " + EC.message());<br>
+static std::unique_ptr<raw_fd_ostream> openFile(StringRef file) {<br>
+ std::error_code ec;<br>
+ auto ret =<br>
+ llvm::make_unique<raw_fd_ostream>(file, ec, sys::fs::OpenFlags::F_None);<br>
+ if (ec) {<br>
+ error("cannot open " + file + ": " + ec.message());<br>
return nullptr;<br>
}<br>
- return Ret;<br>
+ return ret;<br>
}<br>
<br>
-static std::string getThinLTOOutputFile(StringRef ModulePath) {<br>
- return lto::getThinLTOOutputFile(ModulePath,<br>
- Config->ThinLTOPrefixReplace.first,<br>
- Config->ThinLTOPrefixReplace.second);<br>
+static std::string getThinLTOOutputFile(StringRef modulePath) {<br>
+ return lto::getThinLTOOutputFile(modulePath,<br>
+ config->thinLTOPrefixReplace.first,<br>
+ config->thinLTOPrefixReplace.second);<br>
}<br>
<br>
static lto::Config createConfig() {<br>
- lto::Config C;<br>
+ lto::Config c;<br>
<br>
// LLD supports the new relocations and address-significance tables.<br>
- C.Options = initTargetOptionsFromCodeGenFlags();<br>
- C.Options.RelaxELFRelocations = true;<br>
- C.Options.EmitAddrsig = true;<br>
+ c.Options = initTargetOptionsFromCodeGenFlags();<br>
+ c.Options.RelaxELFRelocations = true;<br>
+ c.Options.EmitAddrsig = true;<br>
<br>
// Always emit a section per function/datum with LTO.<br>
- C.Options.FunctionSections = true;<br>
- C.Options.DataSections = true;<br>
+ c.Options.FunctionSections = true;<br>
+ c.Options.DataSections = true;<br>
<br>
- if (Config->Relocatable)<br>
- C.RelocModel = None;<br>
- else if (Config->Pic)<br>
- C.RelocModel = Reloc::PIC_;<br>
+ if (config->relocatable)<br>
+ c.RelocModel = None;<br>
+ else if (config->isPic)<br>
+ c.RelocModel = Reloc::PIC_;<br>
else<br>
- C.RelocModel = Reloc::Static;<br>
+ c.RelocModel = Reloc::Static;<br>
<br>
- C.CodeModel = getCodeModelFromCMModel();<br>
- C.DisableVerify = Config->DisableVerify;<br>
- C.DiagHandler = diagnosticHandler;<br>
- C.OptLevel = Config->LTOO;<br>
- C.CPU = getCPUStr();<br>
- C.MAttrs = getMAttrs();<br>
- C.CGOptLevel = args::getCGOptLevel(Config->LTOO);<br>
+ c.CodeModel = getCodeModelFromCMModel();<br>
+ c.DisableVerify = config->disableVerify;<br>
+ c.DiagHandler = diagnosticHandler;<br>
+ c.OptLevel = config->ltoo;<br>
+ c.CPU = getCPUStr();<br>
+ c.MAttrs = getMAttrs();<br>
+ c.CGOptLevel = args::getCGOptLevel(config->ltoo);<br>
<br>
// Set up a custom pipeline if we've been asked to.<br>
- C.OptPipeline = Config->LTONewPmPasses;<br>
- C.AAPipeline = Config->LTOAAPipeline;<br>
+ c.OptPipeline = config->ltoNewPmPasses;<br>
+ c.AAPipeline = config->ltoAAPipeline;<br>
<br>
// Set up optimization remarks if we've been asked to.<br>
- C.RemarksFilename = Config->OptRemarksFilename;<br>
- C.RemarksPasses = Config->OptRemarksPasses;<br>
- C.RemarksWithHotness = Config->OptRemarksWithHotness;<br>
- C.RemarksFormat = Config->OptRemarksFormat;<br>
-<br>
- C.SampleProfile = Config->LTOSampleProfile;<br>
- C.UseNewPM = Config->LTONewPassManager;<br>
- C.DebugPassManager = Config->LTODebugPassManager;<br>
- C.DwoDir = Config->DwoDir;<br>
-<br>
- C.CSIRProfile = Config->LTOCSProfileFile;<br>
- C.RunCSIRInstr = Config->LTOCSProfileGenerate;<br>
-<br>
- if (Config->EmitLLVM) {<br>
- C.PostInternalizeModuleHook = [](size_t Task, const Module &M) {<br>
- if (std::unique_ptr<raw_fd_ostream> OS = openFile(Config->OutputFile))<br>
- WriteBitcodeToFile(M, *OS, false);<br>
+ c.RemarksFilename = config->optRemarksFilename;<br>
+ c.RemarksPasses = config->optRemarksPasses;<br>
+ c.RemarksWithHotness = config->optRemarksWithHotness;<br>
+ c.RemarksFormat = config->optRemarksFormat;<br>
+<br>
+ c.SampleProfile = config->ltoSampleProfile;<br>
+ c.UseNewPM = config->ltoNewPassManager;<br>
+ c.DebugPassManager = config->ltoDebugPassManager;<br>
+ c.DwoDir = config->dwoDir;<br>
+<br>
+ c.CSIRProfile = config->ltoCSProfileFile;<br>
+ c.RunCSIRInstr = config->ltoCSProfileGenerate;<br>
+<br>
+ if (config->emitLLVM) {<br>
+ c.PostInternalizeModuleHook = [](size_t task, const Module &m) {<br>
+ if (std::unique_ptr<raw_fd_ostream> os = openFile(config->outputFile))<br>
+ WriteBitcodeToFile(m, *os, false);<br>
return false;<br>
};<br>
}<br>
<br>
- if (Config->SaveTemps)<br>
- checkError(C.addSaveTemps(Config->OutputFile.str() + ".",<br>
+ if (config->saveTemps)<br>
+ checkError(c.addSaveTemps(config->outputFile.str() + ".",<br>
/*UseInputModulePath*/ true));<br>
- return C;<br>
+ return c;<br>
}<br>
<br>
BitcodeCompiler::BitcodeCompiler() {<br>
// Initialize IndexFile.<br>
- if (!Config->ThinLTOIndexOnlyArg.empty())<br>
- IndexFile = openFile(Config->ThinLTOIndexOnlyArg);<br>
+ if (!config->thinLTOIndexOnlyArg.empty())<br>
+ indexFile = openFile(config->thinLTOIndexOnlyArg);<br>
<br>
// Initialize LTOObj.<br>
- lto::ThinBackend Backend;<br>
- if (Config->ThinLTOIndexOnly) {<br>
- auto OnIndexWrite = [&](StringRef S) { ThinIndices.erase(S); };<br>
- Backend = lto::createWriteIndexesThinBackend(<br>
- Config->ThinLTOPrefixReplace.first, Config->ThinLTOPrefixReplace.second,<br>
- Config->ThinLTOEmitImportsFiles, IndexFile.get(), OnIndexWrite);<br>
- } else if (Config->ThinLTOJobs != -1U) {<br>
- Backend = lto::createInProcessThinBackend(Config->ThinLTOJobs);<br>
+ lto::ThinBackend backend;<br>
+ if (config->thinLTOIndexOnly) {<br>
+ auto onIndexWrite = [&](StringRef s) { thinIndices.erase(s); };<br>
+ backend = lto::createWriteIndexesThinBackend(<br>
+ config->thinLTOPrefixReplace.first, config->thinLTOPrefixReplace.second,<br>
+ config->thinLTOEmitImportsFiles, indexFile.get(), onIndexWrite);<br>
+ } else if (config->thinLTOJobs != -1U) {<br>
+ backend = lto::createInProcessThinBackend(config->thinLTOJobs);<br>
}<br>
<br>
- LTOObj = llvm::make_unique<lto::LTO>(createConfig(), Backend,<br>
- Config->LTOPartitions);<br>
+ ltoObj = llvm::make_unique<lto::LTO>(createConfig(), backend,<br>
+ config->ltoPartitions);<br>
<br>
// Initialize UsedStartStop.<br>
- Symtab->forEachSymbol([&](Symbol *Sym) {<br>
- StringRef S = Sym->getName();<br>
- for (StringRef Prefix : {"__start_", "__stop_"})<br>
- if (S.startswith(Prefix))<br>
- UsedStartStop.insert(S.substr(Prefix.size()));<br>
+ symtab->forEachSymbol([&](Symbol *sym) {<br>
+ StringRef s = sym->getName();<br>
+ for (StringRef prefix : {"__start_", "__stop_"})<br>
+ if (s.startswith(prefix))<br>
+ usedStartStop.insert(s.substr(prefix.size()));<br>
});<br>
}<br>
<br>
BitcodeCompiler::~BitcodeCompiler() = default;<br>
<br>
-void BitcodeCompiler::add(BitcodeFile &F) {<br>
- lto::InputFile &Obj = *F.Obj;<br>
- bool IsExec = !Config->Shared && !Config->Relocatable;<br>
-<br>
- if (Config->ThinLTOIndexOnly)<br>
- ThinIndices.insert(Obj.getName());<br>
-<br>
- ArrayRef<Symbol *> Syms = F.getSymbols();<br>
- ArrayRef<lto::InputFile::Symbol> ObjSyms = Obj.symbols();<br>
- std::vector<lto::SymbolResolution> Resols(Syms.size());<br>
+void BitcodeCompiler::add(BitcodeFile &f) {<br>
+ lto::InputFile &obj = *f.obj;<br>
+ bool isExec = !config->shared && !config->relocatable;<br>
+<br>
+ if (config->thinLTOIndexOnly)<br>
+ thinIndices.insert(obj.getName());<br>
+<br>
+ ArrayRef<Symbol *> syms = f.getSymbols();<br>
+ ArrayRef<lto::InputFile::Symbol> objSyms = obj.symbols();<br>
+ std::vector<lto::SymbolResolution> resols(syms.size());<br>
<br>
// Provide a resolution to the LTO API for each symbol.<br>
- for (size_t I = 0, E = Syms.size(); I != E; ++I) {<br>
- Symbol *Sym = Syms[I];<br>
- const lto::InputFile::Symbol &ObjSym = ObjSyms[I];<br>
- lto::SymbolResolution &R = Resols[I];<br>
+ for (size_t i = 0, e = syms.size(); i != e; ++i) {<br>
+ Symbol *sym = syms[i];<br>
+ const lto::InputFile::Symbol &objSym = objSyms[i];<br>
+ lto::SymbolResolution &r = resols[i];<br>
<br>
// Ideally we shouldn't check for SF_Undefined but currently IRObjectFile<br>
// reports two symbols for module ASM defined. Without this check, lld<br>
// flags an undefined in IR with a definition in ASM as prevailing.<br>
// Once IRObjectFile is fixed to report only one symbol this hack can<br>
// be removed.<br>
- R.Prevailing = !ObjSym.isUndefined() && Sym->File == &F;<br>
+ r.Prevailing = !objSym.isUndefined() && sym->file == &f;<br>
<br>
// We ask LTO to preserve following global symbols:<br>
// 1) All symbols when doing relocatable link, so that them can be used<br>
@@ -183,121 +183,121 @@ void BitcodeCompiler::add(BitcodeFile &F<br>
// 2) Symbols that are used in regular objects.<br>
// 3) C named sections if we have corresponding __start_/__stop_ symbol.<br>
// 4) Symbols that are defined in bitcode files and used for dynamic linking.<br>
- R.VisibleToRegularObj = Config->Relocatable || Sym->IsUsedInRegularObj ||<br>
- (R.Prevailing && Sym->includeInDynsym()) ||<br>
- UsedStartStop.count(ObjSym.getSectionName());<br>
- const auto *DR = dyn_cast<Defined>(Sym);<br>
- R.FinalDefinitionInLinkageUnit =<br>
- (IsExec || Sym->Visibility != STV_DEFAULT) && DR &&<br>
+ r.VisibleToRegularObj = config->relocatable || sym->isUsedInRegularObj ||<br>
+ (r.Prevailing && sym->includeInDynsym()) ||<br>
+ usedStartStop.count(objSym.getSectionName());<br>
+ const auto *dr = dyn_cast<Defined>(sym);<br>
+ r.FinalDefinitionInLinkageUnit =<br>
+ (isExec || sym->visibility != STV_DEFAULT) && dr &&<br>
// Skip absolute symbols from ELF objects, otherwise PC-rel relocations<br>
// will be generated by for them, triggering linker errors.<br>
// Symbol section is always null for bitcode symbols, hence the check<br>
// for isElf(). Skip linker script defined symbols as well: they have<br>
// no File defined.<br>
- !(DR->Section == nullptr && (!Sym->File || Sym->File->isElf()));<br>
+ !(dr->section == nullptr && (!sym->file || sym->file->isElf()));<br>
<br>
- if (R.Prevailing)<br>
- Sym->replace(Undefined{nullptr, Sym->getName(), STB_GLOBAL, STV_DEFAULT,<br>
- Sym->Type});<br>
+ if (r.Prevailing)<br>
+ sym->replace(Undefined{nullptr, sym->getName(), STB_GLOBAL, STV_DEFAULT,<br>
+ sym->type});<br>
<br>
// We tell LTO to not apply interprocedural optimization for wrapped<br>
// (with --wrap) symbols because otherwise LTO would inline them while<br>
// their values are still not final.<br>
- R.LinkerRedefined = !Sym->CanInline;<br>
+ r.LinkerRedefined = !sym->canInline;<br>
}<br>
- checkError(LTOObj->add(std::move(F.Obj), Resols));<br>
+ checkError(ltoObj->add(std::move(f.obj), resols));<br>
}<br>
<br>
// If LazyObjFile has not been added to link, emit empty index files.<br>
// This is needed because this is what GNU gold plugin does and we have a<br>
// distributed build system that depends on that behavior.<br>
static void thinLTOCreateEmptyIndexFiles() {<br>
- for (LazyObjFile *F : LazyObjFiles) {<br>
- if (!isBitcode(F->MB))<br>
+ for (LazyObjFile *f : lazyObjFiles) {<br>
+ if (!isBitcode(f->mb))<br>
continue;<br>
- std::string Path = replaceThinLTOSuffix(getThinLTOOutputFile(F->getName()));<br>
- std::unique_ptr<raw_fd_ostream> OS = openFile(Path + ".thinlto.bc");<br>
- if (!OS)<br>
+ std::string path = replaceThinLTOSuffix(getThinLTOOutputFile(f->getName()));<br>
+ std::unique_ptr<raw_fd_ostream> os = openFile(path + ".thinlto.bc");<br>
+ if (!os)<br>
continue;<br>
<br>
- ModuleSummaryIndex M(/*HaveGVs*/ false);<br>
- M.setSkipModuleByDistributedBackend();<br>
- WriteIndexToFile(M, *OS);<br>
- if (Config->ThinLTOEmitImportsFiles)<br>
- openFile(Path + ".imports");<br>
+ ModuleSummaryIndex m(/*HaveGVs*/ false);<br>
+ m.setSkipModuleByDistributedBackend();<br>
+ WriteIndexToFile(m, *os);<br>
+ if (config->thinLTOEmitImportsFiles)<br>
+ openFile(path + ".imports");<br>
}<br>
}<br>
<br>
// Merge all the bitcode files we have seen, codegen the result<br>
// and return the resulting ObjectFile(s).<br>
std::vector<InputFile *> BitcodeCompiler::compile() {<br>
- unsigned MaxTasks = LTOObj->getMaxTasks();<br>
- Buf.resize(MaxTasks);<br>
- Files.resize(MaxTasks);<br>
+ unsigned maxTasks = ltoObj->getMaxTasks();<br>
+ buf.resize(maxTasks);<br>
+ files.resize(maxTasks);<br>
<br>
// The --thinlto-cache-dir option specifies the path to a directory in which<br>
// to cache native object files for ThinLTO incremental builds. If a path was<br>
// specified, configure LTO to use it as the cache directory.<br>
- lto::NativeObjectCache Cache;<br>
- if (!Config->ThinLTOCacheDir.empty())<br>
- Cache = check(<br>
- lto::localCache(Config->ThinLTOCacheDir,<br>
- [&](size_t Task, std::unique_ptr<MemoryBuffer> MB) {<br>
- Files[Task] = std::move(MB);<br>
+ lto::NativeObjectCache cache;<br>
+ if (!config->thinLTOCacheDir.empty())<br>
+ cache = check(<br>
+ lto::localCache(config->thinLTOCacheDir,<br>
+ [&](size_t task, std::unique_ptr<MemoryBuffer> mb) {<br>
+ files[task] = std::move(mb);<br>
}));<br>
<br>
- if (!BitcodeFiles.empty())<br>
- checkError(LTOObj->run(<br>
- [&](size_t Task) {<br>
+ if (!bitcodeFiles.empty())<br>
+ checkError(ltoObj->run(<br>
+ [&](size_t task) {<br>
return llvm::make_unique<lto::NativeObjectStream>(<br>
- llvm::make_unique<raw_svector_ostream>(Buf[Task]));<br>
+ llvm::make_unique<raw_svector_ostream>(buf[task]));<br>
},<br>
- Cache));<br>
+ cache));<br>
<br>
// Emit empty index files for non-indexed files<br>
- for (StringRef S : ThinIndices) {<br>
- std::string Path = getThinLTOOutputFile(S);<br>
- openFile(Path + ".thinlto.bc");<br>
- if (Config->ThinLTOEmitImportsFiles)<br>
- openFile(Path + ".imports");<br>
+ for (StringRef s : thinIndices) {<br>
+ std::string path = getThinLTOOutputFile(s);<br>
+ openFile(path + ".thinlto.bc");<br>
+ if (config->thinLTOEmitImportsFiles)<br>
+ openFile(path + ".imports");<br>
}<br>
<br>
- if (Config->ThinLTOIndexOnly) {<br>
+ if (config->thinLTOIndexOnly) {<br>
thinLTOCreateEmptyIndexFiles();<br>
<br>
- if (!Config->LTOObjPath.empty())<br>
- saveBuffer(Buf[0], Config->LTOObjPath);<br>
+ if (!config->ltoObjPath.empty())<br>
+ saveBuffer(buf[0], config->ltoObjPath);<br>
<br>
// ThinLTO with index only option is required to generate only the index<br>
// files. After that, we exit from linker and ThinLTO backend runs in a<br>
// distributed environment.<br>
- if (IndexFile)<br>
- IndexFile->close();<br>
+ if (indexFile)<br>
+ indexFile->close();<br>
return {};<br>
}<br>
<br>
- if (!Config->ThinLTOCacheDir.empty())<br>
- pruneCache(Config->ThinLTOCacheDir, Config->ThinLTOCachePolicy);<br>
+ if (!config->thinLTOCacheDir.empty())<br>
+ pruneCache(config->thinLTOCacheDir, config->thinLTOCachePolicy);<br>
<br>
- if (!Config->LTOObjPath.empty()) {<br>
- saveBuffer(Buf[0], Config->LTOObjPath);<br>
- for (unsigned I = 1; I != MaxTasks; ++I)<br>
- saveBuffer(Buf[I], Config->LTOObjPath + Twine(I));<br>
+ if (!config->ltoObjPath.empty()) {<br>
+ saveBuffer(buf[0], config->ltoObjPath);<br>
+ for (unsigned i = 1; i != maxTasks; ++i)<br>
+ saveBuffer(buf[i], config->ltoObjPath + Twine(i));<br>
}<br>
<br>
- if (Config->SaveTemps) {<br>
- saveBuffer(Buf[0], Config->OutputFile + ".lto.o");<br>
- for (unsigned I = 1; I != MaxTasks; ++I)<br>
- saveBuffer(Buf[I], Config->OutputFile + Twine(I) + ".lto.o");<br>
+ if (config->saveTemps) {<br>
+ saveBuffer(buf[0], config->outputFile + ".lto.o");<br>
+ for (unsigned i = 1; i != maxTasks; ++i)<br>
+ saveBuffer(buf[i], config->outputFile + Twine(i) + ".lto.o");<br>
}<br>
<br>
- std::vector<InputFile *> Ret;<br>
- for (unsigned I = 0; I != MaxTasks; ++I)<br>
- if (!Buf[I].empty())<br>
- Ret.push_back(createObjectFile(MemoryBufferRef(Buf[I], "lto.tmp")));<br>
-<br>
- for (std::unique_ptr<MemoryBuffer> &File : Files)<br>
- if (File)<br>
- Ret.push_back(createObjectFile(*File));<br>
- return Ret;<br>
+ std::vector<InputFile *> ret;<br>
+ for (unsigned i = 0; i != maxTasks; ++i)<br>
+ if (!buf[i].empty())<br>
+ ret.push_back(createObjectFile(MemoryBufferRef(buf[i], "lto.tmp")));<br>
+<br>
+ for (std::unique_ptr<MemoryBuffer> &file : files)<br>
+ if (file)<br>
+ ret.push_back(createObjectFile(*file));<br>
+ return ret;<br>
}<br>
<br>
Modified: lld/trunk/ELF/LTO.h<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_ELF_LTO.h-3Frev-3D365595-26r1-3D365594-26r2-3D365595-26view-3Ddiff&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=9YTjz9F8XG-rZnruLltG9-kLRSWWeUusJ07mHHyEEcM&e=" rel="noreferrer" target="_blank">https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_ELF_LTO.h-3Frev-3D365595-26r1-3D365594-26r2-3D365595-26view-3Ddiff&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=9YTjz9F8XG-rZnruLltG9-kLRSWWeUusJ07mHHyEEcM&e=</a> <br>
==============================================================================<br>
--- lld/trunk/ELF/LTO.h (original)<br>
+++ lld/trunk/ELF/LTO.h Tue Jul 9 22:00:37 2019<br>
@@ -45,16 +45,16 @@ public:<br>
BitcodeCompiler();<br>
~BitcodeCompiler();<br>
<br>
- void add(BitcodeFile &F);<br>
+ void add(BitcodeFile &f);<br>
std::vector<InputFile *> compile();<br>
<br>
private:<br>
- std::unique_ptr<llvm::lto::LTO> LTOObj;<br>
- std::vector<SmallString<0>> Buf;<br>
- std::vector<std::unique_ptr<MemoryBuffer>> Files;<br>
- llvm::DenseSet<StringRef> UsedStartStop;<br>
- std::unique_ptr<llvm::raw_fd_ostream> IndexFile;<br>
- llvm::DenseSet<StringRef> ThinIndices;<br>
+ std::unique_ptr<llvm::lto::LTO> ltoObj;<br>
+ std::vector<SmallString<0>> buf;<br>
+ std::vector<std::unique_ptr<MemoryBuffer>> files;<br>
+ llvm::DenseSet<StringRef> usedStartStop;<br>
+ std::unique_ptr<llvm::raw_fd_ostream> indexFile;<br>
+ llvm::DenseSet<StringRef> thinIndices;<br>
};<br>
} // namespace elf<br>
} // namespace lld<br>
<br>
Modified: lld/trunk/ELF/LinkerScript.cpp<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_ELF_LinkerScript.cpp-3Frev-3D365595-26r1-3D365594-26r2-3D365595-26view-3Ddiff&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=4SrLmLJ48YJv5Bg637lCBWPd4XPXgNSzzzG5xRKgd_A&e=" rel="noreferrer" target="_blank">https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_ELF_LinkerScript.cpp-3Frev-3D365595-26r1-3D365594-26r2-3D365595-26view-3Ddiff&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=4SrLmLJ48YJv5Bg637lCBWPd4XPXgNSzzzG5xRKgd_A&e=</a> <br>
==============================================================================<br>
--- lld/trunk/ELF/LinkerScript.cpp (original)<br>
+++ lld/trunk/ELF/LinkerScript.cpp Tue Jul 9 22:00:37 2019<br>
@@ -46,26 +46,26 @@ using namespace llvm::support::endian;<br>
using namespace lld;<br>
using namespace lld::elf;<br>
<br>
-LinkerScript *elf::Script;<br>
+LinkerScript *elf::script;<br>
<br>
-static uint64_t getOutputSectionVA(SectionBase *InputSec, StringRef Loc) {<br>
- if (OutputSection *OS = InputSec->getOutputSection())<br>
- return OS->Addr;<br>
- error(Loc + ": unable to evaluate expression: input section " +<br>
- InputSec->Name + " has no output section assigned");<br>
+static uint64_t getOutputSectionVA(SectionBase *inputSec, StringRef loc) {<br>
+ if (OutputSection *os = inputSec->getOutputSection())<br>
+ return os->addr;<br>
+ error(loc + ": unable to evaluate expression: input section " +<br>
+ inputSec->name + " has no output section assigned");<br>
return 0;<br>
}<br>
<br>
uint64_t ExprValue::getValue() const {<br>
- if (Sec)<br>
- return alignTo(Sec->getOffset(Val) + getOutputSectionVA(Sec, Loc),<br>
- Alignment);<br>
- return alignTo(Val, Alignment);<br>
+ if (sec)<br>
+ return alignTo(sec->getOffset(val) + getOutputSectionVA(sec, loc),<br>
+ alignment);<br>
+ return alignTo(val, alignment);<br>
}<br>
<br>
uint64_t ExprValue::getSecAddr() const {<br>
- if (Sec)<br>
- return Sec->getOffset(0) + getOutputSectionVA(Sec, Loc);<br>
+ if (sec)<br>
+ return sec->getOffset(0) + getOutputSectionVA(sec, loc);<br>
return 0;<br>
}<br>
<br>
@@ -73,100 +73,100 @@ uint64_t ExprValue::getSectionOffset() c<br>
// If the alignment is trivial, we don't have to compute the full<br>
// value to know the offset. This allows this function to succeed in<br>
// cases where the output section is not yet known.<br>
- if (Alignment == 1 && (!Sec || !Sec->getOutputSection()))<br>
- return Val;<br>
+ if (alignment == 1 && (!sec || !sec->getOutputSection()))<br>
+ return val;<br>
return getValue() - getSecAddr();<br>
}<br>
<br>
-OutputSection *LinkerScript::createOutputSection(StringRef Name,<br>
- StringRef Location) {<br>
- OutputSection *&SecRef = NameToOutputSection[Name];<br>
- OutputSection *Sec;<br>
- if (SecRef && SecRef->Location.empty()) {<br>
+OutputSection *LinkerScript::createOutputSection(StringRef name,<br>
+ StringRef location) {<br>
+ OutputSection *&secRef = nameToOutputSection[name];<br>
+ OutputSection *sec;<br>
+ if (secRef && secRef->location.empty()) {<br>
// There was a forward reference.<br>
- Sec = SecRef;<br>
+ sec = secRef;<br>
} else {<br>
- Sec = make<OutputSection>(Name, SHT_PROGBITS, 0);<br>
- if (!SecRef)<br>
- SecRef = Sec;<br>
- }<br>
- Sec->Location = Location;<br>
- return Sec;<br>
+ sec = make<OutputSection>(name, SHT_PROGBITS, 0);<br>
+ if (!secRef)<br>
+ secRef = sec;<br>
+ }<br>
+ sec->location = location;<br>
+ return sec;<br>
}<br>
<br>
-OutputSection *LinkerScript::getOrCreateOutputSection(StringRef Name) {<br>
- OutputSection *&CmdRef = NameToOutputSection[Name];<br>
- if (!CmdRef)<br>
- CmdRef = make<OutputSection>(Name, SHT_PROGBITS, 0);<br>
- return CmdRef;<br>
+OutputSection *LinkerScript::getOrCreateOutputSection(StringRef name) {<br>
+ OutputSection *&cmdRef = nameToOutputSection[name];<br>
+ if (!cmdRef)<br>
+ cmdRef = make<OutputSection>(name, SHT_PROGBITS, 0);<br>
+ return cmdRef;<br>
}<br>
<br>
// Expands the memory region by the specified size.<br>
-static void expandMemoryRegion(MemoryRegion *MemRegion, uint64_t Size,<br>
- StringRef RegionName, StringRef SecName) {<br>
- MemRegion->CurPos += Size;<br>
- uint64_t NewSize = MemRegion->CurPos - MemRegion->Origin;<br>
- if (NewSize > MemRegion->Length)<br>
- error("section '" + SecName + "' will not fit in region '" + RegionName +<br>
- "': overflowed by " + Twine(NewSize - MemRegion->Length) + " bytes");<br>
+static void expandMemoryRegion(MemoryRegion *memRegion, uint64_t size,<br>
+ StringRef regionName, StringRef secName) {<br>
+ memRegion->curPos += size;<br>
+ uint64_t newSize = memRegion->curPos - memRegion->origin;<br>
+ if (newSize > memRegion->length)<br>
+ error("section '" + secName + "' will not fit in region '" + regionName +<br>
+ "': overflowed by " + Twine(newSize - memRegion->length) + " bytes");<br>
}<br>
<br>
-void LinkerScript::expandMemoryRegions(uint64_t Size) {<br>
- if (Ctx->MemRegion)<br>
- expandMemoryRegion(Ctx->MemRegion, Size, Ctx->MemRegion->Name,<br>
- Ctx->OutSec->Name);<br>
+void LinkerScript::expandMemoryRegions(uint64_t size) {<br>
+ if (ctx->memRegion)<br>
+ expandMemoryRegion(ctx->memRegion, size, ctx->memRegion->name,<br>
+ ctx->outSec->name);<br>
// Only expand the LMARegion if it is different from MemRegion.<br>
- if (Ctx->LMARegion && Ctx->MemRegion != Ctx->LMARegion)<br>
- expandMemoryRegion(Ctx->LMARegion, Size, Ctx->LMARegion->Name,<br>
- Ctx->OutSec->Name);<br>
+ if (ctx->lmaRegion && ctx->memRegion != ctx->lmaRegion)<br>
+ expandMemoryRegion(ctx->lmaRegion, size, ctx->lmaRegion->name,<br>
+ ctx->outSec->name);<br>
}<br>
<br>
-void LinkerScript::expandOutputSection(uint64_t Size) {<br>
- Ctx->OutSec->Size += Size;<br>
- expandMemoryRegions(Size);<br>
+void LinkerScript::expandOutputSection(uint64_t size) {<br>
+ ctx->outSec->size += size;<br>
+ expandMemoryRegions(size);<br>
}<br>
<br>
-void LinkerScript::setDot(Expr E, const Twine &Loc, bool InSec) {<br>
- uint64_t Val = E().getValue();<br>
- if (Val < Dot && InSec)<br>
- error(Loc + ": unable to move location counter backward for: " +<br>
- Ctx->OutSec->Name);<br>
+void LinkerScript::setDot(Expr e, const Twine &loc, bool inSec) {<br>
+ uint64_t val = e().getValue();<br>
+ if (val < dot && inSec)<br>
+ error(loc + ": unable to move location counter backward for: " +<br>
+ ctx->outSec->name);<br>
<br>
// Update to location counter means update to section size.<br>
- if (InSec)<br>
- expandOutputSection(Val - Dot);<br>
+ if (inSec)<br>
+ expandOutputSection(val - dot);<br>
<br>
- Dot = Val;<br>
+ dot = val;<br>
}<br>
<br>
// Used for handling linker symbol assignments, for both finalizing<br>
// their values and doing early declarations. Returns true if symbol<br>
// should be defined from linker script.<br>
-static bool shouldDefineSym(SymbolAssignment *Cmd) {<br>
- if (Cmd->Name == ".")<br>
+static bool shouldDefineSym(SymbolAssignment *cmd) {<br>
+ if (cmd->name == ".")<br>
return false;<br>
<br>
- if (!Cmd->Provide)<br>
+ if (!cmd->provide)<br>
return true;<br>
<br>
// If a symbol was in PROVIDE(), we need to define it only<br>
// when it is a referenced undefined symbol.<br>
- Symbol *B = Symtab->find(Cmd->Name);<br>
- if (B && !B->isDefined())<br>
+ Symbol *b = symtab->find(cmd->name);<br>
+ if (b && !b->isDefined())<br>
return true;<br>
return false;<br>
}<br>
<br>
// This function is called from processSectionCommands,<br>
// while we are fixing the output section layout.<br>
-void LinkerScript::addSymbol(SymbolAssignment *Cmd) {<br>
- if (!shouldDefineSym(Cmd))<br>
+void LinkerScript::addSymbol(SymbolAssignment *cmd) {<br>
+ if (!shouldDefineSym(cmd))<br>
return;<br>
<br>
// Define a symbol.<br>
- ExprValue Value = Cmd->Expression();<br>
- SectionBase *Sec = Value.isAbsolute() ? nullptr : Value.Sec;<br>
- uint8_t Visibility = Cmd->Hidden ? STV_HIDDEN : STV_DEFAULT;<br>
+ ExprValue value = cmd->expression();<br>
+ SectionBase *sec = value.isAbsolute() ? nullptr : value.sec;<br>
+ uint8_t visibility = cmd->hidden ? STV_HIDDEN : STV_DEFAULT;<br>
<br>
// When this function is called, section addresses have not been<br>
// fixed yet. So, we may or may not know the value of the RHS<br>
@@ -179,73 +179,73 @@ void LinkerScript::addSymbol(SymbolAssig<br>
// We want to set symbol values early if we can. This allows us to<br>
// use symbols as variables in linker scripts. Doing so allows us to<br>
// write expressions like this: `alignment = 16; . = ALIGN(., alignment)`.<br>
- uint64_t SymValue = Value.Sec ? 0 : Value.getValue();<br>
+ uint64_t symValue = value.sec ? 0 : value.getValue();<br>
<br>
- Defined New(nullptr, Cmd->Name, STB_GLOBAL, Visibility, STT_NOTYPE, SymValue,<br>
- 0, Sec);<br>
+ Defined New(nullptr, cmd->name, STB_GLOBAL, visibility, STT_NOTYPE, symValue,<br>
+ 0, sec);<br>
<br>
- Symbol *Sym = Symtab->insert(Cmd->Name);<br>
- Sym->mergeProperties(New);<br>
- Sym->replace(New);<br>
- Cmd->Sym = cast<Defined>(Sym);<br>
+ Symbol *sym = symtab->insert(cmd->name);<br>
+ sym->mergeProperties(New);<br>
+ sym->replace(New);<br>
+ cmd->sym = cast<Defined>(sym);<br>
}<br>
<br>
// This function is called from LinkerScript::declareSymbols.<br>
// It creates a placeholder symbol if needed.<br>
-static void declareSymbol(SymbolAssignment *Cmd) {<br>
- if (!shouldDefineSym(Cmd))<br>
+static void declareSymbol(SymbolAssignment *cmd) {<br>
+ if (!shouldDefineSym(cmd))<br>
return;<br>
<br>
- uint8_t Visibility = Cmd->Hidden ? STV_HIDDEN : STV_DEFAULT;<br>
- Defined New(nullptr, Cmd->Name, STB_GLOBAL, Visibility, STT_NOTYPE, 0, 0,<br>
+ uint8_t visibility = cmd->hidden ? STV_HIDDEN : STV_DEFAULT;<br>
+ Defined New(nullptr, cmd->name, STB_GLOBAL, visibility, STT_NOTYPE, 0, 0,<br>
nullptr);<br>
<br>
// We can't calculate final value right now.<br>
- Symbol *Sym = Symtab->insert(Cmd->Name);<br>
- Sym->mergeProperties(New);<br>
- Sym->replace(New);<br>
-<br>
- Cmd->Sym = cast<Defined>(Sym);<br>
- Cmd->Provide = false;<br>
- Sym->ScriptDefined = true;<br>
+ Symbol *sym = symtab->insert(cmd->name);<br>
+ sym->mergeProperties(New);<br>
+ sym->replace(New);<br>
+<br>
+ cmd->sym = cast<Defined>(sym);<br>
+ cmd->provide = false;<br>
+ sym->scriptDefined = true;<br>
}<br>
<br>
// This method is used to handle INSERT AFTER statement. Here we rebuild<br>
// the list of script commands to mix sections inserted into.<br>
void LinkerScript::processInsertCommands() {<br>
- std::vector<BaseCommand *> V;<br>
- auto Insert = [&](std::vector<BaseCommand *> &From) {<br>
- V.insert(V.end(), From.begin(), From.end());<br>
- From.clear();<br>
+ std::vector<BaseCommand *> v;<br>
+ auto insert = [&](std::vector<BaseCommand *> &from) {<br>
+ v.insert(v.end(), from.begin(), from.end());<br>
+ from.clear();<br>
};<br>
<br>
- for (BaseCommand *Base : SectionCommands) {<br>
- if (auto *OS = dyn_cast<OutputSection>(Base)) {<br>
- Insert(InsertBeforeCommands[OS->Name]);<br>
- V.push_back(Base);<br>
- Insert(InsertAfterCommands[OS->Name]);<br>
+ for (BaseCommand *base : sectionCommands) {<br>
+ if (auto *os = dyn_cast<OutputSection>(base)) {<br>
+ insert(insertBeforeCommands[os->name]);<br>
+ v.push_back(base);<br>
+ insert(insertAfterCommands[os->name]);<br>
continue;<br>
}<br>
- V.push_back(Base);<br>
+ v.push_back(base);<br>
}<br>
<br>
- for (auto &Cmds : {InsertBeforeCommands, InsertAfterCommands})<br>
- for (const std::pair<StringRef, std::vector<BaseCommand *>> &P : Cmds)<br>
- if (!P.second.empty())<br>
- error("unable to INSERT AFTER/BEFORE " + P.first +<br>
+ for (auto &cmds : {insertBeforeCommands, insertAfterCommands})<br>
+ for (const std::pair<StringRef, std::vector<BaseCommand *>> &p : cmds)<br>
+ if (!p.second.empty())<br>
+ error("unable to INSERT AFTER/BEFORE " + p.first +<br>
": section not defined");<br>
<br>
- SectionCommands = std::move(V);<br>
+ sectionCommands = std::move(v);<br>
}<br>
<br>
// Symbols defined in script should not be inlined by LTO. At the same time<br>
// we don't know their final values until late stages of link. Here we scan<br>
// over symbol assignment commands and create placeholder symbols if needed.<br>
void LinkerScript::declareSymbols() {<br>
- assert(!Ctx);<br>
- for (BaseCommand *Base : SectionCommands) {<br>
- if (auto *Cmd = dyn_cast<SymbolAssignment>(Base)) {<br>
- declareSymbol(Cmd);<br>
+ assert(!ctx);<br>
+ for (BaseCommand *base : sectionCommands) {<br>
+ if (auto *cmd = dyn_cast<SymbolAssignment>(base)) {<br>
+ declareSymbol(cmd);<br>
continue;<br>
}<br>
<br>
@@ -253,75 +253,75 @@ void LinkerScript::declareSymbols() {<br>
// we can't say for sure if it is going to be included or not.<br>
// Skip such sections for now. Improve the checks if we ever<br>
// need symbols from that sections to be declared early.<br>
- auto *Sec = cast<OutputSection>(Base);<br>
- if (Sec->Constraint != ConstraintKind::NoConstraint)<br>
+ auto *sec = cast<OutputSection>(base);<br>
+ if (sec->constraint != ConstraintKind::NoConstraint)<br>
continue;<br>
- for (BaseCommand *Base2 : Sec->SectionCommands)<br>
- if (auto *Cmd = dyn_cast<SymbolAssignment>(Base2))<br>
- declareSymbol(Cmd);<br>
+ for (BaseCommand *base2 : sec->sectionCommands)<br>
+ if (auto *cmd = dyn_cast<SymbolAssignment>(base2))<br>
+ declareSymbol(cmd);<br>
}<br>
}<br>
<br>
// This function is called from assignAddresses, while we are<br>
// fixing the output section addresses. This function is supposed<br>
// to set the final value for a given symbol assignment.<br>
-void LinkerScript::assignSymbol(SymbolAssignment *Cmd, bool InSec) {<br>
- if (Cmd->Name == ".") {<br>
- setDot(Cmd->Expression, Cmd->Location, InSec);<br>
+void LinkerScript::assignSymbol(SymbolAssignment *cmd, bool inSec) {<br>
+ if (cmd->name == ".") {<br>
+ setDot(cmd->expression, cmd->location, inSec);<br>
return;<br>
}<br>
<br>
- if (!Cmd->Sym)<br>
+ if (!cmd->sym)<br>
return;<br>
<br>
- ExprValue V = Cmd->Expression();<br>
- if (V.isAbsolute()) {<br>
- Cmd->Sym->Section = nullptr;<br>
- Cmd->Sym->Value = V.getValue();<br>
+ ExprValue v = cmd->expression();<br>
+ if (v.isAbsolute()) {<br>
+ cmd->sym->section = nullptr;<br>
+ cmd->sym->value = v.getValue();<br>
} else {<br>
- Cmd->Sym->Section = V.Sec;<br>
- Cmd->Sym->Value = V.getSectionOffset();<br>
+ cmd->sym->section = v.sec;<br>
+ cmd->sym->value = v.getSectionOffset();<br>
}<br>
}<br>
<br>
-static std::string getFilename(InputFile *File) {<br>
- if (!File)<br>
+static std::string getFilename(InputFile *file) {<br>
+ if (!file)<br>
return "";<br>
- if (File->ArchiveName.empty())<br>
- return File->getName();<br>
- return (File->ArchiveName + "(" + File->getName() + ")").str();<br>
+ if (file->archiveName.empty())<br>
+ return file->getName();<br>
+ return (file->archiveName + "(" + file->getName() + ")").str();<br>
}<br>
<br>
-bool LinkerScript::shouldKeep(InputSectionBase *S) {<br>
- if (KeptSections.empty())<br>
+bool LinkerScript::shouldKeep(InputSectionBase *s) {<br>
+ if (keptSections.empty())<br>
return false;<br>
- std::string Filename = getFilename(S->File);<br>
- for (InputSectionDescription *ID : KeptSections)<br>
- if (ID->FilePat.match(Filename))<br>
- for (SectionPattern &P : ID->SectionPatterns)<br>
- if (P.SectionPat.match(S->Name))<br>
+ std::string filename = getFilename(s->file);<br>
+ for (InputSectionDescription *id : keptSections)<br>
+ if (id->filePat.match(filename))<br>
+ for (SectionPattern &p : id->sectionPatterns)<br>
+ if (p.sectionPat.match(s->name))<br>
return true;<br>
return false;<br>
}<br>
<br>
// A helper function for the SORT() command.<br>
static std::function<bool(InputSectionBase *, InputSectionBase *)><br>
-getComparator(SortSectionPolicy K) {<br>
- switch (K) {<br>
+getComparator(SortSectionPolicy k) {<br>
+ switch (k) {<br>
case SortSectionPolicy::Alignment:<br>
- return [](InputSectionBase *A, InputSectionBase *B) {<br>
+ return [](InputSectionBase *a, InputSectionBase *b) {<br>
// ">" is not a mistake. Sections with larger alignments are placed<br>
// before sections with smaller alignments in order to reduce the<br>
// amount of padding necessary. This is compatible with GNU.<br>
- return A->Alignment > B->Alignment;<br>
+ return a->alignment > b->alignment;<br>
};<br>
case SortSectionPolicy::Name:<br>
- return [](InputSectionBase *A, InputSectionBase *B) {<br>
- return A->Name < B->Name;<br>
+ return [](InputSectionBase *a, InputSectionBase *b) {<br>
+ return a->name < b->name;<br>
};<br>
case SortSectionPolicy::Priority:<br>
- return [](InputSectionBase *A, InputSectionBase *B) {<br>
- return getPriority(A->Name) < getPriority(B->Name);<br>
+ return [](InputSectionBase *a, InputSectionBase *b) {<br>
+ return getPriority(a->name) < getPriority(b->name);<br>
};<br>
default:<br>
llvm_unreachable("unknown sort policy");<br>
@@ -329,22 +329,22 @@ getComparator(SortSectionPolicy K) {<br>
}<br>
<br>
// A helper function for the SORT() command.<br>
-static bool matchConstraints(ArrayRef<InputSection *> Sections,<br>
- ConstraintKind Kind) {<br>
- if (Kind == ConstraintKind::NoConstraint)<br>
+static bool matchConstraints(ArrayRef<InputSection *> sections,<br>
+ ConstraintKind kind) {<br>
+ if (kind == ConstraintKind::NoConstraint)<br>
return true;<br>
<br>
- bool IsRW = llvm::any_of(<br>
- Sections, [](InputSection *Sec) { return Sec->Flags & SHF_WRITE; });<br>
+ bool isRW = llvm::any_of(<br>
+ sections, [](InputSection *sec) { return sec->flags & SHF_WRITE; });<br>
<br>
- return (IsRW && Kind == ConstraintKind::ReadWrite) ||<br>
- (!IsRW && Kind == ConstraintKind::ReadOnly);<br>
+ return (isRW && kind == ConstraintKind::ReadWrite) ||<br>
+ (!isRW && kind == ConstraintKind::ReadOnly);<br>
}<br>
<br>
-static void sortSections(MutableArrayRef<InputSection *> Vec,<br>
- SortSectionPolicy K) {<br>
- if (K != SortSectionPolicy::Default && K != SortSectionPolicy::None)<br>
- llvm::stable_sort(Vec, getComparator(K));<br>
+static void sortSections(MutableArrayRef<InputSection *> vec,<br>
+ SortSectionPolicy k) {<br>
+ if (k != SortSectionPolicy::Default && k != SortSectionPolicy::None)<br>
+ llvm::stable_sort(vec, getComparator(k));<br>
}<br>
<br>
// Sort sections as instructed by SORT-family commands and --sort-section<br>
@@ -358,29 +358,29 @@ static void sortSections(MutableArrayRef<br>
// --sort-section is handled as an inner SORT command.<br>
// 3. If one SORT command is given, and if it is SORT_NONE, don't sort.<br>
// 4. If no SORT command is given, sort according to --sort-section.<br>
-static void sortInputSections(MutableArrayRef<InputSection *> Vec,<br>
- const SectionPattern &Pat) {<br>
- if (Pat.SortOuter == SortSectionPolicy::None)<br>
+static void sortInputSections(MutableArrayRef<InputSection *> vec,<br>
+ const SectionPattern &pat) {<br>
+ if (pat.sortOuter == SortSectionPolicy::None)<br>
return;<br>
<br>
- if (Pat.SortInner == SortSectionPolicy::Default)<br>
- sortSections(Vec, Config->SortSection);<br>
+ if (pat.sortInner == SortSectionPolicy::Default)<br>
+ sortSections(vec, config->sortSection);<br>
else<br>
- sortSections(Vec, Pat.SortInner);<br>
- sortSections(Vec, Pat.SortOuter);<br>
+ sortSections(vec, pat.sortInner);<br>
+ sortSections(vec, pat.sortOuter);<br>
}<br>
<br>
// Compute and remember which sections the InputSectionDescription matches.<br>
std::vector<InputSection *><br>
-LinkerScript::computeInputSections(const InputSectionDescription *Cmd) {<br>
- std::vector<InputSection *> Ret;<br>
+LinkerScript::computeInputSections(const InputSectionDescription *cmd) {<br>
+ std::vector<InputSection *> ret;<br>
<br>
// Collects all sections that satisfy constraints of Cmd.<br>
- for (const SectionPattern &Pat : Cmd->SectionPatterns) {<br>
- size_t SizeBefore = Ret.size();<br>
+ for (const SectionPattern &pat : cmd->sectionPatterns) {<br>
+ size_t sizeBefore = ret.size();<br>
<br>
- for (InputSectionBase *Sec : InputSections) {<br>
- if (!Sec->isLive() || Sec->Assigned)<br>
+ for (InputSectionBase *sec : inputSections) {<br>
+ if (!sec->isLive() || sec->assigned)<br>
continue;<br>
<br>
// For -emit-relocs we have to ignore entries like<br>
@@ -388,59 +388,59 @@ LinkerScript::computeInputSections(const<br>
// which are common because they are in the default bfd script.<br>
// We do not ignore SHT_REL[A] linker-synthesized sections here because<br>
// want to support scripts that do custom layout for them.<br>
- if (auto *IS = dyn_cast<InputSection>(Sec))<br>
- if (IS->getRelocatedSection())<br>
+ if (auto *isec = dyn_cast<InputSection>(sec))<br>
+ if (isec->getRelocatedSection())<br>
continue;<br>
<br>
- std::string Filename = getFilename(Sec->File);<br>
- if (!Cmd->FilePat.match(Filename) ||<br>
- Pat.ExcludedFilePat.match(Filename) ||<br>
- !Pat.SectionPat.match(Sec->Name))<br>
+ std::string filename = getFilename(sec->file);<br>
+ if (!cmd->filePat.match(filename) ||<br>
+ pat.excludedFilePat.match(filename) ||<br>
+ !pat.sectionPat.match(sec->name))<br>
continue;<br>
<br>
// It is safe to assume that Sec is an InputSection<br>
// because mergeable or EH input sections have already been<br>
// handled and eliminated.<br>
- Ret.push_back(cast<InputSection>(Sec));<br>
- Sec->Assigned = true;<br>
+ ret.push_back(cast<InputSection>(sec));<br>
+ sec->assigned = true;<br>
}<br>
<br>
- sortInputSections(MutableArrayRef<InputSection *>(Ret).slice(SizeBefore),<br>
- Pat);<br>
+ sortInputSections(MutableArrayRef<InputSection *>(ret).slice(sizeBefore),<br>
+ pat);<br>
}<br>
- return Ret;<br>
+ return ret;<br>
}<br>
<br>
-void LinkerScript::discard(ArrayRef<InputSection *> V) {<br>
- for (InputSection *S : V) {<br>
- if (S == In.ShStrTab || S == Main->RelaDyn || S == Main->RelrDyn)<br>
- error("discarding " + S->Name + " section is not allowed");<br>
+void LinkerScript::discard(ArrayRef<InputSection *> v) {<br>
+ for (InputSection *s : v) {<br>
+ if (s == in.shStrTab || s == mainPart->relaDyn || s == mainPart->relrDyn)<br>
+ error("discarding " + s->name + " section is not allowed");<br>
<br>
// You can discard .hash and .gnu.hash sections by linker scripts. Since<br>
// they are synthesized sections, we need to handle them differently than<br>
// other regular sections.<br>
- if (S == Main->GnuHashTab)<br>
- Main->GnuHashTab = nullptr;<br>
- if (S == Main->HashTab)<br>
- Main->HashTab = nullptr;<br>
-<br>
- S->Assigned = false;<br>
- S->markDead();<br>
- discard(S->DependentSections);<br>
+ if (s == mainPart->gnuHashTab)<br>
+ mainPart->gnuHashTab = nullptr;<br>
+ if (s == mainPart->hashTab)<br>
+ mainPart->hashTab = nullptr;<br>
+<br>
+ s->assigned = false;<br>
+ s->markDead();<br>
+ discard(s->dependentSections);<br>
}<br>
}<br>
<br>
std::vector<InputSection *><br>
-LinkerScript::createInputSectionList(OutputSection &OutCmd) {<br>
- std::vector<InputSection *> Ret;<br>
+LinkerScript::createInputSectionList(OutputSection &outCmd) {<br>
+ std::vector<InputSection *> ret;<br>
<br>
- for (BaseCommand *Base : OutCmd.SectionCommands) {<br>
- if (auto *Cmd = dyn_cast<InputSectionDescription>(Base)) {<br>
- Cmd->Sections = computeInputSections(Cmd);<br>
- Ret.insert(Ret.end(), Cmd->Sections.begin(), Cmd->Sections.end());<br>
+ for (BaseCommand *base : outCmd.sectionCommands) {<br>
+ if (auto *cmd = dyn_cast<InputSectionDescription>(base)) {<br>
+ cmd->sections = computeInputSections(cmd);<br>
+ ret.insert(ret.end(), cmd->sections.begin(), cmd->sections.end());<br>
}<br>
}<br>
- return Ret;<br>
+ return ret;<br>
}<br>
<br>
void LinkerScript::processSectionCommands() {<br>
@@ -453,34 +453,34 @@ void LinkerScript::processSectionCommand<br>
// To handle that, create a dummy aether section that fills the void before<br>
// the linker scripts switches to another section. It has an index of one<br>
// which will map to whatever the first actual section is.<br>
- Aether = make<OutputSection>("", 0, SHF_ALLOC);<br>
- Aether->SectionIndex = 1;<br>
+ aether = make<OutputSection>("", 0, SHF_ALLOC);<br>
+ aether->sectionIndex = 1;<br>
<br>
// Ctx captures the local AddressState and makes it accessible deliberately.<br>
// This is needed as there are some cases where we cannot just<br>
// thread the current state through to a lambda function created by the<br>
// script parser.<br>
- auto Deleter = make_unique<AddressState>();<br>
- Ctx = Deleter.get();<br>
- Ctx->OutSec = Aether;<br>
+ auto deleter = make_unique<AddressState>();<br>
+ ctx = deleter.get();<br>
+ ctx->outSec = aether;<br>
<br>
- size_t I = 0;<br>
+ size_t i = 0;<br>
// Add input sections to output sections.<br>
- for (BaseCommand *Base : SectionCommands) {<br>
+ for (BaseCommand *base : sectionCommands) {<br>
// Handle symbol assignments outside of any output section.<br>
- if (auto *Cmd = dyn_cast<SymbolAssignment>(Base)) {<br>
- addSymbol(Cmd);<br>
+ if (auto *cmd = dyn_cast<SymbolAssignment>(base)) {<br>
+ addSymbol(cmd);<br>
continue;<br>
}<br>
<br>
- if (auto *Sec = dyn_cast<OutputSection>(Base)) {<br>
- std::vector<InputSection *> V = createInputSectionList(*Sec);<br>
+ if (auto *sec = dyn_cast<OutputSection>(base)) {<br>
+ std::vector<InputSection *> v = createInputSectionList(*sec);<br>
<br>
// The output section name `/DISCARD/' is special.<br>
// Any input section assigned to it is discarded.<br>
- if (Sec->Name == "/DISCARD/") {<br>
- discard(V);<br>
- Sec->SectionCommands.clear();<br>
+ if (sec->name == "/DISCARD/") {<br>
+ discard(v);<br>
+ sec->sectionCommands.clear();<br>
continue;<br>
}<br>
<br>
@@ -491,61 +491,61 @@ void LinkerScript::processSectionCommand<br>
//<br>
// Because we'll iterate over SectionCommands many more times, the easy<br>
// way to "make it as if it wasn't present" is to make it empty.<br>
- if (!matchConstraints(V, Sec->Constraint)) {<br>
- for (InputSectionBase *S : V)<br>
- S->Assigned = false;<br>
- Sec->SectionCommands.clear();<br>
+ if (!matchConstraints(v, sec->constraint)) {<br>
+ for (InputSectionBase *s : v)<br>
+ s->assigned = false;<br>
+ sec->sectionCommands.clear();<br>
continue;<br>
}<br>
<br>
// A directive may contain symbol definitions like this:<br>
// ".foo : { ...; bar = .; }". Handle them.<br>
- for (BaseCommand *Base : Sec->SectionCommands)<br>
- if (auto *OutCmd = dyn_cast<SymbolAssignment>(Base))<br>
- addSymbol(OutCmd);<br>
+ for (BaseCommand *base : sec->sectionCommands)<br>
+ if (auto *outCmd = dyn_cast<SymbolAssignment>(base))<br>
+ addSymbol(outCmd);<br>
<br>
// Handle subalign (e.g. ".foo : SUBALIGN(32) { ... }"). If subalign<br>
// is given, input sections are aligned to that value, whether the<br>
// given value is larger or smaller than the original section alignment.<br>
- if (Sec->SubalignExpr) {<br>
- uint32_t Subalign = Sec->SubalignExpr().getValue();<br>
- for (InputSectionBase *S : V)<br>
- S->Alignment = Subalign;<br>
+ if (sec->subalignExpr) {<br>
+ uint32_t subalign = sec->subalignExpr().getValue();<br>
+ for (InputSectionBase *s : v)<br>
+ s->alignment = subalign;<br>
}<br>
<br>
// Add input sections to an output section.<br>
- for (InputSection *S : V)<br>
- Sec->addSection(S);<br>
+ for (InputSection *s : v)<br>
+ sec->addSection(s);<br>
<br>
- Sec->SectionIndex = I++;<br>
- if (Sec->Noload)<br>
- Sec->Type = SHT_NOBITS;<br>
- if (Sec->NonAlloc)<br>
- Sec->Flags &= ~(uint64_t)SHF_ALLOC;<br>
+ sec->sectionIndex = i++;<br>
+ if (sec->noload)<br>
+ sec->type = SHT_NOBITS;<br>
+ if (sec->nonAlloc)<br>
+ sec->flags &= ~(uint64_t)SHF_ALLOC;<br>
}<br>
}<br>
- Ctx = nullptr;<br>
+ ctx = nullptr;<br>
}<br>
<br>
-static OutputSection *findByName(ArrayRef<BaseCommand *> Vec,<br>
- StringRef Name) {<br>
- for (BaseCommand *Base : Vec)<br>
- if (auto *Sec = dyn_cast<OutputSection>(Base))<br>
- if (Sec->Name == Name)<br>
- return Sec;<br>
+static OutputSection *findByName(ArrayRef<BaseCommand *> vec,<br>
+ StringRef name) {<br>
+ for (BaseCommand *base : vec)<br>
+ if (auto *sec = dyn_cast<OutputSection>(base))<br>
+ if (sec->name == name)<br>
+ return sec;<br>
return nullptr;<br>
}<br>
<br>
-static OutputSection *createSection(InputSectionBase *IS,<br>
- StringRef OutsecName) {<br>
- OutputSection *Sec = Script->createOutputSection(OutsecName, "<internal>");<br>
- Sec->addSection(cast<InputSection>(IS));<br>
- return Sec;<br>
+static OutputSection *createSection(InputSectionBase *isec,<br>
+ StringRef outsecName) {<br>
+ OutputSection *sec = script->createOutputSection(outsecName, "<internal>");<br>
+ sec->addSection(cast<InputSection>(isec));<br>
+ return sec;<br>
}<br>
<br>
static OutputSection *<br>
-addInputSec(StringMap<TinyPtrVector<OutputSection *>> &Map,<br>
- InputSectionBase *IS, StringRef OutsecName) {<br>
+addInputSec(StringMap<TinyPtrVector<OutputSection *>> &map,<br>
+ InputSectionBase *isec, StringRef outsecName) {<br>
// Sections with SHT_GROUP or SHF_GROUP attributes reach here only when the -r<br>
// option is given. A section with SHT_GROUP defines a "section group", and<br>
// its members have SHF_GROUP attribute. Usually these flags have already been<br>
@@ -553,8 +553,8 @@ addInputSec(StringMap<TinyPtrVector<Outp<br>
// However, for the -r option, we want to pass through all section groups<br>
// as-is because adding/removing members or merging them with other groups<br>
// change their semantics.<br>
- if (IS->Type == SHT_GROUP || (IS->Flags & SHF_GROUP))<br>
- return createSection(IS, OutsecName);<br>
+ if (isec->type == SHT_GROUP || (isec->flags & SHF_GROUP))<br>
+ return createSection(isec, outsecName);<br>
<br>
// Imagine .zed : { *(.foo) *(.bar) } script. Both foo and bar may have<br>
// relocation sections .rela.foo and .rela.bar for example. Most tools do<br>
@@ -562,25 +562,25 @@ addInputSec(StringMap<TinyPtrVector<Outp<br>
// should combine these relocation sections into single output.<br>
// We skip synthetic sections because it can be .rela.dyn/.rela.plt or any<br>
// other REL[A] sections created by linker itself.<br>
- if (!isa<SyntheticSection>(IS) &&<br>
- (IS->Type == SHT_REL || IS->Type == SHT_RELA)) {<br>
- auto *Sec = cast<InputSection>(IS);<br>
- OutputSection *Out = Sec->getRelocatedSection()->getOutputSection();<br>
+ if (!isa<SyntheticSection>(isec) &&<br>
+ (isec->type == SHT_REL || isec->type == SHT_RELA)) {<br>
+ auto *sec = cast<InputSection>(isec);<br>
+ OutputSection *out = sec->getRelocatedSection()->getOutputSection();<br>
<br>
- if (Out->RelocationSection) {<br>
- Out->RelocationSection->addSection(Sec);<br>
+ if (out->relocationSection) {<br>
+ out->relocationSection->addSection(sec);<br>
return nullptr;<br>
}<br>
<br>
- Out->RelocationSection = createSection(IS, OutsecName);<br>
- return Out->RelocationSection;<br>
+ out->relocationSection = createSection(isec, outsecName);<br>
+ return out->relocationSection;<br>
}<br>
<br>
// When control reaches here, mergeable sections have already been merged into<br>
// synthetic sections. For relocatable case we want to create one output<br>
// section per syntetic section so that they have a valid sh_entsize.<br>
- if (Config->Relocatable && (IS->Flags & SHF_MERGE))<br>
- return createSection(IS, OutsecName);<br>
+ if (config->relocatable && (isec->flags & SHF_MERGE))<br>
+ return createSection(isec, outsecName);<br>
<br>
// The ELF spec just says<br>
// ----------------------------------------------------------------<br>
@@ -624,161 +624,161 @@ addInputSec(StringMap<TinyPtrVector<Outp<br>
//<br>
// Given the above issues, we instead merge sections by name and error on<br>
// incompatible types and flags.<br>
- TinyPtrVector<OutputSection *> &V = Map[OutsecName];<br>
- for (OutputSection *Sec : V) {<br>
- if (Sec->Partition != IS->Partition)<br>
+ TinyPtrVector<OutputSection *> &v = map[outsecName];<br>
+ for (OutputSection *sec : v) {<br>
+ if (sec->partition != isec->partition)<br>
continue;<br>
- Sec->addSection(cast<InputSection>(IS));<br>
+ sec->addSection(cast<InputSection>(isec));<br>
return nullptr;<br>
}<br>
<br>
- OutputSection *Sec = createSection(IS, OutsecName);<br>
- V.push_back(Sec);<br>
- return Sec;<br>
+ OutputSection *sec = createSection(isec, outsecName);<br>
+ v.push_back(sec);<br>
+ return sec;<br>
}<br>
<br>
// Add sections that didn't match any sections command.<br>
void LinkerScript::addOrphanSections() {<br>
- StringMap<TinyPtrVector<OutputSection *>> Map;<br>
- std::vector<OutputSection *> V;<br>
+ StringMap<TinyPtrVector<OutputSection *>> map;<br>
+ std::vector<OutputSection *> v;<br>
<br>
- auto Add = [&](InputSectionBase *S) {<br>
- if (!S->isLive() || S->Parent)<br>
+ auto add = [&](InputSectionBase *s) {<br>
+ if (!s->isLive() || s->parent)<br>
return;<br>
<br>
- StringRef Name = getOutputSectionName(S);<br>
+ StringRef name = getOutputSectionName(s);<br>
<br>
- if (Config->OrphanHandling == OrphanHandlingPolicy::Error)<br>
- error(toString(S) + " is being placed in '" + Name + "'");<br>
- else if (Config->OrphanHandling == OrphanHandlingPolicy::Warn)<br>
- warn(toString(S) + " is being placed in '" + Name + "'");<br>
+ if (config->orphanHandling == OrphanHandlingPolicy::Error)<br>
+ error(toString(s) + " is being placed in '" + name + "'");<br>
+ else if (config->orphanHandling == OrphanHandlingPolicy::Warn)<br>
+ warn(toString(s) + " is being placed in '" + name + "'");<br>
<br>
- if (OutputSection *Sec = findByName(SectionCommands, Name)) {<br>
- Sec->addSection(cast<InputSection>(S));<br>
+ if (OutputSection *sec = findByName(sectionCommands, name)) {<br>
+ sec->addSection(cast<InputSection>(s));<br>
return;<br>
}<br>
<br>
- if (OutputSection *OS = addInputSec(Map, S, Name))<br>
- V.push_back(OS);<br>
- assert(S->getOutputSection()->SectionIndex == UINT32_MAX);<br>
+ if (OutputSection *os = addInputSec(map, s, name))<br>
+ v.push_back(os);<br>
+ assert(s->getOutputSection()->sectionIndex == UINT32_MAX);<br>
};<br>
<br>
// For futher --emit-reloc handling code we need target output section<br>
// to be created before we create relocation output section, so we want<br>
// to create target sections first. We do not want priority handling<br>
// for synthetic sections because them are special.<br>
- for (InputSectionBase *IS : InputSections) {<br>
- if (auto *Sec = dyn_cast<InputSection>(IS))<br>
- if (InputSectionBase *Rel = Sec->getRelocatedSection())<br>
- if (auto *RelIS = dyn_cast_or_null<InputSectionBase>(Rel->Parent))<br>
- Add(RelIS);<br>
- Add(IS);<br>
+ for (InputSectionBase *isec : inputSections) {<br>
+ if (auto *sec = dyn_cast<InputSection>(isec))<br>
+ if (InputSectionBase *rel = sec->getRelocatedSection())<br>
+ if (auto *relIS = dyn_cast_or_null<InputSectionBase>(rel->parent))<br>
+ add(relIS);<br>
+ add(isec);<br>
}<br>
<br>
// If no SECTIONS command was given, we should insert sections commands<br>
// before others, so that we can handle scripts which refers them,<br>
// for example: "foo = ABSOLUTE(ADDR(.text)));".<br>
// When SECTIONS command is present we just add all orphans to the end.<br>
- if (HasSectionsCommand)<br>
- SectionCommands.insert(SectionCommands.end(), V.begin(), V.end());<br>
+ if (hasSectionsCommand)<br>
+ sectionCommands.insert(sectionCommands.end(), v.begin(), v.end());<br>
else<br>
- SectionCommands.insert(SectionCommands.begin(), V.begin(), V.end());<br>
+ sectionCommands.insert(sectionCommands.begin(), v.begin(), v.end());<br>
}<br>
<br>
-uint64_t LinkerScript::advance(uint64_t Size, unsigned Alignment) {<br>
- bool IsTbss =<br>
- (Ctx->OutSec->Flags & SHF_TLS) && Ctx->OutSec->Type == SHT_NOBITS;<br>
- uint64_t Start = IsTbss ? Dot + Ctx->ThreadBssOffset : Dot;<br>
- Start = alignTo(Start, Alignment);<br>
- uint64_t End = Start + Size;<br>
+uint64_t LinkerScript::advance(uint64_t size, unsigned alignment) {<br>
+ bool isTbss =<br>
+ (ctx->outSec->flags & SHF_TLS) && ctx->outSec->type == SHT_NOBITS;<br>
+ uint64_t start = isTbss ? dot + ctx->threadBssOffset : dot;<br>
+ start = alignTo(start, alignment);<br>
+ uint64_t end = start + size;<br>
<br>
- if (IsTbss)<br>
- Ctx->ThreadBssOffset = End - Dot;<br>
+ if (isTbss)<br>
+ ctx->threadBssOffset = end - dot;<br>
else<br>
- Dot = End;<br>
- return End;<br>
+ dot = end;<br>
+ return end;<br>
}<br>
<br>
-void LinkerScript::output(InputSection *S) {<br>
- assert(Ctx->OutSec == S->getParent());<br>
- uint64_t Before = advance(0, 1);<br>
- uint64_t Pos = advance(S->getSize(), S->Alignment);<br>
- S->OutSecOff = Pos - S->getSize() - Ctx->OutSec->Addr;<br>
+void LinkerScript::output(InputSection *s) {<br>
+ assert(ctx->outSec == s->getParent());<br>
+ uint64_t before = advance(0, 1);<br>
+ uint64_t pos = advance(s->getSize(), s->alignment);<br>
+ s->outSecOff = pos - s->getSize() - ctx->outSec->addr;<br>
<br>
// Update output section size after adding each section. This is so that<br>
// SIZEOF works correctly in the case below:<br>
// .foo { *(.aaa) a = SIZEOF(.foo); *(.bbb) }<br>
- expandOutputSection(Pos - Before);<br>
+ expandOutputSection(pos - before);<br>
}<br>
<br>
-void LinkerScript::switchTo(OutputSection *Sec) {<br>
- Ctx->OutSec = Sec;<br>
+void LinkerScript::switchTo(OutputSection *sec) {<br>
+ ctx->outSec = sec;<br>
<br>
- uint64_t Before = advance(0, 1);<br>
- Ctx->OutSec->Addr = advance(0, Ctx->OutSec->Alignment);<br>
- expandMemoryRegions(Ctx->OutSec->Addr - Before);<br>
+ uint64_t before = advance(0, 1);<br>
+ ctx->outSec->addr = advance(0, ctx->outSec->alignment);<br>
+ expandMemoryRegions(ctx->outSec->addr - before);<br>
}<br>
<br>
// This function searches for a memory region to place the given output<br>
// section in. If found, a pointer to the appropriate memory region is<br>
// returned. Otherwise, a nullptr is returned.<br>
-MemoryRegion *LinkerScript::findMemoryRegion(OutputSection *Sec) {<br>
+MemoryRegion *LinkerScript::findMemoryRegion(OutputSection *sec) {<br>
// If a memory region name was specified in the output section command,<br>
// then try to find that region first.<br>
- if (!Sec->MemoryRegionName.empty()) {<br>
- if (MemoryRegion *M = MemoryRegions.lookup(Sec->MemoryRegionName))<br>
- return M;<br>
- error("memory region '" + Sec->MemoryRegionName + "' not declared");<br>
+ if (!sec->memoryRegionName.empty()) {<br>
+ if (MemoryRegion *m = memoryRegions.lookup(sec->memoryRegionName))<br>
+ return m;<br>
+ error("memory region '" + sec->memoryRegionName + "' not declared");<br>
return nullptr;<br>
}<br>
<br>
// If at least one memory region is defined, all sections must<br>
// belong to some memory region. Otherwise, we don't need to do<br>
// anything for memory regions.<br>
- if (MemoryRegions.empty())<br>
+ if (memoryRegions.empty())<br>
return nullptr;<br>
<br>
// See if a region can be found by matching section flags.<br>
- for (auto &Pair : MemoryRegions) {<br>
- MemoryRegion *M = Pair.second;<br>
- if ((M->Flags & Sec->Flags) && (M->NegFlags & Sec->Flags) == 0)<br>
- return M;<br>
+ for (auto &pair : memoryRegions) {<br>
+ MemoryRegion *m = pair.second;<br>
+ if ((m->flags & sec->flags) && (m->negFlags & sec->flags) == 0)<br>
+ return m;<br>
}<br>
<br>
// Otherwise, no suitable region was found.<br>
- if (Sec->Flags & SHF_ALLOC)<br>
- error("no memory region specified for section '" + Sec->Name + "'");<br>
+ if (sec->flags & SHF_ALLOC)<br>
+ error("no memory region specified for section '" + sec->name + "'");<br>
return nullptr;<br>
}<br>
<br>
-static OutputSection *findFirstSection(PhdrEntry *Load) {<br>
- for (OutputSection *Sec : OutputSections)<br>
- if (Sec->PtLoad == Load)<br>
- return Sec;<br>
+static OutputSection *findFirstSection(PhdrEntry *load) {<br>
+ for (OutputSection *sec : outputSections)<br>
+ if (sec->ptLoad == load)<br>
+ return sec;<br>
return nullptr;<br>
}<br>
<br>
// This function assigns offsets to input sections and an output section<br>
// for a single sections command (e.g. ".text { *(.text); }").<br>
-void LinkerScript::assignOffsets(OutputSection *Sec) {<br>
- if (!(Sec->Flags & SHF_ALLOC))<br>
- Dot = 0;<br>
+void LinkerScript::assignOffsets(OutputSection *sec) {<br>
+ if (!(sec->flags & SHF_ALLOC))<br>
+ dot = 0;<br>
<br>
- Ctx->MemRegion = Sec->MemRegion;<br>
- Ctx->LMARegion = Sec->LMARegion;<br>
- if (Ctx->MemRegion)<br>
- Dot = Ctx->MemRegion->CurPos;<br>
+ ctx->memRegion = sec->memRegion;<br>
+ ctx->lmaRegion = sec->lmaRegion;<br>
+ if (ctx->memRegion)<br>
+ dot = ctx->memRegion->curPos;<br>
<br>
- if ((Sec->Flags & SHF_ALLOC) && Sec->AddrExpr)<br>
- setDot(Sec->AddrExpr, Sec->Location, false);<br>
+ if ((sec->flags & SHF_ALLOC) && sec->addrExpr)<br>
+ setDot(sec->addrExpr, sec->location, false);<br>
<br>
- switchTo(Sec);<br>
+ switchTo(sec);<br>
<br>
- if (Sec->LMAExpr)<br>
- Ctx->LMAOffset = Sec->LMAExpr().getValue() - Dot;<br>
+ if (sec->lmaExpr)<br>
+ ctx->lmaOffset = sec->lmaExpr().getValue() - dot;<br>
<br>
- if (MemoryRegion *MR = Sec->LMARegion)<br>
- Ctx->LMAOffset = MR->CurPos - Dot;<br>
+ if (MemoryRegion *mr = sec->lmaRegion)<br>
+ ctx->lmaOffset = mr->curPos - dot;<br>
<br>
// If neither AT nor AT> is specified for an allocatable section, the linker<br>
// will set the LMA such that the difference between VMA and LMA for the<br>
@@ -786,71 +786,71 @@ void LinkerScript::assignOffsets(OutputS<br>
// <a href="https://urldefense.proofpoint.com/v2/url?u=https-3A__sourceware.org_binutils_docs-2D2.20_ld_Output-2DSection-2DLMA.html&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=KIM6JTp85xX6T_wmOfUi4EscNzvcslFgAtN9KSadyGU&e=" rel="noreferrer" target="_blank">https://urldefense.proofpoint.com/v2/url?u=https-3A__sourceware.org_binutils_docs-2D2.20_ld_Output-2DSection-2DLMA.html&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=KIM6JTp85xX6T_wmOfUi4EscNzvcslFgAtN9KSadyGU&e=</a> <br>
// This, however, should only be done by the first "non-header" section<br>
// in the segment.<br>
- if (PhdrEntry *L = Ctx->OutSec->PtLoad)<br>
- if (Sec == findFirstSection(L))<br>
- L->LMAOffset = Ctx->LMAOffset;<br>
+ if (PhdrEntry *l = ctx->outSec->ptLoad)<br>
+ if (sec == findFirstSection(l))<br>
+ l->lmaOffset = ctx->lmaOffset;<br>
<br>
// We can call this method multiple times during the creation of<br>
// thunks and want to start over calculation each time.<br>
- Sec->Size = 0;<br>
+ sec->size = 0;<br>
<br>
// We visited SectionsCommands from processSectionCommands to<br>
// layout sections. Now, we visit SectionsCommands again to fix<br>
// section offsets.<br>
- for (BaseCommand *Base : Sec->SectionCommands) {<br>
+ for (BaseCommand *base : sec->sectionCommands) {<br>
// This handles the assignments to symbol or to the dot.<br>
- if (auto *Cmd = dyn_cast<SymbolAssignment>(Base)) {<br>
- Cmd->Addr = Dot;<br>
- assignSymbol(Cmd, true);<br>
- Cmd->Size = Dot - Cmd->Addr;<br>
+ if (auto *cmd = dyn_cast<SymbolAssignment>(base)) {<br>
+ cmd->addr = dot;<br>
+ assignSymbol(cmd, true);<br>
+ cmd->size = dot - cmd->addr;<br>
continue;<br>
}<br>
<br>
// Handle BYTE(), SHORT(), LONG(), or QUAD().<br>
- if (auto *Cmd = dyn_cast<ByteCommand>(Base)) {<br>
- Cmd->Offset = Dot - Ctx->OutSec->Addr;<br>
- Dot += Cmd->Size;<br>
- expandOutputSection(Cmd->Size);<br>
+ if (auto *cmd = dyn_cast<ByteCommand>(base)) {<br>
+ cmd->offset = dot - ctx->outSec->addr;<br>
+ dot += cmd->size;<br>
+ expandOutputSection(cmd->size);<br>
continue;<br>
}<br>
<br>
// Handle a single input section description command.<br>
// It calculates and assigns the offsets for each section and also<br>
// updates the output section size.<br>
- for (InputSection *Sec : cast<InputSectionDescription>(Base)->Sections)<br>
- output(Sec);<br>
+ for (InputSection *sec : cast<InputSectionDescription>(base)->sections)<br>
+ output(sec);<br>
}<br>
}<br>
<br>
-static bool isDiscardable(OutputSection &Sec) {<br>
- if (Sec.Name == "/DISCARD/")<br>
+static bool isDiscardable(OutputSection &sec) {<br>
+ if (<a href="http://sec.name" rel="noreferrer" target="_blank">sec.name</a> == "/DISCARD/")<br>
return true;<br>
<br>
// We do not remove empty sections that are explicitly<br>
// assigned to any segment.<br>
- if (!Sec.Phdrs.empty())<br>
+ if (!sec.phdrs.empty())<br>
return false;<br>
<br>
// We do not want to remove OutputSections with expressions that reference<br>
// symbols even if the OutputSection is empty. We want to ensure that the<br>
// expressions can be evaluated and report an error if they cannot.<br>
- if (Sec.ExpressionsUseSymbols)<br>
+ if (sec.expressionsUseSymbols)<br>
return false;<br>
<br>
// OutputSections may be referenced by name in ADDR and LOADADDR expressions,<br>
// as an empty Section can has a valid VMA and LMA we keep the OutputSection<br>
// to maintain the integrity of the other Expression.<br>
- if (Sec.UsedInExpression)<br>
+ if (sec.usedInExpression)<br>
return false;<br>
<br>
- for (BaseCommand *Base : Sec.SectionCommands) {<br>
- if (auto Cmd = dyn_cast<SymbolAssignment>(Base))<br>
+ for (BaseCommand *base : sec.sectionCommands) {<br>
+ if (auto cmd = dyn_cast<SymbolAssignment>(base))<br>
// Don't create empty output sections just for unreferenced PROVIDE<br>
// symbols.<br>
- if (Cmd->Name != "." && !Cmd->Sym)<br>
+ if (cmd->name != "." && !cmd->sym)<br>
continue;<br>
<br>
- if (!isa<InputSectionDescription>(*Base))<br>
+ if (!isa<InputSectionDescription>(*base))<br>
return false;<br>
}<br>
return true;<br>
@@ -877,35 +877,35 @@ void LinkerScript::adjustSectionsBeforeS<br>
// The other option is to pick flags that minimize the impact the section<br>
// will have on the rest of the linker. That is why we copy the flags from<br>
// the previous sections. Only a few flags are needed to keep the impact low.<br>
- uint64_t Flags = SHF_ALLOC;<br>
+ uint64_t flags = SHF_ALLOC;<br>
<br>
- for (BaseCommand *&Cmd : SectionCommands) {<br>
- auto *Sec = dyn_cast<OutputSection>(Cmd);<br>
- if (!Sec)<br>
+ for (BaseCommand *&cmd : sectionCommands) {<br>
+ auto *sec = dyn_cast<OutputSection>(cmd);<br>
+ if (!sec)<br>
continue;<br>
<br>
// Handle align (e.g. ".foo : ALIGN(16) { ... }").<br>
- if (Sec->AlignExpr)<br>
- Sec->Alignment =<br>
- std::max<uint32_t>(Sec->Alignment, Sec->AlignExpr().getValue());<br>
+ if (sec->alignExpr)<br>
+ sec->alignment =<br>
+ std::max<uint32_t>(sec->alignment, sec->alignExpr().getValue());<br>
<br>
// The input section might have been removed (if it was an empty synthetic<br>
// section), but we at least know the flags.<br>
- if (Sec->HasInputSections)<br>
- Flags = Sec->Flags;<br>
+ if (sec->hasInputSections)<br>
+ flags = sec->flags;<br>
<br>
// We do not want to keep any special flags for output section<br>
// in case it is empty.<br>
- bool IsEmpty = getInputSections(Sec).empty();<br>
- if (IsEmpty)<br>
- Sec->Flags = Flags & ((Sec->NonAlloc ? 0 : (uint64_t)SHF_ALLOC) |<br>
+ bool isEmpty = getInputSections(sec).empty();<br>
+ if (isEmpty)<br>
+ sec->flags = flags & ((sec->nonAlloc ? 0 : (uint64_t)SHF_ALLOC) |<br>
SHF_WRITE | SHF_EXECINSTR);<br>
<br>
- if (IsEmpty && isDiscardable(*Sec)) {<br>
- Sec->markDead();<br>
- Cmd = nullptr;<br>
- } else if (!Sec->isLive()) {<br>
- Sec->markLive();<br>
+ if (isEmpty && isDiscardable(*sec)) {<br>
+ sec->markDead();<br>
+ cmd = nullptr;<br>
+ } else if (!sec->isLive()) {<br>
+ sec->markLive();<br>
}<br>
}<br>
<br>
@@ -915,20 +915,20 @@ void LinkerScript::adjustSectionsBeforeS<br>
// clutter the output.<br>
// We instead remove trivially empty sections. The bfd linker seems even<br>
// more aggressive at removing them.<br>
- llvm::erase_if(SectionCommands, [&](BaseCommand *Base) { return !Base; });<br>
+ llvm::erase_if(sectionCommands, [&](BaseCommand *base) { return !base; });<br>
}<br>
<br>
void LinkerScript::adjustSectionsAfterSorting() {<br>
// Try and find an appropriate memory region to assign offsets in.<br>
- for (BaseCommand *Base : SectionCommands) {<br>
- if (auto *Sec = dyn_cast<OutputSection>(Base)) {<br>
- if (!Sec->LMARegionName.empty()) {<br>
- if (MemoryRegion *M = MemoryRegions.lookup(Sec->LMARegionName))<br>
- Sec->LMARegion = M;<br>
+ for (BaseCommand *base : sectionCommands) {<br>
+ if (auto *sec = dyn_cast<OutputSection>(base)) {<br>
+ if (!sec->lmaRegionName.empty()) {<br>
+ if (MemoryRegion *m = memoryRegions.lookup(sec->lmaRegionName))<br>
+ sec->lmaRegion = m;<br>
else<br>
- error("memory region '" + Sec->LMARegionName + "' not declared");<br>
+ error("memory region '" + sec->lmaRegionName + "' not declared");<br>
}<br>
- Sec->MemRegion = findMemoryRegion(Sec);<br>
+ sec->memRegion = findMemoryRegion(sec);<br>
}<br>
}<br>
<br>
@@ -938,38 +938,38 @@ void LinkerScript::adjustSectionsAfterSo<br>
// Below is an example of such linker script:<br>
// PHDRS { seg PT_LOAD; }<br>
// SECTIONS { .aaa : { *(.aaa) } }<br>
- std::vector<StringRef> DefPhdrs;<br>
- auto FirstPtLoad = llvm::find_if(PhdrsCommands, [](const PhdrsCommand &Cmd) {<br>
- return Cmd.Type == PT_LOAD;<br>
+ std::vector<StringRef> defPhdrs;<br>
+ auto firstPtLoad = llvm::find_if(phdrsCommands, [](const PhdrsCommand &cmd) {<br>
+ return cmd.type == PT_LOAD;<br>
});<br>
- if (FirstPtLoad != PhdrsCommands.end())<br>
- DefPhdrs.push_back(FirstPtLoad->Name);<br>
+ if (firstPtLoad != phdrsCommands.end())<br>
+ defPhdrs.push_back(firstPtLoad->name);<br>
<br>
// Walk the commands and propagate the program headers to commands that don't<br>
// explicitly specify them.<br>
- for (BaseCommand *Base : SectionCommands) {<br>
- auto *Sec = dyn_cast<OutputSection>(Base);<br>
- if (!Sec)<br>
+ for (BaseCommand *base : sectionCommands) {<br>
+ auto *sec = dyn_cast<OutputSection>(base);<br>
+ if (!sec)<br>
continue;<br>
<br>
- if (Sec->Phdrs.empty()) {<br>
+ if (sec->phdrs.empty()) {<br>
// To match the bfd linker script behaviour, only propagate program<br>
// headers to sections that are allocated.<br>
- if (Sec->Flags & SHF_ALLOC)<br>
- Sec->Phdrs = DefPhdrs;<br>
+ if (sec->flags & SHF_ALLOC)<br>
+ sec->phdrs = defPhdrs;<br>
} else {<br>
- DefPhdrs = Sec->Phdrs;<br>
+ defPhdrs = sec->phdrs;<br>
}<br>
}<br>
}<br>
<br>
-static uint64_t computeBase(uint64_t Min, bool AllocateHeaders) {<br>
+static uint64_t computeBase(uint64_t min, bool allocateHeaders) {<br>
// If there is no SECTIONS or if the linkerscript is explicit about program<br>
// headers, do our best to allocate them.<br>
- if (!Script->HasSectionsCommand || AllocateHeaders)<br>
+ if (!script->hasSectionsCommand || allocateHeaders)<br>
return 0;<br>
// Otherwise only allocate program headers if that would not add a page.<br>
- return alignDown(Min, Config->MaxPageSize);<br>
+ return alignDown(min, config->maxPageSize);<br>
}<br>
<br>
// Try to find an address for the file and program headers output sections,<br>
@@ -983,120 +983,120 @@ static uint64_t computeBase(uint64_t Min<br>
//<br>
// If there isn't enough space for these sections, we'll remove them from the<br>
// PT_LOAD segment, and we'll also remove the PT_PHDR segment.<br>
-void LinkerScript::allocateHeaders(std::vector<PhdrEntry *> &Phdrs) {<br>
- uint64_t Min = std::numeric_limits<uint64_t>::max();<br>
- for (OutputSection *Sec : OutputSections)<br>
- if (Sec->Flags & SHF_ALLOC)<br>
- Min = std::min<uint64_t>(Min, Sec->Addr);<br>
-<br>
- auto It = llvm::find_if(<br>
- Phdrs, [](const PhdrEntry *E) { return E->p_type == PT_LOAD; });<br>
- if (It == Phdrs.end())<br>
+void LinkerScript::allocateHeaders(std::vector<PhdrEntry *> &phdrs) {<br>
+ uint64_t min = std::numeric_limits<uint64_t>::max();<br>
+ for (OutputSection *sec : outputSections)<br>
+ if (sec->flags & SHF_ALLOC)<br>
+ min = std::min<uint64_t>(min, sec->addr);<br>
+<br>
+ auto it = llvm::find_if(<br>
+ phdrs, [](const PhdrEntry *e) { return e->p_type == PT_LOAD; });<br>
+ if (it == phdrs.end())<br>
return;<br>
- PhdrEntry *FirstPTLoad = *It;<br>
+ PhdrEntry *firstPTLoad = *it;<br>
<br>
- bool HasExplicitHeaders =<br>
- llvm::any_of(PhdrsCommands, [](const PhdrsCommand &Cmd) {<br>
- return Cmd.HasPhdrs || Cmd.HasFilehdr;<br>
+ bool hasExplicitHeaders =<br>
+ llvm::any_of(phdrsCommands, [](const PhdrsCommand &cmd) {<br>
+ return cmd.hasPhdrs || cmd.hasFilehdr;<br>
});<br>
- bool Paged = !Config->Omagic && !Config->Nmagic;<br>
- uint64_t HeaderSize = getHeaderSize();<br>
- if ((Paged || HasExplicitHeaders) &&<br>
- HeaderSize <= Min - computeBase(Min, HasExplicitHeaders)) {<br>
- Min = alignDown(Min - HeaderSize, Config->MaxPageSize);<br>
- Out::ElfHeader->Addr = Min;<br>
- Out::ProgramHeaders->Addr = Min + Out::ElfHeader->Size;<br>
+ bool paged = !config->omagic && !config->nmagic;<br>
+ uint64_t headerSize = getHeaderSize();<br>
+ if ((paged || hasExplicitHeaders) &&<br>
+ headerSize <= min - computeBase(min, hasExplicitHeaders)) {<br>
+ min = alignDown(min - headerSize, config->maxPageSize);<br>
+ Out::elfHeader->addr = min;<br>
+ Out::programHeaders->addr = min + Out::elfHeader->size;<br>
return;<br>
}<br>
<br>
// Error if we were explicitly asked to allocate headers.<br>
- if (HasExplicitHeaders)<br>
+ if (hasExplicitHeaders)<br>
error("could not allocate headers");<br>
<br>
- Out::ElfHeader->PtLoad = nullptr;<br>
- Out::ProgramHeaders->PtLoad = nullptr;<br>
- FirstPTLoad->FirstSec = findFirstSection(FirstPTLoad);<br>
+ Out::elfHeader->ptLoad = nullptr;<br>
+ Out::programHeaders->ptLoad = nullptr;<br>
+ firstPTLoad->firstSec = findFirstSection(firstPTLoad);<br>
<br>
- llvm::erase_if(Phdrs,<br>
- [](const PhdrEntry *E) { return E->p_type == PT_PHDR; });<br>
+ llvm::erase_if(phdrs,<br>
+ [](const PhdrEntry *e) { return e->p_type == PT_PHDR; });<br>
}<br>
<br>
LinkerScript::AddressState::AddressState() {<br>
- for (auto &MRI : Script->MemoryRegions) {<br>
- MemoryRegion *MR = MRI.second;<br>
- MR->CurPos = MR->Origin;<br>
+ for (auto &mri : script->memoryRegions) {<br>
+ MemoryRegion *mr = mri.second;<br>
+ mr->curPos = mr->origin;<br>
}<br>
}<br>
<br>
static uint64_t getInitialDot() {<br>
// By default linker scripts use an initial value of 0 for '.',<br>
// but prefer -image-base if set.<br>
- if (Script->HasSectionsCommand)<br>
- return Config->ImageBase ? *Config->ImageBase : 0;<br>
+ if (script->hasSectionsCommand)<br>
+ return config->imageBase ? *config->imageBase : 0;<br>
<br>
- uint64_t StartAddr = UINT64_MAX;<br>
+ uint64_t startAddr = UINT64_MAX;<br>
// The Sections with -T<section> have been sorted in order of ascending<br>
// address. We must lower StartAddr if the lowest -T<section address> as<br>
// calls to setDot() must be monotonically increasing.<br>
- for (auto &KV : Config->SectionStartMap)<br>
- StartAddr = std::min(StartAddr, KV.second);<br>
- return std::min(StartAddr, Target->getImageBase() + elf::getHeaderSize());<br>
+ for (auto &kv : config->sectionStartMap)<br>
+ startAddr = std::min(startAddr, kv.second);<br>
+ return std::min(startAddr, target->getImageBase() + elf::getHeaderSize());<br>
}<br>
<br>
// Here we assign addresses as instructed by linker script SECTIONS<br>
// sub-commands. Doing that allows us to use final VA values, so here<br>
// we also handle rest commands like symbol assignments and ASSERTs.<br>
void LinkerScript::assignAddresses() {<br>
- Dot = getInitialDot();<br>
+ dot = getInitialDot();<br>
<br>
- auto Deleter = make_unique<AddressState>();<br>
- Ctx = Deleter.get();<br>
- ErrorOnMissingSection = true;<br>
- switchTo(Aether);<br>
-<br>
- for (BaseCommand *Base : SectionCommands) {<br>
- if (auto *Cmd = dyn_cast<SymbolAssignment>(Base)) {<br>
- Cmd->Addr = Dot;<br>
- assignSymbol(Cmd, false);<br>
- Cmd->Size = Dot - Cmd->Addr;<br>
+ auto deleter = make_unique<AddressState>();<br>
+ ctx = deleter.get();<br>
+ errorOnMissingSection = true;<br>
+ switchTo(aether);<br>
+<br>
+ for (BaseCommand *base : sectionCommands) {<br>
+ if (auto *cmd = dyn_cast<SymbolAssignment>(base)) {<br>
+ cmd->addr = dot;<br>
+ assignSymbol(cmd, false);<br>
+ cmd->size = dot - cmd->addr;<br>
continue;<br>
}<br>
- assignOffsets(cast<OutputSection>(Base));<br>
+ assignOffsets(cast<OutputSection>(base));<br>
}<br>
- Ctx = nullptr;<br>
+ ctx = nullptr;<br>
}<br>
<br>
// Creates program headers as instructed by PHDRS linker script command.<br>
std::vector<PhdrEntry *> LinkerScript::createPhdrs() {<br>
- std::vector<PhdrEntry *> Ret;<br>
+ std::vector<PhdrEntry *> ret;<br>
<br>
// Process PHDRS and FILEHDR keywords because they are not<br>
// real output sections and cannot be added in the following loop.<br>
- for (const PhdrsCommand &Cmd : PhdrsCommands) {<br>
- PhdrEntry *Phdr = make<PhdrEntry>(Cmd.Type, Cmd.Flags ? *Cmd.Flags : PF_R);<br>
+ for (const PhdrsCommand &cmd : phdrsCommands) {<br>
+ PhdrEntry *phdr = make<PhdrEntry>(cmd.type, cmd.flags ? *cmd.flags : PF_R);<br>
<br>
- if (Cmd.HasFilehdr)<br>
- Phdr->add(Out::ElfHeader);<br>
- if (Cmd.HasPhdrs)<br>
- Phdr->add(Out::ProgramHeaders);<br>
-<br>
- if (Cmd.LMAExpr) {<br>
- Phdr->p_paddr = Cmd.LMAExpr().getValue();<br>
- Phdr->HasLMA = true;<br>
+ if (cmd.hasFilehdr)<br>
+ phdr->add(Out::elfHeader);<br>
+ if (cmd.hasPhdrs)<br>
+ phdr->add(Out::programHeaders);<br>
+<br>
+ if (cmd.lmaExpr) {<br>
+ phdr->p_paddr = cmd.lmaExpr().getValue();<br>
+ phdr->hasLMA = true;<br>
}<br>
- Ret.push_back(Phdr);<br>
+ ret.push_back(phdr);<br>
}<br>
<br>
// Add output sections to program headers.<br>
- for (OutputSection *Sec : OutputSections) {<br>
+ for (OutputSection *sec : outputSections) {<br>
// Assign headers specified by linker script<br>
- for (size_t Id : getPhdrIndices(Sec)) {<br>
- Ret[Id]->add(Sec);<br>
- if (!PhdrsCommands[Id].Flags.hasValue())<br>
- Ret[Id]->p_flags |= Sec->getPhdrFlags();<br>
+ for (size_t id : getPhdrIndices(sec)) {<br>
+ ret[id]->add(sec);<br>
+ if (!phdrsCommands[id].flags.hasValue())<br>
+ ret[id]->p_flags |= sec->getPhdrFlags();<br>
}<br>
}<br>
- return Ret;<br>
+ return ret;<br>
}<br>
<br>
// Returns true if we should emit an .interp section.<br>
@@ -1105,54 +1105,54 @@ std::vector<PhdrEntry *> LinkerScript::c<br>
// no PT_INTERP is there, there's no place to emit an<br>
// .interp, so we don't do that in that case.<br>
bool LinkerScript::needsInterpSection() {<br>
- if (PhdrsCommands.empty())<br>
+ if (phdrsCommands.empty())<br>
return true;<br>
- for (PhdrsCommand &Cmd : PhdrsCommands)<br>
- if (Cmd.Type == PT_INTERP)<br>
+ for (PhdrsCommand &cmd : phdrsCommands)<br>
+ if (cmd.type == PT_INTERP)<br>
return true;<br>
return false;<br>
}<br>
<br>
-ExprValue LinkerScript::getSymbolValue(StringRef Name, const Twine &Loc) {<br>
- if (Name == ".") {<br>
- if (Ctx)<br>
- return {Ctx->OutSec, false, Dot - Ctx->OutSec->Addr, Loc};<br>
- error(Loc + ": unable to get location counter value");<br>
+ExprValue LinkerScript::getSymbolValue(StringRef name, const Twine &loc) {<br>
+ if (name == ".") {<br>
+ if (ctx)<br>
+ return {ctx->outSec, false, dot - ctx->outSec->addr, loc};<br>
+ error(loc + ": unable to get location counter value");<br>
return 0;<br>
}<br>
<br>
- if (Symbol *Sym = Symtab->find(Name)) {<br>
- if (auto *DS = dyn_cast<Defined>(Sym))<br>
- return {DS->Section, false, DS->Value, Loc};<br>
- if (isa<SharedSymbol>(Sym))<br>
- if (!ErrorOnMissingSection)<br>
- return {nullptr, false, 0, Loc};<br>
+ if (Symbol *sym = symtab->find(name)) {<br>
+ if (auto *ds = dyn_cast<Defined>(sym))<br>
+ return {ds->section, false, ds->value, loc};<br>
+ if (isa<SharedSymbol>(sym))<br>
+ if (!errorOnMissingSection)<br>
+ return {nullptr, false, 0, loc};<br>
}<br>
<br>
- error(Loc + ": symbol not found: " + Name);<br>
+ error(loc + ": symbol not found: " + name);<br>
return 0;<br>
}<br>
<br>
// Returns the index of the segment named Name.<br>
-static Optional<size_t> getPhdrIndex(ArrayRef<PhdrsCommand> Vec,<br>
- StringRef Name) {<br>
- for (size_t I = 0; I < Vec.size(); ++I)<br>
- if (Vec[I].Name == Name)<br>
- return I;<br>
+static Optional<size_t> getPhdrIndex(ArrayRef<PhdrsCommand> vec,<br>
+ StringRef name) {<br>
+ for (size_t i = 0; i < vec.size(); ++i)<br>
+ if (vec[i].name == name)<br>
+ return i;<br>
return None;<br>
}<br>
<br>
// Returns indices of ELF headers containing specific section. Each index is a<br>
// zero based number of ELF header listed within PHDRS {} script block.<br>
-std::vector<size_t> LinkerScript::getPhdrIndices(OutputSection *Cmd) {<br>
- std::vector<size_t> Ret;<br>
+std::vector<size_t> LinkerScript::getPhdrIndices(OutputSection *cmd) {<br>
+ std::vector<size_t> ret;<br>
<br>
- for (StringRef S : Cmd->Phdrs) {<br>
- if (Optional<size_t> Idx = getPhdrIndex(PhdrsCommands, S))<br>
- Ret.push_back(*Idx);<br>
- else if (S != "NONE")<br>
- error(Cmd->Location + ": section header '" + S +<br>
+ for (StringRef s : cmd->phdrs) {<br>
+ if (Optional<size_t> idx = getPhdrIndex(phdrsCommands, s))<br>
+ ret.push_back(*idx);<br>
+ else if (s != "NONE")<br>
+ error(cmd->location + ": section header '" + s +<br>
"' is not listed in PHDRS");<br>
}<br>
- return Ret;<br>
+ return ret;<br>
}<br>
<br>
Modified: lld/trunk/ELF/LinkerScript.h<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_ELF_LinkerScript.h-3Frev-3D365595-26r1-3D365594-26r2-3D365595-26view-3Ddiff&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=SaXI9lNu0Ic2lLxs2_hjjb42a99oRYpPbCb30hfTvOs&e=" rel="noreferrer" target="_blank">https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_ELF_LinkerScript.h-3Frev-3D365595-26r1-3D365594-26r2-3D365595-26view-3Ddiff&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=SaXI9lNu0Ic2lLxs2_hjjb42a99oRYpPbCb30hfTvOs&e=</a> <br>
==============================================================================<br>
--- lld/trunk/ELF/LinkerScript.h (original)<br>
+++ lld/trunk/ELF/LinkerScript.h Tue Jul 9 22:00:37 2019<br>
@@ -38,29 +38,29 @@ class ThunkSection;<br>
<br>
// This represents an r-value in the linker script.<br>
struct ExprValue {<br>
- ExprValue(SectionBase *Sec, bool ForceAbsolute, uint64_t Val,<br>
- const Twine &Loc)<br>
- : Sec(Sec), ForceAbsolute(ForceAbsolute), Val(Val), Loc(Loc.str()) {}<br>
+ ExprValue(SectionBase *sec, bool forceAbsolute, uint64_t val,<br>
+ const Twine &loc)<br>
+ : sec(sec), forceAbsolute(forceAbsolute), val(val), loc(loc.str()) {}<br>
<br>
- ExprValue(uint64_t Val) : ExprValue(nullptr, false, Val, "") {}<br>
+ ExprValue(uint64_t val) : ExprValue(nullptr, false, val, "") {}<br>
<br>
- bool isAbsolute() const { return ForceAbsolute || Sec == nullptr; }<br>
+ bool isAbsolute() const { return forceAbsolute || sec == nullptr; }<br>
uint64_t getValue() const;<br>
uint64_t getSecAddr() const;<br>
uint64_t getSectionOffset() const;<br>
<br>
// If a value is relative to a section, it has a non-null Sec.<br>
- SectionBase *Sec;<br>
+ SectionBase *sec;<br>
<br>
// True if this expression is enclosed in ABSOLUTE().<br>
// This flag affects the return value of getValue().<br>
- bool ForceAbsolute;<br>
+ bool forceAbsolute;<br>
<br>
- uint64_t Val;<br>
- uint64_t Alignment = 1;<br>
+ uint64_t val;<br>
+ uint64_t alignment = 1;<br>
<br>
// Original source location. Used for error messages.<br>
- std::string Loc;<br>
+ std::string loc;<br>
};<br>
<br>
// This represents an expression in the linker script.<br>
@@ -78,42 +78,42 @@ enum SectionsCommandKind {<br>
};<br>
<br>
struct BaseCommand {<br>
- BaseCommand(int K) : Kind(K) {}<br>
- int Kind;<br>
+ BaseCommand(int k) : kind(k) {}<br>
+ int kind;<br>
};<br>
<br>
// This represents ". = <expr>" or "<symbol> = <expr>".<br>
struct SymbolAssignment : BaseCommand {<br>
- SymbolAssignment(StringRef Name, Expr E, std::string Loc)<br>
- : BaseCommand(AssignmentKind), Name(Name), Expression(E), Location(Loc) {}<br>
+ SymbolAssignment(StringRef name, Expr e, std::string loc)<br>
+ : BaseCommand(AssignmentKind), name(name), expression(e), location(loc) {}<br>
<br>
- static bool classof(const BaseCommand *C) {<br>
- return C->Kind == AssignmentKind;<br>
+ static bool classof(const BaseCommand *c) {<br>
+ return c->kind == AssignmentKind;<br>
}<br>
<br>
// The LHS of an expression. Name is either a symbol name or ".".<br>
- StringRef Name;<br>
- Defined *Sym = nullptr;<br>
+ StringRef name;<br>
+ Defined *sym = nullptr;<br>
<br>
// The RHS of an expression.<br>
- Expr Expression;<br>
+ Expr expression;<br>
<br>
// Command attributes for PROVIDE, HIDDEN and PROVIDE_HIDDEN.<br>
- bool Provide = false;<br>
- bool Hidden = false;<br>
+ bool provide = false;<br>
+ bool hidden = false;<br>
<br>
// Holds file name and line number for error reporting.<br>
- std::string Location;<br>
+ std::string location;<br>
<br>
// A string representation of this command. We use this for -Map.<br>
- std::string CommandString;<br>
+ std::string commandString;<br>
<br>
// Address of this assignment command.<br>
- unsigned Addr;<br>
+ unsigned addr;<br>
<br>
// Size of this assignment command. This is usually 0, but if<br>
// you move '.' this may be greater than 0.<br>
- unsigned Size;<br>
+ unsigned size;<br>
};<br>
<br>
// Linker scripts allow additional constraints to be put on ouput sections.<br>
@@ -126,83 +126,83 @@ enum class ConstraintKind { NoConstraint<br>
// target memory. Instances of the struct are created by parsing the<br>
// MEMORY command.<br>
struct MemoryRegion {<br>
- MemoryRegion(StringRef Name, uint64_t Origin, uint64_t Length, uint32_t Flags,<br>
- uint32_t NegFlags)<br>
- : Name(Name), Origin(Origin), Length(Length), Flags(Flags),<br>
- NegFlags(NegFlags) {}<br>
-<br>
- std::string Name;<br>
- uint64_t Origin;<br>
- uint64_t Length;<br>
- uint32_t Flags;<br>
- uint32_t NegFlags;<br>
- uint64_t CurPos = 0;<br>
+ MemoryRegion(StringRef name, uint64_t origin, uint64_t length, uint32_t flags,<br>
+ uint32_t negFlags)<br>
+ : name(name), origin(origin), length(length), flags(flags),<br>
+ negFlags(negFlags) {}<br>
+<br>
+ std::string name;<br>
+ uint64_t origin;<br>
+ uint64_t length;<br>
+ uint32_t flags;<br>
+ uint32_t negFlags;<br>
+ uint64_t curPos = 0;<br>
};<br>
<br>
// This struct represents one section match pattern in SECTIONS() command.<br>
// It can optionally have negative match pattern for EXCLUDED_FILE command.<br>
// Also it may be surrounded with SORT() command, so contains sorting rules.<br>
struct SectionPattern {<br>
- SectionPattern(StringMatcher &&Pat1, StringMatcher &&Pat2)<br>
- : ExcludedFilePat(Pat1), SectionPat(Pat2),<br>
- SortOuter(SortSectionPolicy::Default),<br>
- SortInner(SortSectionPolicy::Default) {}<br>
-<br>
- StringMatcher ExcludedFilePat;<br>
- StringMatcher SectionPat;<br>
- SortSectionPolicy SortOuter;<br>
- SortSectionPolicy SortInner;<br>
+ SectionPattern(StringMatcher &&pat1, StringMatcher &&pat2)<br>
+ : excludedFilePat(pat1), sectionPat(pat2),<br>
+ sortOuter(SortSectionPolicy::Default),<br>
+ sortInner(SortSectionPolicy::Default) {}<br>
+<br>
+ StringMatcher excludedFilePat;<br>
+ StringMatcher sectionPat;<br>
+ SortSectionPolicy sortOuter;<br>
+ SortSectionPolicy sortInner;<br>
};<br>
<br>
struct InputSectionDescription : BaseCommand {<br>
- InputSectionDescription(StringRef FilePattern)<br>
- : BaseCommand(InputSectionKind), FilePat(FilePattern) {}<br>
+ InputSectionDescription(StringRef filePattern)<br>
+ : BaseCommand(InputSectionKind), filePat(filePattern) {}<br>
<br>
- static bool classof(const BaseCommand *C) {<br>
- return C->Kind == InputSectionKind;<br>
+ static bool classof(const BaseCommand *c) {<br>
+ return c->kind == InputSectionKind;<br>
}<br>
<br>
- StringMatcher FilePat;<br>
+ StringMatcher filePat;<br>
<br>
// Input sections that matches at least one of SectionPatterns<br>
// will be associated with this InputSectionDescription.<br>
- std::vector<SectionPattern> SectionPatterns;<br>
+ std::vector<SectionPattern> sectionPatterns;<br>
<br>
- std::vector<InputSection *> Sections;<br>
+ std::vector<InputSection *> sections;<br>
<br>
// Temporary record of synthetic ThunkSection instances and the pass that<br>
// they were created in. This is used to insert newly created ThunkSections<br>
// into Sections at the end of a createThunks() pass.<br>
- std::vector<std::pair<ThunkSection *, uint32_t>> ThunkSections;<br>
+ std::vector<std::pair<ThunkSection *, uint32_t>> thunkSections;<br>
};<br>
<br>
// Represents BYTE(), SHORT(), LONG(), or QUAD().<br>
struct ByteCommand : BaseCommand {<br>
- ByteCommand(Expr E, unsigned Size, std::string CommandString)<br>
- : BaseCommand(ByteKind), CommandString(CommandString), Expression(E),<br>
- Size(Size) {}<br>
+ ByteCommand(Expr e, unsigned size, std::string commandString)<br>
+ : BaseCommand(ByteKind), commandString(commandString), expression(e),<br>
+ size(size) {}<br>
<br>
- static bool classof(const BaseCommand *C) { return C->Kind == ByteKind; }<br>
+ static bool classof(const BaseCommand *c) { return c->kind == ByteKind; }<br>
<br>
// Keeps string representing the command. Used for -Map" is perhaps better.<br>
- std::string CommandString;<br>
+ std::string commandString;<br>
<br>
- Expr Expression;<br>
+ Expr expression;<br>
<br>
// This is just an offset of this assignment command in the output section.<br>
- unsigned Offset;<br>
+ unsigned offset;<br>
<br>
// Size of this data command.<br>
- unsigned Size;<br>
+ unsigned size;<br>
};<br>
<br>
struct PhdrsCommand {<br>
- StringRef Name;<br>
- unsigned Type = llvm::ELF::PT_NULL;<br>
- bool HasFilehdr = false;<br>
- bool HasPhdrs = false;<br>
- llvm::Optional<unsigned> Flags;<br>
- Expr LMAExpr = nullptr;<br>
+ StringRef name;<br>
+ unsigned type = llvm::ELF::PT_NULL;<br>
+ bool hasFilehdr = false;<br>
+ bool hasPhdrs = false;<br>
+ llvm::Optional<unsigned> flags;<br>
+ Expr lmaExpr = nullptr;<br>
};<br>
<br>
class LinkerScript final {<br>
@@ -211,35 +211,35 @@ class LinkerScript final {<br>
// not be used outside of the scope of a call to the above functions.<br>
struct AddressState {<br>
AddressState();<br>
- uint64_t ThreadBssOffset = 0;<br>
- OutputSection *OutSec = nullptr;<br>
- MemoryRegion *MemRegion = nullptr;<br>
- MemoryRegion *LMARegion = nullptr;<br>
- uint64_t LMAOffset = 0;<br>
+ uint64_t threadBssOffset = 0;<br>
+ OutputSection *outSec = nullptr;<br>
+ MemoryRegion *memRegion = nullptr;<br>
+ MemoryRegion *lmaRegion = nullptr;<br>
+ uint64_t lmaOffset = 0;<br>
};<br>
<br>
- llvm::DenseMap<StringRef, OutputSection *> NameToOutputSection;<br>
+ llvm::DenseMap<StringRef, OutputSection *> nameToOutputSection;<br>
<br>
- void addSymbol(SymbolAssignment *Cmd);<br>
- void assignSymbol(SymbolAssignment *Cmd, bool InSec);<br>
- void setDot(Expr E, const Twine &Loc, bool InSec);<br>
- void expandOutputSection(uint64_t Size);<br>
- void expandMemoryRegions(uint64_t Size);<br>
+ void addSymbol(SymbolAssignment *cmd);<br>
+ void assignSymbol(SymbolAssignment *cmd, bool inSec);<br>
+ void setDot(Expr e, const Twine &loc, bool inSec);<br>
+ void expandOutputSection(uint64_t size);<br>
+ void expandMemoryRegions(uint64_t size);<br>
<br>
std::vector<InputSection *><br>
computeInputSections(const InputSectionDescription *);<br>
<br>
- std::vector<InputSection *> createInputSectionList(OutputSection &Cmd);<br>
+ std::vector<InputSection *> createInputSectionList(OutputSection &cmd);<br>
<br>
- std::vector<size_t> getPhdrIndices(OutputSection *Sec);<br>
+ std::vector<size_t> getPhdrIndices(OutputSection *sec);<br>
<br>
- MemoryRegion *findMemoryRegion(OutputSection *Sec);<br>
+ MemoryRegion *findMemoryRegion(OutputSection *sec);<br>
<br>
- void switchTo(OutputSection *Sec);<br>
- uint64_t advance(uint64_t Size, unsigned Align);<br>
- void output(InputSection *Sec);<br>
+ void switchTo(OutputSection *sec);<br>
+ uint64_t advance(uint64_t size, unsigned align);<br>
+ void output(InputSection *sec);<br>
<br>
- void assignOffsets(OutputSection *Sec);<br>
+ void assignOffsets(OutputSection *sec);<br>
<br>
// Ctx captures the local AddressState and makes it accessible<br>
// deliberately. This is needed as there are some cases where we cannot just<br>
@@ -247,21 +247,21 @@ class LinkerScript final {<br>
// script parser.<br>
// This should remain a plain pointer as its lifetime is smaller than<br>
// LinkerScript.<br>
- AddressState *Ctx = nullptr;<br>
+ AddressState *ctx = nullptr;<br>
<br>
- OutputSection *Aether;<br>
+ OutputSection *aether;<br>
<br>
- uint64_t Dot;<br>
+ uint64_t dot;<br>
<br>
public:<br>
- OutputSection *createOutputSection(StringRef Name, StringRef Location);<br>
- OutputSection *getOrCreateOutputSection(StringRef Name);<br>
+ OutputSection *createOutputSection(StringRef name, StringRef location);<br>
+ OutputSection *getOrCreateOutputSection(StringRef name);<br>
<br>
- bool hasPhdrsCommands() { return !PhdrsCommands.empty(); }<br>
- uint64_t getDot() { return Dot; }<br>
- void discard(ArrayRef<InputSection *> V);<br>
+ bool hasPhdrsCommands() { return !phdrsCommands.empty(); }<br>
+ uint64_t getDot() { return dot; }<br>
+ void discard(ArrayRef<InputSection *> v);<br>
<br>
- ExprValue getSymbolValue(StringRef Name, const Twine &Loc);<br>
+ ExprValue getSymbolValue(StringRef name, const Twine &loc);<br>
<br>
void addOrphanSections();<br>
void adjustSectionsBeforeSorting();<br>
@@ -270,9 +270,9 @@ public:<br>
std::vector<PhdrEntry *> createPhdrs();<br>
bool needsInterpSection();<br>
<br>
- bool shouldKeep(InputSectionBase *S);<br>
+ bool shouldKeep(InputSectionBase *s);<br>
void assignAddresses();<br>
- void allocateHeaders(std::vector<PhdrEntry *> &Phdrs);<br>
+ void allocateHeaders(std::vector<PhdrEntry *> &phdrs);<br>
void processSectionCommands();<br>
void declareSymbols();<br>
<br>
@@ -280,31 +280,31 @@ public:<br>
void processInsertCommands();<br>
<br>
// SECTIONS command list.<br>
- std::vector<BaseCommand *> SectionCommands;<br>
+ std::vector<BaseCommand *> sectionCommands;<br>
<br>
// PHDRS command list.<br>
- std::vector<PhdrsCommand> PhdrsCommands;<br>
+ std::vector<PhdrsCommand> phdrsCommands;<br>
<br>
- bool HasSectionsCommand = false;<br>
- bool ErrorOnMissingSection = false;<br>
+ bool hasSectionsCommand = false;<br>
+ bool errorOnMissingSection = false;<br>
<br>
// List of section patterns specified with KEEP commands. They will<br>
// be kept even if they are unused and --gc-sections is specified.<br>
- std::vector<InputSectionDescription *> KeptSections;<br>
+ std::vector<InputSectionDescription *> keptSections;<br>
<br>
// A map from memory region name to a memory region descriptor.<br>
- llvm::MapVector<llvm::StringRef, MemoryRegion *> MemoryRegions;<br>
+ llvm::MapVector<llvm::StringRef, MemoryRegion *> memoryRegions;<br>
<br>
// A list of symbols referenced by the script.<br>
- std::vector<llvm::StringRef> ReferencedSymbols;<br>
+ std::vector<llvm::StringRef> referencedSymbols;<br>
<br>
// Used to implement INSERT [AFTER|BEFORE]. Contains commands that need<br>
// to be inserted into SECTIONS commands list.<br>
- llvm::DenseMap<StringRef, std::vector<BaseCommand *>> InsertAfterCommands;<br>
- llvm::DenseMap<StringRef, std::vector<BaseCommand *>> InsertBeforeCommands;<br>
+ llvm::DenseMap<StringRef, std::vector<BaseCommand *>> insertAfterCommands;<br>
+ llvm::DenseMap<StringRef, std::vector<BaseCommand *>> insertBeforeCommands;<br>
};<br>
<br>
-extern LinkerScript *Script;<br>
+extern LinkerScript *script;<br>
<br>
} // end namespace elf<br>
} // end namespace lld<br>
<br>
Modified: lld/trunk/ELF/MapFile.cpp<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_ELF_MapFile.cpp-3Frev-3D365595-26r1-3D365594-26r2-3D365595-26view-3Ddiff&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=DV0j7kv6ALbDYnbvb0v0NzYqJPlD0Vb-1XMCTCN5zXo&e=" rel="noreferrer" target="_blank">https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_ELF_MapFile.cpp-3Frev-3D365595-26r1-3D365594-26r2-3D365595-26view-3Ddiff&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=DV0j7kv6ALbDYnbvb0v0NzYqJPlD0Vb-1XMCTCN5zXo&e=</a> <br>
==============================================================================<br>
--- lld/trunk/ELF/MapFile.cpp (original)<br>
+++ lld/trunk/ELF/MapFile.cpp Tue Jul 9 22:00:37 2019<br>
@@ -39,65 +39,65 @@ using namespace lld::elf;<br>
<br>
using SymbolMapTy = DenseMap<const SectionBase *, SmallVector<Defined *, 4>>;<br>
<br>
-static const std::string Indent8 = " "; // 8 spaces<br>
-static const std::string Indent16 = " "; // 16 spaces<br>
+static const std::string indent8 = " "; // 8 spaces<br>
+static const std::string indent16 = " "; // 16 spaces<br>
<br>
// Print out the first three columns of a line.<br>
-static void writeHeader(raw_ostream &OS, uint64_t VMA, uint64_t LMA,<br>
- uint64_t Size, uint64_t Align) {<br>
- if (Config->Is64)<br>
- OS << format("%16llx %16llx %8llx %5lld ", VMA, LMA, Size, Align);<br>
+static void writeHeader(raw_ostream &os, uint64_t vma, uint64_t lma,<br>
+ uint64_t size, uint64_t align) {<br>
+ if (config->is64)<br>
+ os << format("%16llx %16llx %8llx %5lld ", vma, lma, size, align);<br>
else<br>
- OS << format("%8llx %8llx %8llx %5lld ", VMA, LMA, Size, Align);<br>
+ os << format("%8llx %8llx %8llx %5lld ", vma, lma, size, align);<br>
}<br>
<br>
// Returns a list of all symbols that we want to print out.<br>
static std::vector<Defined *> getSymbols() {<br>
- std::vector<Defined *> V;<br>
- for (InputFile *File : ObjectFiles)<br>
- for (Symbol *B : File->getSymbols())<br>
- if (auto *DR = dyn_cast<Defined>(B))<br>
- if (!DR->isSection() && DR->Section && DR->Section->isLive() &&<br>
- (DR->File == File || DR->NeedsPltAddr || DR->Section->Bss))<br>
- V.push_back(DR);<br>
- return V;<br>
+ std::vector<Defined *> v;<br>
+ for (InputFile *file : objectFiles)<br>
+ for (Symbol *b : file->getSymbols())<br>
+ if (auto *dr = dyn_cast<Defined>(b))<br>
+ if (!dr->isSection() && dr->section && dr->section->isLive() &&<br>
+ (dr->file == file || dr->needsPltAddr || dr->section->bss))<br>
+ v.push_back(dr);<br>
+ return v;<br>
}<br>
<br>
// Returns a map from sections to their symbols.<br>
-static SymbolMapTy getSectionSyms(ArrayRef<Defined *> Syms) {<br>
- SymbolMapTy Ret;<br>
- for (Defined *DR : Syms)<br>
- Ret[DR->Section].push_back(DR);<br>
+static SymbolMapTy getSectionSyms(ArrayRef<Defined *> syms) {<br>
+ SymbolMapTy ret;<br>
+ for (Defined *dr : syms)<br>
+ ret[dr->section].push_back(dr);<br>
<br>
// Sort symbols by address. We want to print out symbols in the<br>
// order in the output file rather than the order they appeared<br>
// in the input files.<br>
- for (auto &It : Ret)<br>
- llvm::stable_sort(It.second, [](Defined *A, Defined *B) {<br>
- return A->getVA() < B->getVA();<br>
+ for (auto &it : ret)<br>
+ llvm::stable_sort(it.second, [](Defined *a, Defined *b) {<br>
+ return a->getVA() < b->getVA();<br>
});<br>
- return Ret;<br>
+ return ret;<br>
}<br>
<br>
// Construct a map from symbols to their stringified representations.<br>
// Demangling symbols (which is what toString() does) is slow, so<br>
// we do that in batch using parallel-for.<br>
static DenseMap<Symbol *, std::string><br>
-getSymbolStrings(ArrayRef<Defined *> Syms) {<br>
- std::vector<std::string> Str(Syms.size());<br>
- parallelForEachN(0, Syms.size(), [&](size_t I) {<br>
- raw_string_ostream OS(Str[I]);<br>
- OutputSection *OSec = Syms[I]->getOutputSection();<br>
- uint64_t VMA = Syms[I]->getVA();<br>
- uint64_t LMA = OSec ? OSec->getLMA() + VMA - OSec->getVA(0) : 0;<br>
- writeHeader(OS, VMA, LMA, Syms[I]->getSize(), 1);<br>
- OS << Indent16 << toString(*Syms[I]);<br>
+getSymbolStrings(ArrayRef<Defined *> syms) {<br>
+ std::vector<std::string> str(syms.size());<br>
+ parallelForEachN(0, syms.size(), [&](size_t i) {<br>
+ raw_string_ostream os(str[i]);<br>
+ OutputSection *osec = syms[i]->getOutputSection();<br>
+ uint64_t vma = syms[i]->getVA();<br>
+ uint64_t lma = osec ? osec->getLMA() + vma - osec->getVA(0) : 0;<br>
+ writeHeader(os, vma, lma, syms[i]->getSize(), 1);<br>
+ os << indent16 << toString(*syms[i]);<br>
});<br>
<br>
- DenseMap<Symbol *, std::string> Ret;<br>
- for (size_t I = 0, E = Syms.size(); I < E; ++I)<br>
- Ret[Syms[I]] = std::move(Str[I]);<br>
- return Ret;<br>
+ DenseMap<Symbol *, std::string> ret;<br>
+ for (size_t i = 0, e = syms.size(); i < e; ++i)<br>
+ ret[syms[i]] = std::move(str[i]);<br>
+ return ret;<br>
}<br>
<br>
// Print .eh_frame contents. Since the section consists of EhSectionPieces,<br>
@@ -106,115 +106,115 @@ getSymbolStrings(ArrayRef<Defined *> Sym<br>
// .eh_frame tend to contain a lot of section pieces that are contiguous<br>
// both in input file and output file. Such pieces are squashed before<br>
// being displayed to make output compact.<br>
-static void printEhFrame(raw_ostream &OS, const EhFrameSection *Sec) {<br>
- std::vector<EhSectionPiece> Pieces;<br>
+static void printEhFrame(raw_ostream &os, const EhFrameSection *sec) {<br>
+ std::vector<EhSectionPiece> pieces;<br>
<br>
- auto Add = [&](const EhSectionPiece &P) {<br>
+ auto add = [&](const EhSectionPiece &p) {<br>
// If P is adjacent to Last, squash the two.<br>
- if (!Pieces.empty()) {<br>
- EhSectionPiece &Last = Pieces.back();<br>
- if (Last.Sec == P.Sec && Last.InputOff + Last.Size == P.InputOff &&<br>
- Last.OutputOff + Last.Size == P.OutputOff) {<br>
- Last.Size += P.Size;<br>
+ if (!pieces.empty()) {<br>
+ EhSectionPiece &last = pieces.back();<br>
+ if (last.sec == p.sec && last.inputOff + last.size == p.inputOff &&<br>
+ last.outputOff + last.size == p.outputOff) {<br>
+ last.size += p.size;<br>
return;<br>
}<br>
}<br>
- Pieces.push_back(P);<br>
+ pieces.push_back(p);<br>
};<br>
<br>
// Gather section pieces.<br>
- for (const CieRecord *Rec : Sec->getCieRecords()) {<br>
- Add(*Rec->Cie);<br>
- for (const EhSectionPiece *Fde : Rec->Fdes)<br>
- Add(*Fde);<br>
+ for (const CieRecord *rec : sec->getCieRecords()) {<br>
+ add(*rec->cie);<br>
+ for (const EhSectionPiece *fde : rec->fdes)<br>
+ add(*fde);<br>
}<br>
<br>
// Print out section pieces.<br>
- const OutputSection *OSec = Sec->getOutputSection();<br>
- for (EhSectionPiece &P : Pieces) {<br>
- writeHeader(OS, OSec->Addr + P.OutputOff, OSec->getLMA() + P.OutputOff,<br>
- P.Size, 1);<br>
- OS << Indent8 << toString(P.Sec->File) << ":(" << P.Sec->Name << "+0x"<br>
- << Twine::utohexstr(P.InputOff) + ")\n";<br>
+ const OutputSection *osec = sec->getOutputSection();<br>
+ for (EhSectionPiece &p : pieces) {<br>
+ writeHeader(os, osec->addr + p.outputOff, osec->getLMA() + p.outputOff,<br>
+ p.size, 1);<br>
+ os << indent8 << toString(p.sec->file) << ":(" << p.sec->name << "+0x"<br>
+ << Twine::utohexstr(p.inputOff) + ")\n";<br>
}<br>
}<br>
<br>
void elf::writeMapFile() {<br>
- if (Config->MapFile.empty())<br>
+ if (config->mapFile.empty())<br>
return;<br>
<br>
// Open a map file for writing.<br>
- std::error_code EC;<br>
- raw_fd_ostream OS(Config->MapFile, EC, sys::fs::F_None);<br>
- if (EC) {<br>
- error("cannot open " + Config->MapFile + ": " + EC.message());<br>
+ std::error_code ec;<br>
+ raw_fd_ostream os(config->mapFile, ec, sys::fs::F_None);<br>
+ if (ec) {<br>
+ error("cannot open " + config->mapFile + ": " + ec.message());<br>
return;<br>
}<br>
<br>
// Collect symbol info that we want to print out.<br>
- std::vector<Defined *> Syms = getSymbols();<br>
- SymbolMapTy SectionSyms = getSectionSyms(Syms);<br>
- DenseMap<Symbol *, std::string> SymStr = getSymbolStrings(Syms);<br>
+ std::vector<Defined *> syms = getSymbols();<br>
+ SymbolMapTy sectionSyms = getSectionSyms(syms);<br>
+ DenseMap<Symbol *, std::string> symStr = getSymbolStrings(syms);<br>
<br>
// Print out the header line.<br>
- int W = Config->Is64 ? 16 : 8;<br>
- OS << right_justify("VMA", W) << ' ' << right_justify("LMA", W)<br>
+ int w = config->is64 ? 16 : 8;<br>
+ os << right_justify("VMA", w) << ' ' << right_justify("LMA", w)<br>
<< " Size Align Out In Symbol\n";<br>
<br>
- OutputSection* OSec = nullptr;<br>
- for (BaseCommand *Base : Script->SectionCommands) {<br>
- if (auto *Cmd = dyn_cast<SymbolAssignment>(Base)) {<br>
- if (Cmd->Provide && !Cmd->Sym)<br>
+ OutputSection* osec = nullptr;<br>
+ for (BaseCommand *base : script->sectionCommands) {<br>
+ if (auto *cmd = dyn_cast<SymbolAssignment>(base)) {<br>
+ if (cmd->provide && !cmd->sym)<br>
continue;<br>
- uint64_t LMA = OSec ? OSec->getLMA() + Cmd->Addr - OSec->getVA(0) : 0;<br>
- writeHeader(OS, Cmd->Addr, LMA, Cmd->Size, 1);<br>
- OS << Cmd->CommandString << '\n';<br>
+ uint64_t lma = osec ? osec->getLMA() + cmd->addr - osec->getVA(0) : 0;<br>
+ writeHeader(os, cmd->addr, lma, cmd->size, 1);<br>
+ os << cmd->commandString << '\n';<br>
continue;<br>
}<br>
<br>
- OSec = cast<OutputSection>(Base);<br>
- writeHeader(OS, OSec->Addr, OSec->getLMA(), OSec->Size, OSec->Alignment);<br>
- OS << OSec->Name << '\n';<br>
+ osec = cast<OutputSection>(base);<br>
+ writeHeader(os, osec->addr, osec->getLMA(), osec->size, osec->alignment);<br>
+ os << osec->name << '\n';<br>
<br>
// Dump symbols for each input section.<br>
- for (BaseCommand *Base : OSec->SectionCommands) {<br>
- if (auto *ISD = dyn_cast<InputSectionDescription>(Base)) {<br>
- for (InputSection *IS : ISD->Sections) {<br>
- if (auto *EhSec = dyn_cast<EhFrameSection>(IS)) {<br>
- printEhFrame(OS, EhSec);<br>
+ for (BaseCommand *base : osec->sectionCommands) {<br>
+ if (auto *isd = dyn_cast<InputSectionDescription>(base)) {<br>
+ for (InputSection *isec : isd->sections) {<br>
+ if (auto *ehSec = dyn_cast<EhFrameSection>(isec)) {<br>
+ printEhFrame(os, ehSec);<br>
continue;<br>
}<br>
<br>
- writeHeader(OS, IS->getVA(0), OSec->getLMA() + IS->getOffset(0),<br>
- IS->getSize(), IS->Alignment);<br>
- OS << Indent8 << toString(IS) << '\n';<br>
- for (Symbol *Sym : SectionSyms[IS])<br>
- OS << SymStr[Sym] << '\n';<br>
+ writeHeader(os, isec->getVA(0), osec->getLMA() + isec->getOffset(0),<br>
+ isec->getSize(), isec->alignment);<br>
+ os << indent8 << toString(isec) << '\n';<br>
+ for (Symbol *sym : sectionSyms[isec])<br>
+ os << symStr[sym] << '\n';<br>
}<br>
continue;<br>
}<br>
<br>
- if (auto *Cmd = dyn_cast<ByteCommand>(Base)) {<br>
- writeHeader(OS, OSec->Addr + Cmd->Offset, OSec->getLMA() + Cmd->Offset,<br>
- Cmd->Size, 1);<br>
- OS << Indent8 << Cmd->CommandString << '\n';<br>
+ if (auto *cmd = dyn_cast<ByteCommand>(base)) {<br>
+ writeHeader(os, osec->addr + cmd->offset, osec->getLMA() + cmd->offset,<br>
+ cmd->size, 1);<br>
+ os << indent8 << cmd->commandString << '\n';<br>
continue;<br>
}<br>
<br>
- if (auto *Cmd = dyn_cast<SymbolAssignment>(Base)) {<br>
- if (Cmd->Provide && !Cmd->Sym)<br>
+ if (auto *cmd = dyn_cast<SymbolAssignment>(base)) {<br>
+ if (cmd->provide && !cmd->sym)<br>
continue;<br>
- writeHeader(OS, Cmd->Addr, OSec->getLMA() + Cmd->Addr - OSec->getVA(0),<br>
- Cmd->Size, 1);<br>
- OS << Indent8 << Cmd->CommandString << '\n';<br>
+ writeHeader(os, cmd->addr, osec->getLMA() + cmd->addr - osec->getVA(0),<br>
+ cmd->size, 1);<br>
+ os << indent8 << cmd->commandString << '\n';<br>
continue;<br>
}<br>
}<br>
}<br>
}<br>
<br>
-static void print(StringRef A, StringRef B) {<br>
- outs() << left_justify(A, 49) << " " << B << "\n";<br>
+static void print(StringRef a, StringRef b) {<br>
+ outs() << left_justify(a, 49) << " " << b << "\n";<br>
}<br>
<br>
// Output a cross reference table to stdout. This is for --cref.<br>
@@ -229,18 +229,18 @@ static void print(StringRef A, StringRef<br>
// In this case, strlen is defined by libc.so.6 and used by other two<br>
// files.<br>
void elf::writeCrossReferenceTable() {<br>
- if (!Config->Cref)<br>
+ if (!config->cref)<br>
return;<br>
<br>
// Collect symbols and files.<br>
- MapVector<Symbol *, SetVector<InputFile *>> Map;<br>
- for (InputFile *File : ObjectFiles) {<br>
- for (Symbol *Sym : File->getSymbols()) {<br>
- if (isa<SharedSymbol>(Sym))<br>
- Map[Sym].insert(File);<br>
- if (auto *D = dyn_cast<Defined>(Sym))<br>
- if (!D->isLocal() && (!D->Section || D->Section->isLive()))<br>
- Map[D].insert(File);<br>
+ MapVector<Symbol *, SetVector<InputFile *>> map;<br>
+ for (InputFile *file : objectFiles) {<br>
+ for (Symbol *sym : file->getSymbols()) {<br>
+ if (isa<SharedSymbol>(sym))<br>
+ map[sym].insert(file);<br>
+ if (auto *d = dyn_cast<Defined>(sym))<br>
+ if (!d->isLocal() && (!d->section || d->section->isLive()))<br>
+ map[d].insert(file);<br>
}<br>
}<br>
<br>
@@ -249,13 +249,13 @@ void elf::writeCrossReferenceTable() {<br>
print("Symbol", "File");<br>
<br>
// Print out a table.<br>
- for (auto KV : Map) {<br>
- Symbol *Sym = KV.first;<br>
- SetVector<InputFile *> &Files = KV.second;<br>
-<br>
- print(toString(*Sym), toString(Sym->File));<br>
- for (InputFile *File : Files)<br>
- if (File != Sym->File)<br>
- print("", toString(File));<br>
+ for (auto kv : map) {<br>
+ Symbol *sym = kv.first;<br>
+ SetVector<InputFile *> &files = kv.second;<br>
+<br>
+ print(toString(*sym), toString(sym->file));<br>
+ for (InputFile *file : files)<br>
+ if (file != sym->file)<br>
+ print("", toString(file));<br>
}<br>
}<br>
<br>
Modified: lld/trunk/ELF/MarkLive.cpp<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_ELF_MarkLive.cpp-3Frev-3D365595-26r1-3D365594-26r2-3D365595-26view-3Ddiff&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=TrkJUpXOIQbq5R4KCX3iFy8_V5IK2MGUNU3rf5VYhQw&e=" rel="noreferrer" target="_blank">https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_ELF_MarkLive.cpp-3Frev-3D365595-26r1-3D365594-26r2-3D365595-26view-3Ddiff&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=TrkJUpXOIQbq5R4KCX3iFy8_V5IK2MGUNU3rf5VYhQw&e=</a> <br>
==============================================================================<br>
--- lld/trunk/ELF/MarkLive.cpp (original)<br>
+++ lld/trunk/ELF/MarkLive.cpp Tue Jul 9 22:00:37 2019<br>
@@ -45,76 +45,76 @@ using namespace lld::elf;<br>
namespace {<br>
template <class ELFT> class MarkLive {<br>
public:<br>
- MarkLive(unsigned Partition) : Partition(Partition) {}<br>
+ MarkLive(unsigned partition) : partition(partition) {}<br>
<br>
void run();<br>
void moveToMain();<br>
<br>
private:<br>
- void enqueue(InputSectionBase *Sec, uint64_t Offset);<br>
- void markSymbol(Symbol *Sym);<br>
+ void enqueue(InputSectionBase *sec, uint64_t offset);<br>
+ void markSymbol(Symbol *sym);<br>
void mark();<br>
<br>
template <class RelTy><br>
- void resolveReloc(InputSectionBase &Sec, RelTy &Rel, bool IsLSDA);<br>
+ void resolveReloc(InputSectionBase &sec, RelTy &rel, bool isLSDA);<br>
<br>
template <class RelTy><br>
- void scanEhFrameSection(EhInputSection &EH, ArrayRef<RelTy> Rels);<br>
+ void scanEhFrameSection(EhInputSection &eh, ArrayRef<RelTy> rels);<br>
<br>
// The index of the partition that we are currently processing.<br>
- unsigned Partition;<br>
+ unsigned partition;<br>
<br>
// A list of sections to visit.<br>
- SmallVector<InputSection *, 256> Queue;<br>
+ SmallVector<InputSection *, 256> queue;<br>
<br>
// There are normally few input sections whose names are valid C<br>
// identifiers, so we just store a std::vector instead of a multimap.<br>
- DenseMap<StringRef, std::vector<InputSectionBase *>> CNamedSections;<br>
+ DenseMap<StringRef, std::vector<InputSectionBase *>> cNamedSections;<br>
};<br>
} // namespace<br>
<br>
template <class ELFT><br>
-static uint64_t getAddend(InputSectionBase &Sec,<br>
- const typename ELFT::Rel &Rel) {<br>
- return Target->getImplicitAddend(Sec.data().begin() + Rel.r_offset,<br>
- Rel.getType(Config->IsMips64EL));<br>
+static uint64_t getAddend(InputSectionBase &sec,<br>
+ const typename ELFT::Rel &rel) {<br>
+ return target->getImplicitAddend(sec.data().begin() + rel.r_offset,<br>
+ rel.getType(config->isMips64EL));<br>
}<br>
<br>
template <class ELFT><br>
-static uint64_t getAddend(InputSectionBase &Sec,<br>
- const typename ELFT::Rela &Rel) {<br>
- return Rel.r_addend;<br>
+static uint64_t getAddend(InputSectionBase &sec,<br>
+ const typename ELFT::Rela &rel) {<br>
+ return rel.r_addend;<br>
}<br>
<br>
template <class ELFT><br>
template <class RelTy><br>
-void MarkLive<ELFT>::resolveReloc(InputSectionBase &Sec, RelTy &Rel,<br>
- bool IsLSDA) {<br>
- Symbol &Sym = Sec.getFile<ELFT>()->getRelocTargetSym(Rel);<br>
+void MarkLive<ELFT>::resolveReloc(InputSectionBase &sec, RelTy &rel,<br>
+ bool isLSDA) {<br>
+ Symbol &sym = sec.getFile<ELFT>()->getRelocTargetSym(rel);<br>
<br>
// If a symbol is referenced in a live section, it is used.<br>
- Sym.Used = true;<br>
+ sym.used = true;<br>
<br>
- if (auto *D = dyn_cast<Defined>(&Sym)) {<br>
- auto *RelSec = dyn_cast_or_null<InputSectionBase>(D->Section);<br>
- if (!RelSec)<br>
+ if (auto *d = dyn_cast<Defined>(&sym)) {<br>
+ auto *relSec = dyn_cast_or_null<InputSectionBase>(d->section);<br>
+ if (!relSec)<br>
return;<br>
<br>
- uint64_t Offset = D->Value;<br>
- if (D->isSection())<br>
- Offset += getAddend<ELFT>(Sec, Rel);<br>
+ uint64_t offset = d->value;<br>
+ if (d->isSection())<br>
+ offset += getAddend<ELFT>(sec, rel);<br>
<br>
- if (!IsLSDA || !(RelSec->Flags & SHF_EXECINSTR))<br>
- enqueue(RelSec, Offset);<br>
+ if (!isLSDA || !(relSec->flags & SHF_EXECINSTR))<br>
+ enqueue(relSec, offset);<br>
return;<br>
}<br>
<br>
- if (auto *SS = dyn_cast<SharedSymbol>(&Sym))<br>
- if (!SS->isWeak())<br>
- SS->getFile().IsNeeded = true;<br>
+ if (auto *ss = dyn_cast<SharedSymbol>(&sym))<br>
+ if (!ss->isWeak())<br>
+ ss->getFile().isNeeded = true;<br>
<br>
- for (InputSectionBase *Sec : CNamedSections.lookup(Sym.getName()))<br>
- enqueue(Sec, 0);<br>
+ for (InputSectionBase *sec : cNamedSections.lookup(sym.getName()))<br>
+ enqueue(sec, 0);<br>
}<br>
<br>
// The .eh_frame section is an unfortunate special case.<br>
@@ -133,80 +133,80 @@ void MarkLive<ELFT>::resolveReloc(InputS<br>
// LSDAs and personality functions if we found that they were unused.<br>
template <class ELFT><br>
template <class RelTy><br>
-void MarkLive<ELFT>::scanEhFrameSection(EhInputSection &EH,<br>
- ArrayRef<RelTy> Rels) {<br>
- for (size_t I = 0, End = EH.Pieces.size(); I < End; ++I) {<br>
- EhSectionPiece &Piece = EH.Pieces[I];<br>
- size_t FirstRelI = Piece.FirstRelocation;<br>
- if (FirstRelI == (unsigned)-1)<br>
+void MarkLive<ELFT>::scanEhFrameSection(EhInputSection &eh,<br>
+ ArrayRef<RelTy> rels) {<br>
+ for (size_t i = 0, end = eh.pieces.size(); i < end; ++i) {<br>
+ EhSectionPiece &piece = eh.pieces[i];<br>
+ size_t firstRelI = piece.firstRelocation;<br>
+ if (firstRelI == (unsigned)-1)<br>
continue;<br>
<br>
- if (read32<ELFT::TargetEndianness>(Piece.data().data() + 4) == 0) {<br>
+ if (read32<ELFT::TargetEndianness>(piece.data().data() + 4) == 0) {<br>
// This is a CIE, we only need to worry about the first relocation. It is<br>
// known to point to the personality function.<br>
- resolveReloc(EH, Rels[FirstRelI], false);<br>
+ resolveReloc(eh, rels[firstRelI], false);<br>
continue;<br>
}<br>
<br>
// This is a FDE. The relocations point to the described function or to<br>
// a LSDA. We only need to keep the LSDA alive, so ignore anything that<br>
// points to executable sections.<br>
- uint64_t PieceEnd = Piece.InputOff + Piece.Size;<br>
- for (size_t J = FirstRelI, End2 = Rels.size(); J < End2; ++J)<br>
- if (Rels[J].r_offset < PieceEnd)<br>
- resolveReloc(EH, Rels[J], true);<br>
+ uint64_t pieceEnd = piece.inputOff + piece.size;<br>
+ for (size_t j = firstRelI, end2 = rels.size(); j < end2; ++j)<br>
+ if (rels[j].r_offset < pieceEnd)<br>
+ resolveReloc(eh, rels[j], true);<br>
}<br>
}<br>
<br>
// Some sections are used directly by the loader, so they should never be<br>
// garbage-collected. This function returns true if a given section is such<br>
// section.<br>
-static bool isReserved(InputSectionBase *Sec) {<br>
- switch (Sec->Type) {<br>
+static bool isReserved(InputSectionBase *sec) {<br>
+ switch (sec->type) {<br>
case SHT_FINI_ARRAY:<br>
case SHT_INIT_ARRAY:<br>
case SHT_NOTE:<br>
case SHT_PREINIT_ARRAY:<br>
return true;<br>
default:<br>
- StringRef S = Sec->Name;<br>
- return S.startswith(".ctors") || S.startswith(".dtors") ||<br>
- S.startswith(".init") || S.startswith(".fini") ||<br>
- S.startswith(".jcr");<br>
+ StringRef s = sec->name;<br>
+ return s.startswith(".ctors") || s.startswith(".dtors") ||<br>
+ s.startswith(".init") || s.startswith(".fini") ||<br>
+ s.startswith(".jcr");<br>
}<br>
}<br>
<br>
template <class ELFT><br>
-void MarkLive<ELFT>::enqueue(InputSectionBase *Sec, uint64_t Offset) {<br>
+void MarkLive<ELFT>::enqueue(InputSectionBase *sec, uint64_t offset) {<br>
// Skip over discarded sections. This in theory shouldn't happen, because<br>
// the ELF spec doesn't allow a relocation to point to a deduplicated<br>
// COMDAT section directly. Unfortunately this happens in practice (e.g.<br>
// .eh_frame) so we need to add a check.<br>
- if (Sec == &InputSection::Discarded)<br>
+ if (sec == &InputSection::discarded)<br>
return;<br>
<br>
// Usually, a whole section is marked as live or dead, but in mergeable<br>
// (splittable) sections, each piece of data has independent liveness bit.<br>
// So we explicitly tell it which offset is in use.<br>
- if (auto *MS = dyn_cast<MergeInputSection>(Sec))<br>
- MS->getSectionPiece(Offset)->Live = true;<br>
+ if (auto *ms = dyn_cast<MergeInputSection>(sec))<br>
+ ms->getSectionPiece(offset)->live = true;<br>
<br>
// Set Sec->Partition to the meet (i.e. the "minimum") of Partition and<br>
// Sec->Partition in the following lattice: 1 < other < 0. If Sec->Partition<br>
// doesn't change, we don't need to do anything.<br>
- if (Sec->Partition == 1 || Sec->Partition == Partition)<br>
+ if (sec->partition == 1 || sec->partition == partition)<br>
return;<br>
- Sec->Partition = Sec->Partition ? 1 : Partition;<br>
+ sec->partition = sec->partition ? 1 : partition;<br>
<br>
// Add input section to the queue.<br>
- if (InputSection *S = dyn_cast<InputSection>(Sec))<br>
- Queue.push_back(S);<br>
+ if (InputSection *s = dyn_cast<InputSection>(sec))<br>
+ queue.push_back(s);<br>
}<br>
<br>
-template <class ELFT> void MarkLive<ELFT>::markSymbol(Symbol *Sym) {<br>
- if (auto *D = dyn_cast_or_null<Defined>(Sym))<br>
- if (auto *IS = dyn_cast_or_null<InputSectionBase>(D->Section))<br>
- enqueue(IS, D->Value);<br>
+template <class ELFT> void MarkLive<ELFT>::markSymbol(Symbol *sym) {<br>
+ if (auto *d = dyn_cast_or_null<Defined>(sym))<br>
+ if (auto *isec = dyn_cast_or_null<InputSectionBase>(d->section))<br>
+ enqueue(isec, d->value);<br>
}<br>
<br>
// This is the main function of the garbage collector.<br>
@@ -217,51 +217,51 @@ template <class ELFT> void MarkLive<ELFT<br>
<br>
// Preserve externally-visible symbols if the symbols defined by this<br>
// file can interrupt other ELF file's symbols at runtime.<br>
- Symtab->forEachSymbol([&](Symbol *Sym) {<br>
- if (Sym->includeInDynsym() && Sym->Partition == Partition)<br>
- markSymbol(Sym);<br>
+ symtab->forEachSymbol([&](Symbol *sym) {<br>
+ if (sym->includeInDynsym() && sym->partition == partition)<br>
+ markSymbol(sym);<br>
});<br>
<br>
// If this isn't the main partition, that's all that we need to preserve.<br>
- if (Partition != 1) {<br>
+ if (partition != 1) {<br>
mark();<br>
return;<br>
}<br>
<br>
- markSymbol(Symtab->find(Config->Entry));<br>
- markSymbol(Symtab->find(Config->Init));<br>
- markSymbol(Symtab->find(Config->Fini));<br>
- for (StringRef S : Config->Undefined)<br>
- markSymbol(Symtab->find(S));<br>
- for (StringRef S : Script->ReferencedSymbols)<br>
- markSymbol(Symtab->find(S));<br>
+ markSymbol(symtab->find(config->entry));<br>
+ markSymbol(symtab->find(config->init));<br>
+ markSymbol(symtab->find(config->fini));<br>
+ for (StringRef s : config->undefined)<br>
+ markSymbol(symtab->find(s));<br>
+ for (StringRef s : script->referencedSymbols)<br>
+ markSymbol(symtab->find(s));<br>
<br>
// Preserve special sections and those which are specified in linker<br>
// script KEEP command.<br>
- for (InputSectionBase *Sec : InputSections) {<br>
+ for (InputSectionBase *sec : inputSections) {<br>
// Mark .eh_frame sections as live because there are usually no relocations<br>
// that point to .eh_frames. Otherwise, the garbage collector would drop<br>
// all of them. We also want to preserve personality routines and LSDA<br>
// referenced by .eh_frame sections, so we scan them for that here.<br>
- if (auto *EH = dyn_cast<EhInputSection>(Sec)) {<br>
- EH->markLive();<br>
- if (!EH->NumRelocations)<br>
+ if (auto *eh = dyn_cast<EhInputSection>(sec)) {<br>
+ eh->markLive();<br>
+ if (!eh->numRelocations)<br>
continue;<br>
<br>
- if (EH->AreRelocsRela)<br>
- scanEhFrameSection(*EH, EH->template relas<ELFT>());<br>
+ if (eh->areRelocsRela)<br>
+ scanEhFrameSection(*eh, eh->template relas<ELFT>());<br>
else<br>
- scanEhFrameSection(*EH, EH->template rels<ELFT>());<br>
+ scanEhFrameSection(*eh, eh->template rels<ELFT>());<br>
}<br>
<br>
- if (Sec->Flags & SHF_LINK_ORDER)<br>
+ if (sec->flags & SHF_LINK_ORDER)<br>
continue;<br>
<br>
- if (isReserved(Sec) || Script->shouldKeep(Sec)) {<br>
- enqueue(Sec, 0);<br>
- } else if (isValidCIdentifier(Sec->Name)) {<br>
- CNamedSections[Saver.save("__start_" + Sec->Name)].push_back(Sec);<br>
- CNamedSections[Saver.save("__stop_" + Sec->Name)].push_back(Sec);<br>
+ if (isReserved(sec) || script->shouldKeep(sec)) {<br>
+ enqueue(sec, 0);<br>
+ } else if (isValidCIdentifier(sec->name)) {<br>
+ cNamedSections[Saver.save("__start_" + sec->name)].push_back(sec);<br>
+ cNamedSections[Saver.save("__stop_" + sec->name)].push_back(sec);<br>
}<br>
}<br>
<br>
@@ -270,19 +270,19 @@ template <class ELFT> void MarkLive<ELFT<br>
<br>
template <class ELFT> void MarkLive<ELFT>::mark() {<br>
// Mark all reachable sections.<br>
- while (!Queue.empty()) {<br>
- InputSectionBase &Sec = *Queue.pop_back_val();<br>
+ while (!queue.empty()) {<br>
+ InputSectionBase &sec = *queue.pop_back_val();<br>
<br>
- if (Sec.AreRelocsRela) {<br>
- for (const typename ELFT::Rela &Rel : Sec.template relas<ELFT>())<br>
- resolveReloc(Sec, Rel, false);<br>
+ if (sec.areRelocsRela) {<br>
+ for (const typename ELFT::Rela &rel : sec.template relas<ELFT>())<br>
+ resolveReloc(sec, rel, false);<br>
} else {<br>
- for (const typename ELFT::Rel &Rel : Sec.template rels<ELFT>())<br>
- resolveReloc(Sec, Rel, false);<br>
+ for (const typename ELFT::Rel &rel : sec.template rels<ELFT>())<br>
+ resolveReloc(sec, rel, false);<br>
}<br>
<br>
- for (InputSectionBase *IS : Sec.DependentSections)<br>
- enqueue(IS, 0);<br>
+ for (InputSectionBase *isec : sec.dependentSections)<br>
+ enqueue(isec, 0);<br>
}<br>
}<br>
<br>
@@ -292,12 +292,12 @@ template <class ELFT> void MarkLive<ELFT<br>
// loaded) and TLS symbols (because we only know how to correctly process TLS<br>
// relocations for the main partition).<br>
template <class ELFT> void MarkLive<ELFT>::moveToMain() {<br>
- for (InputFile *File : ObjectFiles)<br>
- for (Symbol *S : File->getSymbols())<br>
- if (auto *D = dyn_cast<Defined>(S))<br>
- if ((D->Type == STT_GNU_IFUNC || D->Type == STT_TLS) && D->Section &&<br>
- D->Section->isLive())<br>
- markSymbol(S);<br>
+ for (InputFile *file : objectFiles)<br>
+ for (Symbol *s : file->getSymbols())<br>
+ if (auto *d = dyn_cast<Defined>(s))<br>
+ if ((d->type == STT_GNU_IFUNC || d->type == STT_TLS) && d->section &&<br>
+ d->section->isLive())<br>
+ markSymbol(s);<br>
<br>
mark();<br>
}<br>
@@ -307,15 +307,15 @@ template <class ELFT> void MarkLive<ELFT<br>
// so that they are emitted to the output file.<br>
template <class ELFT> void elf::markLive() {<br>
// If -gc-sections is not given, no sections are removed.<br>
- if (!Config->GcSections) {<br>
- for (InputSectionBase *Sec : InputSections)<br>
- Sec->markLive();<br>
+ if (!config->gcSections) {<br>
+ for (InputSectionBase *sec : inputSections)<br>
+ sec->markLive();<br>
<br>
// If a DSO defines a symbol referenced in a regular object, it is needed.<br>
- Symtab->forEachSymbol([](Symbol *Sym) {<br>
- if (auto *S = dyn_cast<SharedSymbol>(Sym))<br>
- if (S->IsUsedInRegularObj && !S->isWeak())<br>
- S->getFile().IsNeeded = true;<br>
+ symtab->forEachSymbol([](Symbol *sym) {<br>
+ if (auto *s = dyn_cast<SharedSymbol>(sym))<br>
+ if (s->isUsedInRegularObj && !s->isWeak())<br>
+ s->getFile().isNeeded = true;<br>
});<br>
return;<br>
}<br>
@@ -341,30 +341,30 @@ template <class ELFT> void elf::markLive<br>
// or -emit-reloc were given. And they are subject of garbage<br>
// collection because, if we remove a text section, we also<br>
// remove its relocation section.<br>
- for (InputSectionBase *Sec : InputSections) {<br>
- bool IsAlloc = (Sec->Flags & SHF_ALLOC);<br>
- bool IsLinkOrder = (Sec->Flags & SHF_LINK_ORDER);<br>
- bool IsRel = (Sec->Type == SHT_REL || Sec->Type == SHT_RELA);<br>
+ for (InputSectionBase *sec : inputSections) {<br>
+ bool isAlloc = (sec->flags & SHF_ALLOC);<br>
+ bool isLinkOrder = (sec->flags & SHF_LINK_ORDER);<br>
+ bool isRel = (sec->type == SHT_REL || sec->type == SHT_RELA);<br>
<br>
- if (!IsAlloc && !IsLinkOrder && !IsRel)<br>
- Sec->markLive();<br>
+ if (!isAlloc && !isLinkOrder && !isRel)<br>
+ sec->markLive();<br>
}<br>
<br>
// Follow the graph to mark all live sections.<br>
- for (unsigned CurPart = 1; CurPart <= Partitions.size(); ++CurPart)<br>
- MarkLive<ELFT>(CurPart).run();<br>
+ for (unsigned curPart = 1; curPart <= partitions.size(); ++curPart)<br>
+ MarkLive<ELFT>(curPart).run();<br>
<br>
// If we have multiple partitions, some sections need to live in the main<br>
// partition even if they were allocated to a loadable partition. Move them<br>
// there now.<br>
- if (Partitions.size() != 1)<br>
+ if (partitions.size() != 1)<br>
MarkLive<ELFT>(1).moveToMain();<br>
<br>
// Report garbage-collected sections.<br>
- if (Config->PrintGcSections)<br>
- for (InputSectionBase *Sec : InputSections)<br>
- if (!Sec->isLive())<br>
- message("removing unused section " + toString(Sec));<br>
+ if (config->printGcSections)<br>
+ for (InputSectionBase *sec : inputSections)<br>
+ if (!sec->isLive())<br>
+ message("removing unused section " + toString(sec));<br>
}<br>
<br>
template void elf::markLive<ELF32LE>();<br>
<br>
Modified: lld/trunk/ELF/OutputSections.cpp<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_ELF_OutputSections.cpp-3Frev-3D365595-26r1-3D365594-26r2-3D365595-26view-3Ddiff&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=UVTokxJaAliERGw5ZRPaBQW2iLQTkwBdSYMAbkicE8g&e=" rel="noreferrer" target="_blank">https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_ELF_OutputSections.cpp-3Frev-3D365595-26r1-3D365594-26r2-3D365595-26view-3Ddiff&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=UVTokxJaAliERGw5ZRPaBQW2iLQTkwBdSYMAbkicE8g&e=</a> <br>
==============================================================================<br>
--- lld/trunk/ELF/OutputSections.cpp (original)<br>
+++ lld/trunk/ELF/OutputSections.cpp Tue Jul 9 22:00:37 2019<br>
@@ -30,45 +30,45 @@ using namespace llvm::ELF;<br>
using namespace lld;<br>
using namespace lld::elf;<br>
<br>
-uint8_t *Out::BufferStart;<br>
-uint8_t Out::First;<br>
-PhdrEntry *Out::TlsPhdr;<br>
-OutputSection *Out::ElfHeader;<br>
-OutputSection *Out::ProgramHeaders;<br>
-OutputSection *Out::PreinitArray;<br>
-OutputSection *Out::InitArray;<br>
-OutputSection *Out::FiniArray;<br>
+uint8_t *Out::bufferStart;<br>
+uint8_t Out::first;<br>
+PhdrEntry *Out::tlsPhdr;<br>
+OutputSection *Out::elfHeader;<br>
+OutputSection *Out::programHeaders;<br>
+OutputSection *Out::preinitArray;<br>
+OutputSection *Out::initArray;<br>
+OutputSection *Out::finiArray;<br>
<br>
-std::vector<OutputSection *> elf::OutputSections;<br>
+std::vector<OutputSection *> elf::outputSections;<br>
<br>
uint32_t OutputSection::getPhdrFlags() const {<br>
- uint32_t Ret = 0;<br>
- if (Config->EMachine != EM_ARM || !(Flags & SHF_ARM_PURECODE))<br>
- Ret |= PF_R;<br>
- if (Flags & SHF_WRITE)<br>
- Ret |= PF_W;<br>
- if (Flags & SHF_EXECINSTR)<br>
- Ret |= PF_X;<br>
- return Ret;<br>
+ uint32_t ret = 0;<br>
+ if (config->emachine != EM_ARM || !(flags & SHF_ARM_PURECODE))<br>
+ ret |= PF_R;<br>
+ if (flags & SHF_WRITE)<br>
+ ret |= PF_W;<br>
+ if (flags & SHF_EXECINSTR)<br>
+ ret |= PF_X;<br>
+ return ret;<br>
}<br>
<br>
template <class ELFT><br>
-void OutputSection::writeHeaderTo(typename ELFT::Shdr *Shdr) {<br>
- Shdr->sh_entsize = Entsize;<br>
- Shdr->sh_addralign = Alignment;<br>
- Shdr->sh_type = Type;<br>
- Shdr->sh_offset = Offset;<br>
- Shdr->sh_flags = Flags;<br>
- Shdr->sh_info = Info;<br>
- Shdr->sh_link = Link;<br>
- Shdr->sh_addr = Addr;<br>
- Shdr->sh_size = Size;<br>
- Shdr->sh_name = ShName;<br>
+void OutputSection::writeHeaderTo(typename ELFT::Shdr *shdr) {<br>
+ shdr->sh_entsize = entsize;<br>
+ shdr->sh_addralign = alignment;<br>
+ shdr->sh_type = type;<br>
+ shdr->sh_offset = offset;<br>
+ shdr->sh_flags = flags;<br>
+ shdr->sh_info = info;<br>
+ shdr->sh_link = link;<br>
+ shdr->sh_addr = addr;<br>
+ shdr->sh_size = size;<br>
+ shdr->sh_name = shName;<br>
}<br>
<br>
-OutputSection::OutputSection(StringRef Name, uint32_t Type, uint64_t Flags)<br>
+OutputSection::OutputSection(StringRef name, uint32_t type, uint64_t flags)<br>
: BaseCommand(OutputSectionKind),<br>
- SectionBase(Output, Name, Flags, /*Entsize*/ 0, /*Alignment*/ 1, Type,<br>
+ SectionBase(Output, name, flags, /*Entsize*/ 0, /*Alignment*/ 1, type,<br>
/*Info*/ 0, /*Link*/ 0) {}<br>
<br>
// We allow sections of types listed below to merged into a<br>
@@ -77,102 +77,102 @@ OutputSection::OutputSection(StringRef N<br>
// to be allocated for nobits sections. Other ones don't require<br>
// any special treatment on top of progbits, so there doesn't<br>
// seem to be a harm in merging them.<br>
-static bool canMergeToProgbits(unsigned Type) {<br>
- return Type == SHT_NOBITS || Type == SHT_PROGBITS || Type == SHT_INIT_ARRAY ||<br>
- Type == SHT_PREINIT_ARRAY || Type == SHT_FINI_ARRAY ||<br>
- Type == SHT_NOTE;<br>
+static bool canMergeToProgbits(unsigned type) {<br>
+ return type == SHT_NOBITS || type == SHT_PROGBITS || type == SHT_INIT_ARRAY ||<br>
+ type == SHT_PREINIT_ARRAY || type == SHT_FINI_ARRAY ||<br>
+ type == SHT_NOTE;<br>
}<br>
<br>
-void OutputSection::addSection(InputSection *IS) {<br>
- if (!HasInputSections) {<br>
+void OutputSection::addSection(InputSection *isec) {<br>
+ if (!hasInputSections) {<br>
// If IS is the first section to be added to this section,<br>
// initialize Partition, Type, Entsize and flags from IS.<br>
- HasInputSections = true;<br>
- Partition = IS->Partition;<br>
- Type = IS->Type;<br>
- Entsize = IS->Entsize;<br>
- Flags = IS->Flags;<br>
+ hasInputSections = true;<br>
+ partition = isec->partition;<br>
+ type = isec->type;<br>
+ entsize = isec->entsize;<br>
+ flags = isec->flags;<br>
} else {<br>
// Otherwise, check if new type or flags are compatible with existing ones.<br>
- unsigned Mask = SHF_TLS | SHF_LINK_ORDER;<br>
- if ((Flags & Mask) != (IS->Flags & Mask))<br>
- error("incompatible section flags for " + Name + "\n>>> " + toString(IS) +<br>
- ": 0x" + utohexstr(IS->Flags) + "\n>>> output section " + Name +<br>
- ": 0x" + utohexstr(Flags));<br>
-<br>
- if (Type != IS->Type) {<br>
- if (!canMergeToProgbits(Type) || !canMergeToProgbits(IS->Type))<br>
- error("section type mismatch for " + IS->Name + "\n>>> " +<br>
- toString(IS) + ": " +<br>
- getELFSectionTypeName(Config->EMachine, IS->Type) +<br>
- "\n>>> output section " + Name + ": " +<br>
- getELFSectionTypeName(Config->EMachine, Type));<br>
- Type = SHT_PROGBITS;<br>
+ unsigned mask = SHF_TLS | SHF_LINK_ORDER;<br>
+ if ((flags & mask) != (isec->flags & mask))<br>
+ error("incompatible section flags for " + name + "\n>>> " + toString(isec) +<br>
+ ": 0x" + utohexstr(isec->flags) + "\n>>> output section " + name +<br>
+ ": 0x" + utohexstr(flags));<br>
+<br>
+ if (type != isec->type) {<br>
+ if (!canMergeToProgbits(type) || !canMergeToProgbits(isec->type))<br>
+ error("section type mismatch for " + isec->name + "\n>>> " +<br>
+ toString(isec) + ": " +<br>
+ getELFSectionTypeName(config->emachine, isec->type) +<br>
+ "\n>>> output section " + name + ": " +<br>
+ getELFSectionTypeName(config->emachine, type));<br>
+ type = SHT_PROGBITS;<br>
}<br>
}<br>
<br>
- IS->Parent = this;<br>
- uint64_t AndMask =<br>
- Config->EMachine == EM_ARM ? (uint64_t)SHF_ARM_PURECODE : 0;<br>
- uint64_t OrMask = ~AndMask;<br>
- uint64_t AndFlags = (Flags & IS->Flags) & AndMask;<br>
- uint64_t OrFlags = (Flags | IS->Flags) & OrMask;<br>
- Flags = AndFlags | OrFlags;<br>
+ isec->parent = this;<br>
+ uint64_t andMask =<br>
+ config->emachine == EM_ARM ? (uint64_t)SHF_ARM_PURECODE : 0;<br>
+ uint64_t orMask = ~andMask;<br>
+ uint64_t andFlags = (flags & isec->flags) & andMask;<br>
+ uint64_t orFlags = (flags | isec->flags) & orMask;<br>
+ flags = andFlags | orFlags;<br>
<br>
- Alignment = std::max(Alignment, IS->Alignment);<br>
+ alignment = std::max(alignment, isec->alignment);<br>
<br>
// If this section contains a table of fixed-size entries, sh_entsize<br>
// holds the element size. If it contains elements of different size we<br>
// set sh_entsize to 0.<br>
- if (Entsize != IS->Entsize)<br>
- Entsize = 0;<br>
+ if (entsize != isec->entsize)<br>
+ entsize = 0;<br>
<br>
- if (!IS->Assigned) {<br>
- IS->Assigned = true;<br>
- if (SectionCommands.empty() ||<br>
- !isa<InputSectionDescription>(SectionCommands.back()))<br>
- SectionCommands.push_back(make<InputSectionDescription>(""));<br>
- auto *ISD = cast<InputSectionDescription>(SectionCommands.back());<br>
- ISD->Sections.push_back(IS);<br>
+ if (!isec->assigned) {<br>
+ isec->assigned = true;<br>
+ if (sectionCommands.empty() ||<br>
+ !isa<InputSectionDescription>(sectionCommands.back()))<br>
+ sectionCommands.push_back(make<InputSectionDescription>(""));<br>
+ auto *isd = cast<InputSectionDescription>(sectionCommands.back());<br>
+ isd->sections.push_back(isec);<br>
}<br>
}<br>
<br>
-static void sortByOrder(MutableArrayRef<InputSection *> In,<br>
- llvm::function_ref<int(InputSectionBase *S)> Order) {<br>
- std::vector<std::pair<int, InputSection *>> V;<br>
- for (InputSection *S : In)<br>
- V.push_back({Order(S), S});<br>
- llvm::stable_sort(V, less_first());<br>
+static void sortByOrder(MutableArrayRef<InputSection *> in,<br>
+ llvm::function_ref<int(InputSectionBase *s)> order) {<br>
+ std::vector<std::pair<int, InputSection *>> v;<br>
+ for (InputSection *s : in)<br>
+ v.push_back({order(s), s});<br>
+ llvm::stable_sort(v, less_first());<br>
<br>
- for (size_t I = 0; I < V.size(); ++I)<br>
- In[I] = V[I].second;<br>
+ for (size_t i = 0; i < v.size(); ++i)<br>
+ in[i] = v[i].second;<br>
}<br>
<br>
uint64_t elf::getHeaderSize() {<br>
- if (Config->OFormatBinary)<br>
+ if (config->oFormatBinary)<br>
return 0;<br>
- return Out::ElfHeader->Size + Out::ProgramHeaders->Size;<br>
+ return Out::elfHeader->size + Out::programHeaders->size;<br>
}<br>
<br>
-bool OutputSection::classof(const BaseCommand *C) {<br>
- return C->Kind == OutputSectionKind;<br>
+bool OutputSection::classof(const BaseCommand *c) {<br>
+ return c->kind == OutputSectionKind;<br>
}<br>
<br>
-void OutputSection::sort(llvm::function_ref<int(InputSectionBase *S)> Order) {<br>
+void OutputSection::sort(llvm::function_ref<int(InputSectionBase *s)> order) {<br>
assert(isLive());<br>
- for (BaseCommand *B : SectionCommands)<br>
- if (auto *ISD = dyn_cast<InputSectionDescription>(B))<br>
- sortByOrder(ISD->Sections, Order);<br>
+ for (BaseCommand *b : sectionCommands)<br>
+ if (auto *isd = dyn_cast<InputSectionDescription>(b))<br>
+ sortByOrder(isd->sections, order);<br>
}<br>
<br>
// Fill [Buf, Buf + Size) with Filler.<br>
// This is used for linker script "=fillexp" command.<br>
-static void fill(uint8_t *Buf, size_t Size,<br>
- const std::array<uint8_t, 4> &Filler) {<br>
- size_t I = 0;<br>
- for (; I + 4 < Size; I += 4)<br>
- memcpy(Buf + I, Filler.data(), 4);<br>
- memcpy(Buf + I, Filler.data(), Size - I);<br>
+static void fill(uint8_t *buf, size_t size,<br>
+ const std::array<uint8_t, 4> &filler) {<br>
+ size_t i = 0;<br>
+ for (; i + 4 < size; i += 4)<br>
+ memcpy(buf + i, filler.data(), 4);<br>
+ memcpy(buf + i, filler.data(), size - i);<br>
}<br>
<br>
// Compress section contents if this section contains debug info.<br>
@@ -180,145 +180,145 @@ template <class ELFT> void OutputSection<br>
using Elf_Chdr = typename ELFT::Chdr;<br>
<br>
// Compress only DWARF debug sections.<br>
- if (!Config->CompressDebugSections || (Flags & SHF_ALLOC) ||<br>
- !Name.startswith(".debug_"))<br>
+ if (!config->compressDebugSections || (flags & SHF_ALLOC) ||<br>
+ !name.startswith(".debug_"))<br>
return;<br>
<br>
// Create a section header.<br>
- ZDebugHeader.resize(sizeof(Elf_Chdr));<br>
- auto *Hdr = reinterpret_cast<Elf_Chdr *>(ZDebugHeader.data());<br>
- Hdr->ch_type = ELFCOMPRESS_ZLIB;<br>
- Hdr->ch_size = Size;<br>
- Hdr->ch_addralign = Alignment;<br>
+ zDebugHeader.resize(sizeof(Elf_Chdr));<br>
+ auto *hdr = reinterpret_cast<Elf_Chdr *>(zDebugHeader.data());<br>
+ hdr->ch_type = ELFCOMPRESS_ZLIB;<br>
+ hdr->ch_size = size;<br>
+ hdr->ch_addralign = alignment;<br>
<br>
// Write section contents to a temporary buffer and compress it.<br>
- std::vector<uint8_t> Buf(Size);<br>
- writeTo<ELFT>(Buf.data());<br>
- if (Error E = zlib::compress(toStringRef(Buf), CompressedData))<br>
- fatal("compress failed: " + llvm::toString(std::move(E)));<br>
+ std::vector<uint8_t> buf(size);<br>
+ writeTo<ELFT>(buf.data());<br>
+ if (Error e = zlib::compress(toStringRef(buf), compressedData))<br>
+ fatal("compress failed: " + llvm::toString(std::move(e)));<br>
<br>
// Update section headers.<br>
- Size = sizeof(Elf_Chdr) + CompressedData.size();<br>
- Flags |= SHF_COMPRESSED;<br>
+ size = sizeof(Elf_Chdr) + compressedData.size();<br>
+ flags |= SHF_COMPRESSED;<br>
}<br>
<br>
-static void writeInt(uint8_t *Buf, uint64_t Data, uint64_t Size) {<br>
- if (Size == 1)<br>
- *Buf = Data;<br>
- else if (Size == 2)<br>
- write16(Buf, Data);<br>
- else if (Size == 4)<br>
- write32(Buf, Data);<br>
- else if (Size == 8)<br>
- write64(Buf, Data);<br>
+static void writeInt(uint8_t *buf, uint64_t data, uint64_t size) {<br>
+ if (size == 1)<br>
+ *buf = data;<br>
+ else if (size == 2)<br>
+ write16(buf, data);<br>
+ else if (size == 4)<br>
+ write32(buf, data);<br>
+ else if (size == 8)<br>
+ write64(buf, data);<br>
else<br>
llvm_unreachable("unsupported Size argument");<br>
}<br>
<br>
-template <class ELFT> void OutputSection::writeTo(uint8_t *Buf) {<br>
- if (Type == SHT_NOBITS)<br>
+template <class ELFT> void OutputSection::writeTo(uint8_t *buf) {<br>
+ if (type == SHT_NOBITS)<br>
return;<br>
<br>
// If -compress-debug-section is specified and if this is a debug seciton,<br>
// we've already compressed section contents. If that's the case,<br>
// just write it down.<br>
- if (!CompressedData.empty()) {<br>
- memcpy(Buf, ZDebugHeader.data(), ZDebugHeader.size());<br>
- memcpy(Buf + ZDebugHeader.size(), CompressedData.data(),<br>
- CompressedData.size());<br>
+ if (!compressedData.empty()) {<br>
+ memcpy(buf, zDebugHeader.data(), zDebugHeader.size());<br>
+ memcpy(buf + zDebugHeader.size(), compressedData.data(),<br>
+ compressedData.size());<br>
return;<br>
}<br>
<br>
// Write leading padding.<br>
- std::vector<InputSection *> Sections = getInputSections(this);<br>
- std::array<uint8_t, 4> Filler = getFiller();<br>
- bool NonZeroFiller = read32(Filler.data()) != 0;<br>
- if (NonZeroFiller)<br>
- fill(Buf, Sections.empty() ? Size : Sections[0]->OutSecOff, Filler);<br>
-<br>
- parallelForEachN(0, Sections.size(), [&](size_t I) {<br>
- InputSection *IS = Sections[I];<br>
- IS->writeTo<ELFT>(Buf);<br>
+ std::vector<InputSection *> sections = getInputSections(this);<br>
+ std::array<uint8_t, 4> filler = getFiller();<br>
+ bool nonZeroFiller = read32(filler.data()) != 0;<br>
+ if (nonZeroFiller)<br>
+ fill(buf, sections.empty() ? size : sections[0]->outSecOff, filler);<br>
+<br>
+ parallelForEachN(0, sections.size(), [&](size_t i) {<br>
+ InputSection *isec = sections[i];<br>
+ isec->writeTo<ELFT>(buf);<br>
<br>
// Fill gaps between sections.<br>
- if (NonZeroFiller) {<br>
- uint8_t *Start = Buf + IS->OutSecOff + IS->getSize();<br>
- uint8_t *End;<br>
- if (I + 1 == Sections.size())<br>
- End = Buf + Size;<br>
+ if (nonZeroFiller) {<br>
+ uint8_t *start = buf + isec->outSecOff + isec->getSize();<br>
+ uint8_t *end;<br>
+ if (i + 1 == sections.size())<br>
+ end = buf + size;<br>
else<br>
- End = Buf + Sections[I + 1]->OutSecOff;<br>
- fill(Start, End - Start, Filler);<br>
+ end = buf + sections[i + 1]->outSecOff;<br>
+ fill(start, end - start, filler);<br>
}<br>
});<br>
<br>
// Linker scripts may have BYTE()-family commands with which you<br>
// can write arbitrary bytes to the output. Process them if any.<br>
- for (BaseCommand *Base : SectionCommands)<br>
- if (auto *Data = dyn_cast<ByteCommand>(Base))<br>
- writeInt(Buf + Data->Offset, Data->Expression().getValue(), Data->Size);<br>
+ for (BaseCommand *base : sectionCommands)<br>
+ if (auto *data = dyn_cast<ByteCommand>(base))<br>
+ writeInt(buf + data->offset, data->expression().getValue(), data->size);<br>
}<br>
<br>
-static void finalizeShtGroup(OutputSection *OS,<br>
- InputSection *Section) {<br>
- assert(Config->Relocatable);<br>
+static void finalizeShtGroup(OutputSection *os,<br>
+ InputSection *section) {<br>
+ assert(config->relocatable);<br>
<br>
// sh_link field for SHT_GROUP sections should contain the section index of<br>
// the symbol table.<br>
- OS->Link = In.SymTab->getParent()->SectionIndex;<br>
+ os->link = in.symTab->getParent()->sectionIndex;<br>
<br>
// sh_info then contain index of an entry in symbol table section which<br>
// provides signature of the section group.<br>
- ArrayRef<Symbol *> Symbols = Section->File->getSymbols();<br>
- OS->Info = In.SymTab->getSymbolIndex(Symbols[Section->Info]);<br>
+ ArrayRef<Symbol *> symbols = section->file->getSymbols();<br>
+ os->info = in.symTab->getSymbolIndex(symbols[section->info]);<br>
}<br>
<br>
void OutputSection::finalize() {<br>
- std::vector<InputSection *> V = getInputSections(this);<br>
- InputSection *First = V.empty() ? nullptr : V[0];<br>
+ std::vector<InputSection *> v = getInputSections(this);<br>
+ InputSection *first = v.empty() ? nullptr : v[0];<br>
<br>
- if (Flags & SHF_LINK_ORDER) {<br>
+ if (flags & SHF_LINK_ORDER) {<br>
// We must preserve the link order dependency of sections with the<br>
// SHF_LINK_ORDER flag. The dependency is indicated by the sh_link field. We<br>
// need to translate the InputSection sh_link to the OutputSection sh_link,<br>
// all InputSections in the OutputSection have the same dependency.<br>
- if (auto *EX = dyn_cast<ARMExidxSyntheticSection>(First))<br>
- Link = EX->getLinkOrderDep()->getParent()->SectionIndex;<br>
- else if (auto *D = First->getLinkOrderDep())<br>
- Link = D->getParent()->SectionIndex;<br>
+ if (auto *ex = dyn_cast<ARMExidxSyntheticSection>(first))<br>
+ link = ex->getLinkOrderDep()->getParent()->sectionIndex;<br>
+ else if (auto *d = first->getLinkOrderDep())<br>
+ link = d->getParent()->sectionIndex;<br>
}<br>
<br>
- if (Type == SHT_GROUP) {<br>
- finalizeShtGroup(this, First);<br>
+ if (type == SHT_GROUP) {<br>
+ finalizeShtGroup(this, first);<br>
return;<br>
}<br>
<br>
- if (!Config->CopyRelocs || (Type != SHT_RELA && Type != SHT_REL))<br>
+ if (!config->copyRelocs || (type != SHT_RELA && type != SHT_REL))<br>
return;<br>
<br>
- if (isa<SyntheticSection>(First))<br>
+ if (isa<SyntheticSection>(first))<br>
return;<br>
<br>
- Link = In.SymTab->getParent()->SectionIndex;<br>
+ link = in.symTab->getParent()->sectionIndex;<br>
// sh_info for SHT_REL[A] sections should contain the section header index of<br>
// the section to which the relocation applies.<br>
- InputSectionBase *S = First->getRelocatedSection();<br>
- Info = S->getOutputSection()->SectionIndex;<br>
- Flags |= SHF_INFO_LINK;<br>
+ InputSectionBase *s = first->getRelocatedSection();<br>
+ info = s->getOutputSection()->sectionIndex;<br>
+ flags |= SHF_INFO_LINK;<br>
}<br>
<br>
// Returns true if S matches /Filename.?\.o$/.<br>
-static bool isCrtBeginEnd(StringRef S, StringRef Filename) {<br>
- if (!S.endswith(".o"))<br>
+static bool isCrtBeginEnd(StringRef s, StringRef filename) {<br>
+ if (!s.endswith(".o"))<br>
return false;<br>
- S = S.drop_back(2);<br>
- if (S.endswith(Filename))<br>
+ s = s.drop_back(2);<br>
+ if (s.endswith(filename))<br>
return true;<br>
- return !S.empty() && S.drop_back().endswith(Filename);<br>
+ return !s.empty() && s.drop_back().endswith(filename);<br>
}<br>
<br>
-static bool isCrtbegin(StringRef S) { return isCrtBeginEnd(S, "crtbegin"); }<br>
-static bool isCrtend(StringRef S) { return isCrtBeginEnd(S, "crtend"); }<br>
+static bool isCrtbegin(StringRef s) { return isCrtBeginEnd(s, "crtbegin"); }<br>
+static bool isCrtend(StringRef s) { return isCrtBeginEnd(s, "crtend"); }<br>
<br>
// .ctors and .dtors are sorted by this priority from highest to lowest.<br>
//<br>
@@ -338,52 +338,52 @@ static bool isCrtend(StringRef S) { retu<br>
// .ctors are duplicate features (and .init_array is newer.) However, there<br>
// are too many real-world use cases of .ctors, so we had no choice to<br>
// support that with this rather ad-hoc semantics.<br>
-static bool compCtors(const InputSection *A, const InputSection *B) {<br>
- bool BeginA = isCrtbegin(A->File->getName());<br>
- bool BeginB = isCrtbegin(B->File->getName());<br>
- if (BeginA != BeginB)<br>
- return BeginA;<br>
- bool EndA = isCrtend(A->File->getName());<br>
- bool EndB = isCrtend(B->File->getName());<br>
- if (EndA != EndB)<br>
- return EndB;<br>
- StringRef X = A->Name;<br>
- StringRef Y = B->Name;<br>
- assert(X.startswith(".ctors") || X.startswith(".dtors"));<br>
- assert(Y.startswith(".ctors") || Y.startswith(".dtors"));<br>
- X = X.substr(6);<br>
- Y = Y.substr(6);<br>
- return X < Y;<br>
+static bool compCtors(const InputSection *a, const InputSection *b) {<br>
+ bool beginA = isCrtbegin(a->file->getName());<br>
+ bool beginB = isCrtbegin(b->file->getName());<br>
+ if (beginA != beginB)<br>
+ return beginA;<br>
+ bool endA = isCrtend(a->file->getName());<br>
+ bool endB = isCrtend(b->file->getName());<br>
+ if (endA != endB)<br>
+ return endB;<br>
+ StringRef x = a->name;<br>
+ StringRef y = b->name;<br>
+ assert(x.startswith(".ctors") || x.startswith(".dtors"));<br>
+ assert(y.startswith(".ctors") || y.startswith(".dtors"));<br>
+ x = x.substr(6);<br>
+ y = y.substr(6);<br>
+ return x < y;<br>
}<br>
<br>
// Sorts input sections by the special rules for .ctors and .dtors.<br>
// Unfortunately, the rules are different from the one for .{init,fini}_array.<br>
// Read the comment above.<br>
void OutputSection::sortCtorsDtors() {<br>
- assert(SectionCommands.size() == 1);<br>
- auto *ISD = cast<InputSectionDescription>(SectionCommands[0]);<br>
- llvm::stable_sort(ISD->Sections, compCtors);<br>
+ assert(sectionCommands.size() == 1);<br>
+ auto *isd = cast<InputSectionDescription>(sectionCommands[0]);<br>
+ llvm::stable_sort(isd->sections, compCtors);<br>
}<br>
<br>
// If an input string is in the form of "foo.N" where N is a number,<br>
// return N. Otherwise, returns 65536, which is one greater than the<br>
// lowest priority.<br>
-int elf::getPriority(StringRef S) {<br>
- size_t Pos = S.rfind('.');<br>
- if (Pos == StringRef::npos)<br>
+int elf::getPriority(StringRef s) {<br>
+ size_t pos = s.rfind('.');<br>
+ if (pos == StringRef::npos)<br>
return 65536;<br>
- int V;<br>
- if (!to_integer(S.substr(Pos + 1), V, 10))<br>
+ int v;<br>
+ if (!to_integer(s.substr(pos + 1), v, 10))<br>
return 65536;<br>
- return V;<br>
+ return v;<br>
}<br>
<br>
-std::vector<InputSection *> elf::getInputSections(OutputSection *OS) {<br>
- std::vector<InputSection *> Ret;<br>
- for (BaseCommand *Base : OS->SectionCommands)<br>
- if (auto *ISD = dyn_cast<InputSectionDescription>(Base))<br>
- Ret.insert(Ret.end(), ISD->Sections.begin(), ISD->Sections.end());<br>
- return Ret;<br>
+std::vector<InputSection *> elf::getInputSections(OutputSection *os) {<br>
+ std::vector<InputSection *> ret;<br>
+ for (BaseCommand *base : os->sectionCommands)<br>
+ if (auto *isd = dyn_cast<InputSectionDescription>(base))<br>
+ ret.insert(ret.end(), isd->sections.begin(), isd->sections.end());<br>
+ return ret;<br>
}<br>
<br>
// Sorts input sections by section name suffixes, so that .foo.N comes<br>
@@ -394,14 +394,14 @@ std::vector<InputSection *> elf::getInpu<br>
// For more detail, read the section of the GCC's manual about init_priority.<br>
void OutputSection::sortInitFini() {<br>
// Sort sections by priority.<br>
- sort([](InputSectionBase *S) { return getPriority(S->Name); });<br>
+ sort([](InputSectionBase *s) { return getPriority(s->name); });<br>
}<br>
<br>
std::array<uint8_t, 4> OutputSection::getFiller() {<br>
- if (Filler)<br>
- return *Filler;<br>
- if (Flags & SHF_EXECINSTR)<br>
- return Target->TrapInstr;<br>
+ if (filler)<br>
+ return *filler;<br>
+ if (flags & SHF_EXECINSTR)<br>
+ return target->trapInstr;<br>
return {0, 0, 0, 0};<br>
}<br>
<br>
<br>
Modified: lld/trunk/ELF/OutputSections.h<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_ELF_OutputSections.h-3Frev-3D365595-26r1-3D365594-26r2-3D365595-26view-3Ddiff&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=0sg9eJvrxwt0wJYHYKYKhDpKWMqW3dpgnzaSoVSdGtk&e=" rel="noreferrer" target="_blank">https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_ELF_OutputSections.h-3Frev-3D365595-26r1-3D365594-26r2-3D365595-26view-3Ddiff&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=0sg9eJvrxwt0wJYHYKYKhDpKWMqW3dpgnzaSoVSdGtk&e=</a> <br>
==============================================================================<br>
--- lld/trunk/ELF/OutputSections.h (original)<br>
+++ lld/trunk/ELF/OutputSections.h Tue Jul 9 22:00:37 2019<br>
@@ -31,19 +31,19 @@ class InputSectionBase;<br>
// non-overlapping file offsets and VAs.<br>
class OutputSection final : public BaseCommand, public SectionBase {<br>
public:<br>
- OutputSection(StringRef Name, uint32_t Type, uint64_t Flags);<br>
+ OutputSection(StringRef name, uint32_t type, uint64_t flags);<br>
<br>
- static bool classof(const SectionBase *S) {<br>
- return S->kind() == SectionBase::Output;<br>
+ static bool classof(const SectionBase *s) {<br>
+ return s->kind() == SectionBase::Output;<br>
}<br>
<br>
- static bool classof(const BaseCommand *C);<br>
+ static bool classof(const BaseCommand *c);<br>
<br>
- uint64_t getLMA() const { return PtLoad ? Addr + PtLoad->LMAOffset : Addr; }<br>
- template <typename ELFT> void writeHeaderTo(typename ELFT::Shdr *SHdr);<br>
+ uint64_t getLMA() const { return ptLoad ? addr + ptLoad->lmaOffset : addr; }<br>
+ template <typename ELFT> void writeHeaderTo(typename ELFT::Shdr *sHdr);<br>
<br>
- uint32_t SectionIndex = UINT32_MAX;<br>
- unsigned SortRank;<br>
+ uint32_t sectionIndex = UINT32_MAX;<br>
+ unsigned sortRank;<br>
<br>
uint32_t getPhdrFlags() const;<br>
<br>
@@ -54,82 +54,82 @@ public:<br>
// section offset we use the following formula: Off = Off_first + VA -<br>
// VA_first, where Off_first and VA_first is file offset and VA of first<br>
// section in PT_LOAD.<br>
- PhdrEntry *PtLoad = nullptr;<br>
+ PhdrEntry *ptLoad = nullptr;<br>
<br>
// Pointer to a relocation section for this section. Usually nullptr because<br>
// we consume relocations, but if --emit-relocs is specified (which is rare),<br>
// it may have a non-null value.<br>
- OutputSection *RelocationSection = nullptr;<br>
+ OutputSection *relocationSection = nullptr;<br>
<br>
// Initially this field is the number of InputSections that have been added to<br>
// the OutputSection so far. Later on, after a call to assignAddresses, it<br>
// corresponds to the Elf_Shdr member.<br>
- uint64_t Size = 0;<br>
+ uint64_t size = 0;<br>
<br>
// The following fields correspond to Elf_Shdr members.<br>
- uint64_t Offset = 0;<br>
- uint64_t Addr = 0;<br>
- uint32_t ShName = 0;<br>
+ uint64_t offset = 0;<br>
+ uint64_t addr = 0;<br>
+ uint32_t shName = 0;<br>
<br>
- void addSection(InputSection *IS);<br>
+ void addSection(InputSection *isec);<br>
<br>
// The following members are normally only used in linker scripts.<br>
- MemoryRegion *MemRegion = nullptr;<br>
- MemoryRegion *LMARegion = nullptr;<br>
- Expr AddrExpr;<br>
- Expr AlignExpr;<br>
- Expr LMAExpr;<br>
- Expr SubalignExpr;<br>
- std::vector<BaseCommand *> SectionCommands;<br>
- std::vector<StringRef> Phdrs;<br>
- llvm::Optional<std::array<uint8_t, 4>> Filler;<br>
- ConstraintKind Constraint = ConstraintKind::NoConstraint;<br>
- std::string Location;<br>
- std::string MemoryRegionName;<br>
- std::string LMARegionName;<br>
- bool NonAlloc = false;<br>
- bool Noload = false;<br>
- bool ExpressionsUseSymbols = false;<br>
- bool UsedInExpression = false;<br>
- bool InOverlay = false;<br>
+ MemoryRegion *memRegion = nullptr;<br>
+ MemoryRegion *lmaRegion = nullptr;<br>
+ Expr addrExpr;<br>
+ Expr alignExpr;<br>
+ Expr lmaExpr;<br>
+ Expr subalignExpr;<br>
+ std::vector<BaseCommand *> sectionCommands;<br>
+ std::vector<StringRef> phdrs;<br>
+ llvm::Optional<std::array<uint8_t, 4>> filler;<br>
+ ConstraintKind constraint = ConstraintKind::NoConstraint;<br>
+ std::string location;<br>
+ std::string memoryRegionName;<br>
+ std::string lmaRegionName;<br>
+ bool nonAlloc = false;<br>
+ bool noload = false;<br>
+ bool expressionsUseSymbols = false;<br>
+ bool usedInExpression = false;<br>
+ bool inOverlay = false;<br>
<br>
// Tracks whether the section has ever had an input section added to it, even<br>
// if the section was later removed (e.g. because it is a synthetic section<br>
// that wasn't needed). This is needed for orphan placement.<br>
- bool HasInputSections = false;<br>
+ bool hasInputSections = false;<br>
<br>
void finalize();<br>
- template <class ELFT> void writeTo(uint8_t *Buf);<br>
+ template <class ELFT> void writeTo(uint8_t *buf);<br>
template <class ELFT> void maybeCompress();<br>
<br>
- void sort(llvm::function_ref<int(InputSectionBase *S)> Order);<br>
+ void sort(llvm::function_ref<int(InputSectionBase *s)> order);<br>
void sortInitFini();<br>
void sortCtorsDtors();<br>
<br>
private:<br>
// Used for implementation of --compress-debug-sections option.<br>
- std::vector<uint8_t> ZDebugHeader;<br>
- llvm::SmallVector<char, 1> CompressedData;<br>
+ std::vector<uint8_t> zDebugHeader;<br>
+ llvm::SmallVector<char, 1> compressedData;<br>
<br>
std::array<uint8_t, 4> getFiller();<br>
};<br>
<br>
-int getPriority(StringRef S);<br>
+int getPriority(StringRef s);<br>
<br>
-std::vector<InputSection *> getInputSections(OutputSection* OS);<br>
+std::vector<InputSection *> getInputSections(OutputSection* os);<br>
<br>
// All output sections that are handled by the linker specially are<br>
// globally accessible. Writer initializes them, so don't use them<br>
// until Writer is initialized.<br>
struct Out {<br>
- static uint8_t *BufferStart;<br>
- static uint8_t First;<br>
- static PhdrEntry *TlsPhdr;<br>
- static OutputSection *ElfHeader;<br>
- static OutputSection *ProgramHeaders;<br>
- static OutputSection *PreinitArray;<br>
- static OutputSection *InitArray;<br>
- static OutputSection *FiniArray;<br>
+ static uint8_t *bufferStart;<br>
+ static uint8_t first;<br>
+ static PhdrEntry *tlsPhdr;<br>
+ static OutputSection *elfHeader;<br>
+ static OutputSection *programHeaders;<br>
+ static OutputSection *preinitArray;<br>
+ static OutputSection *initArray;<br>
+ static OutputSection *finiArray;<br>
};<br>
<br>
} // namespace elf<br>
@@ -140,7 +140,7 @@ namespace elf {<br>
<br>
uint64_t getHeaderSize();<br>
<br>
-extern std::vector<OutputSection *> OutputSections;<br>
+extern std::vector<OutputSection *> outputSections;<br>
} // namespace elf<br>
} // namespace lld<br>
<br>
<br>
Modified: lld/trunk/ELF/Relocations.cpp<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_ELF_Relocations.cpp-3Frev-3D365595-26r1-3D365594-26r2-3D365595-26view-3Ddiff&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=OJl7a8UYp5_5CV1dOgpnFxXO60FVHvRxpV2CGGP1uKg&e=" rel="noreferrer" target="_blank">https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_ELF_Relocations.cpp-3Frev-3D365595-26r1-3D365594-26r2-3D365595-26view-3Ddiff&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=OJl7a8UYp5_5CV1dOgpnFxXO60FVHvRxpV2CGGP1uKg&e=</a> <br>
==============================================================================<br>
--- lld/trunk/ELF/Relocations.cpp (original)<br>
+++ lld/trunk/ELF/Relocations.cpp Tue Jul 9 22:00:37 2019<br>
@@ -65,11 +65,11 @@ using namespace llvm::support::endian;<br>
using namespace lld;<br>
using namespace lld::elf;<br>
<br>
-static Optional<std::string> getLinkerScriptLocation(const Symbol &Sym) {<br>
- for (BaseCommand *Base : Script->SectionCommands)<br>
- if (auto *Cmd = dyn_cast<SymbolAssignment>(Base))<br>
- if (Cmd->Sym == &Sym)<br>
- return Cmd->Location;<br>
+static Optional<std::string> getLinkerScriptLocation(const Symbol &sym) {<br>
+ for (BaseCommand *base : script->sectionCommands)<br>
+ if (auto *cmd = dyn_cast<SymbolAssignment>(base))<br>
+ if (cmd->sym == &sym)<br>
+ return cmd->location;<br>
return None;<br>
}<br>
<br>
@@ -78,19 +78,19 @@ static Optional<std::string> getLinkerSc<br>
// >>> defined in /home/alice/src/foo.o<br>
// >>> referenced by bar.c:12 (/home/alice/src/bar.c:12)<br>
// >>> /home/alice/src/bar.o:(.text+0x1)<br>
-static std::string getLocation(InputSectionBase &S, const Symbol &Sym,<br>
- uint64_t Off) {<br>
- std::string Msg = "\n>>> defined in ";<br>
- if (Sym.File)<br>
- Msg += toString(Sym.File);<br>
- else if (Optional<std::string> Loc = getLinkerScriptLocation(Sym))<br>
- Msg += *Loc;<br>
-<br>
- Msg += "\n>>> referenced by ";<br>
- std::string Src = S.getSrcMsg(Sym, Off);<br>
- if (!Src.empty())<br>
- Msg += Src + "\n>>> ";<br>
- return Msg + S.getObjMsg(Off);<br>
+static std::string getLocation(InputSectionBase &s, const Symbol &sym,<br>
+ uint64_t off) {<br>
+ std::string msg = "\n>>> defined in ";<br>
+ if (sym.file)<br>
+ msg += toString(sym.file);<br>
+ else if (Optional<std::string> loc = getLinkerScriptLocation(sym))<br>
+ msg += *loc;<br>
+<br>
+ msg += "\n>>> referenced by ";<br>
+ std::string src = s.getSrcMsg(sym, off);<br>
+ if (!src.empty())<br>
+ msg += src + "\n>>> ";<br>
+ return msg + s.getObjMsg(off);<br>
}<br>
<br>
namespace {<br>
@@ -119,10 +119,10 @@ struct RelExprMaskBuilder<Head, Tail...><br>
// There are fewer than 64 RelExpr's, so we can represent any set of<br>
// RelExpr's as a constant bit mask and test for membership with a<br>
// couple cheap bitwise operations.<br>
-template <RelExpr... Exprs> bool oneof(RelExpr Expr) {<br>
- assert(0 <= Expr && (int)Expr < 64 &&<br>
+template <RelExpr... Exprs> bool oneof(RelExpr expr) {<br>
+ assert(0 <= expr && (int)expr < 64 &&<br>
"RelExpr is too large for 64-bit mask!");<br>
- return (uint64_t(1) << Expr) & RelExprMaskBuilder<Exprs...>::build();<br>
+ return (uint64_t(1) << expr) & RelExprMaskBuilder<Exprs...>::build();<br>
}<br>
<br>
// This function is similar to the `handleTlsRelocation`. MIPS does not<br>
@@ -131,17 +131,17 @@ template <RelExpr... Exprs> bool oneof(R<br>
// pollute other `handleTlsRelocation` by MIPS `ifs` statements.<br>
// Mips has a custom MipsGotSection that handles the writing of GOT entries<br>
// without dynamic relocations.<br>
-static unsigned handleMipsTlsRelocation(RelType Type, Symbol &Sym,<br>
- InputSectionBase &C, uint64_t Offset,<br>
- int64_t Addend, RelExpr Expr) {<br>
- if (Expr == R_MIPS_TLSLD) {<br>
- In.MipsGot->addTlsIndex(*C.File);<br>
- C.Relocations.push_back({Expr, Type, Offset, Addend, &Sym});<br>
+static unsigned handleMipsTlsRelocation(RelType type, Symbol &sym,<br>
+ InputSectionBase &c, uint64_t offset,<br>
+ int64_t addend, RelExpr expr) {<br>
+ if (expr == R_MIPS_TLSLD) {<br>
+ in.mipsGot->addTlsIndex(*c.file);<br>
+ c.relocations.push_back({expr, type, offset, addend, &sym});<br>
return 1;<br>
}<br>
- if (Expr == R_MIPS_TLSGD) {<br>
- In.MipsGot->addDynTlsEntry(*C.File, Sym);<br>
- C.Relocations.push_back({Expr, Type, Offset, Addend, &Sym});<br>
+ if (expr == R_MIPS_TLSGD) {<br>
+ in.mipsGot->addDynTlsEntry(*c.file, sym);<br>
+ c.relocations.push_back({expr, type, offset, addend, &sym});<br>
return 1;<br>
}<br>
return 0;<br>
@@ -156,28 +156,28 @@ static unsigned handleMipsTlsRelocation(<br>
// Returns the number of relocations processed.<br>
template <class ELFT><br>
static unsigned<br>
-handleTlsRelocation(RelType Type, Symbol &Sym, InputSectionBase &C,<br>
- typename ELFT::uint Offset, int64_t Addend, RelExpr Expr) {<br>
- if (!Sym.isTls())<br>
+handleTlsRelocation(RelType type, Symbol &sym, InputSectionBase &c,<br>
+ typename ELFT::uint offset, int64_t addend, RelExpr expr) {<br>
+ if (!sym.isTls())<br>
return 0;<br>
<br>
- if (Config->EMachine == EM_MIPS)<br>
- return handleMipsTlsRelocation(Type, Sym, C, Offset, Addend, Expr);<br>
+ if (config->emachine == EM_MIPS)<br>
+ return handleMipsTlsRelocation(type, sym, c, offset, addend, expr);<br>
<br>
if (oneof<R_AARCH64_TLSDESC_PAGE, R_TLSDESC, R_TLSDESC_CALL, R_TLSDESC_PC>(<br>
- Expr) &&<br>
- Config->Shared) {<br>
- if (In.Got->addDynTlsEntry(Sym)) {<br>
- uint64_t Off = In.Got->getGlobalDynOffset(Sym);<br>
- Main->RelaDyn->addReloc(<br>
- {Target->TlsDescRel, In.Got, Off, !Sym.IsPreemptible, &Sym, 0});<br>
+ expr) &&<br>
+ config->shared) {<br>
+ if (in.got->addDynTlsEntry(sym)) {<br>
+ uint64_t off = in.got->getGlobalDynOffset(sym);<br>
+ mainPart->relaDyn->addReloc(<br>
+ {target->tlsDescRel, in.got, off, !sym.isPreemptible, &sym, 0});<br>
}<br>
- if (Expr != R_TLSDESC_CALL)<br>
- C.Relocations.push_back({Expr, Type, Offset, Addend, &Sym});<br>
+ if (expr != R_TLSDESC_CALL)<br>
+ c.relocations.push_back({expr, type, offset, addend, &sym});<br>
return 1;<br>
}<br>
<br>
- bool CanRelax = Config->EMachine != EM_ARM && Config->EMachine != EM_RISCV;<br>
+ bool canRelax = config->emachine != EM_ARM && config->emachine != EM_RISCV;<br>
<br>
// If we are producing an executable and the symbol is non-preemptable, it<br>
// must be defined and the code sequence can be relaxed to use Local-Exec.<br>
@@ -186,118 +186,118 @@ handleTlsRelocation(RelType Type, Symbol<br>
// we can omit the DTPMOD dynamic relocations and resolve them at link time<br>
// because them are always 1. This may be necessary for static linking as<br>
// DTPMOD may not be expected at load time.<br>
- bool IsLocalInExecutable = !Sym.IsPreemptible && !Config->Shared;<br>
+ bool isLocalInExecutable = !sym.isPreemptible && !config->shared;<br>
<br>
// Local Dynamic is for access to module local TLS variables, while still<br>
// being suitable for being dynamically loaded via dlopen. GOT[e0] is the<br>
// module index, with a special value of 0 for the current module. GOT[e1] is<br>
// unused. There only needs to be one module index entry.<br>
if (oneof<R_TLSLD_GOT, R_TLSLD_GOTPLT, R_TLSLD_PC, R_TLSLD_HINT>(<br>
- Expr)) {<br>
+ expr)) {<br>
// Local-Dynamic relocs can be relaxed to Local-Exec.<br>
- if (CanRelax && !Config->Shared) {<br>
- C.Relocations.push_back(<br>
- {Target->adjustRelaxExpr(Type, nullptr, R_RELAX_TLS_LD_TO_LE), Type,<br>
- Offset, Addend, &Sym});<br>
- return Target->getTlsGdRelaxSkip(Type);<br>
+ if (canRelax && !config->shared) {<br>
+ c.relocations.push_back(<br>
+ {target->adjustRelaxExpr(type, nullptr, R_RELAX_TLS_LD_TO_LE), type,<br>
+ offset, addend, &sym});<br>
+ return target->getTlsGdRelaxSkip(type);<br>
}<br>
- if (Expr == R_TLSLD_HINT)<br>
+ if (expr == R_TLSLD_HINT)<br>
return 1;<br>
- if (In.Got->addTlsIndex()) {<br>
- if (IsLocalInExecutable)<br>
- In.Got->Relocations.push_back(<br>
- {R_ADDEND, Target->SymbolicRel, In.Got->getTlsIndexOff(), 1, &Sym});<br>
+ if (in.got->addTlsIndex()) {<br>
+ if (isLocalInExecutable)<br>
+ in.got->relocations.push_back(<br>
+ {R_ADDEND, target->symbolicRel, in.got->getTlsIndexOff(), 1, &sym});<br>
else<br>
- Main->RelaDyn->addReloc(Target->TlsModuleIndexRel, In.Got,<br>
- In.Got->getTlsIndexOff(), nullptr);<br>
+ mainPart->relaDyn->addReloc(target->tlsModuleIndexRel, in.got,<br>
+ in.got->getTlsIndexOff(), nullptr);<br>
}<br>
- C.Relocations.push_back({Expr, Type, Offset, Addend, &Sym});<br>
+ c.relocations.push_back({expr, type, offset, addend, &sym});<br>
return 1;<br>
}<br>
<br>
// Local-Dynamic relocs can be relaxed to Local-Exec.<br>
- if (Expr == R_DTPREL && !Config->Shared) {<br>
- C.Relocations.push_back(<br>
- {Target->adjustRelaxExpr(Type, nullptr, R_RELAX_TLS_LD_TO_LE), Type,<br>
- Offset, Addend, &Sym});<br>
+ if (expr == R_DTPREL && !config->shared) {<br>
+ c.relocations.push_back(<br>
+ {target->adjustRelaxExpr(type, nullptr, R_RELAX_TLS_LD_TO_LE), type,<br>
+ offset, addend, &sym});<br>
return 1;<br>
}<br>
<br>
// Local-Dynamic sequence where offset of tls variable relative to dynamic<br>
// thread pointer is stored in the got. This cannot be relaxed to Local-Exec.<br>
- if (Expr == R_TLSLD_GOT_OFF) {<br>
- if (!Sym.isInGot()) {<br>
- In.Got->addEntry(Sym);<br>
- uint64_t Off = Sym.getGotOffset();<br>
- In.Got->Relocations.push_back(<br>
- {R_ABS, Target->TlsOffsetRel, Off, 0, &Sym});<br>
+ if (expr == R_TLSLD_GOT_OFF) {<br>
+ if (!sym.isInGot()) {<br>
+ in.got->addEntry(sym);<br>
+ uint64_t off = sym.getGotOffset();<br>
+ in.got->relocations.push_back(<br>
+ {R_ABS, target->tlsOffsetRel, off, 0, &sym});<br>
}<br>
- C.Relocations.push_back({Expr, Type, Offset, Addend, &Sym});<br>
+ c.relocations.push_back({expr, type, offset, addend, &sym});<br>
return 1;<br>
}<br>
<br>
if (oneof<R_AARCH64_TLSDESC_PAGE, R_TLSDESC, R_TLSDESC_CALL, R_TLSDESC_PC,<br>
- R_TLSGD_GOT, R_TLSGD_GOTPLT, R_TLSGD_PC>(Expr)) {<br>
- if (!CanRelax || Config->Shared) {<br>
- if (In.Got->addDynTlsEntry(Sym)) {<br>
- uint64_t Off = In.Got->getGlobalDynOffset(Sym);<br>
+ R_TLSGD_GOT, R_TLSGD_GOTPLT, R_TLSGD_PC>(expr)) {<br>
+ if (!canRelax || config->shared) {<br>
+ if (in.got->addDynTlsEntry(sym)) {<br>
+ uint64_t off = in.got->getGlobalDynOffset(sym);<br>
<br>
- if (IsLocalInExecutable)<br>
+ if (isLocalInExecutable)<br>
// Write one to the GOT slot.<br>
- In.Got->Relocations.push_back(<br>
- {R_ADDEND, Target->SymbolicRel, Off, 1, &Sym});<br>
+ in.got->relocations.push_back(<br>
+ {R_ADDEND, target->symbolicRel, off, 1, &sym});<br>
else<br>
- Main->RelaDyn->addReloc(Target->TlsModuleIndexRel, In.Got, Off, &Sym);<br>
+ mainPart->relaDyn->addReloc(target->tlsModuleIndexRel, in.got, off, &sym);<br>
<br>
// If the symbol is preemptible we need the dynamic linker to write<br>
// the offset too.<br>
- uint64_t OffsetOff = Off + Config->Wordsize;<br>
- if (Sym.IsPreemptible)<br>
- Main->RelaDyn->addReloc(Target->TlsOffsetRel, In.Got, OffsetOff,<br>
- &Sym);<br>
+ uint64_t offsetOff = off + config->wordsize;<br>
+ if (sym.isPreemptible)<br>
+ mainPart->relaDyn->addReloc(target->tlsOffsetRel, in.got, offsetOff,<br>
+ &sym);<br>
else<br>
- In.Got->Relocations.push_back(<br>
- {R_ABS, Target->TlsOffsetRel, OffsetOff, 0, &Sym});<br>
+ in.got->relocations.push_back(<br>
+ {R_ABS, target->tlsOffsetRel, offsetOff, 0, &sym});<br>
}<br>
- C.Relocations.push_back({Expr, Type, Offset, Addend, &Sym});<br>
+ c.relocations.push_back({expr, type, offset, addend, &sym});<br>
return 1;<br>
}<br>
<br>
// Global-Dynamic relocs can be relaxed to Initial-Exec or Local-Exec<br>
// depending on the symbol being locally defined or not.<br>
- if (Sym.IsPreemptible) {<br>
- C.Relocations.push_back(<br>
- {Target->adjustRelaxExpr(Type, nullptr, R_RELAX_TLS_GD_TO_IE), Type,<br>
- Offset, Addend, &Sym});<br>
- if (!Sym.isInGot()) {<br>
- In.Got->addEntry(Sym);<br>
- Main->RelaDyn->addReloc(Target->TlsGotRel, In.Got, Sym.getGotOffset(),<br>
- &Sym);<br>
+ if (sym.isPreemptible) {<br>
+ c.relocations.push_back(<br>
+ {target->adjustRelaxExpr(type, nullptr, R_RELAX_TLS_GD_TO_IE), type,<br>
+ offset, addend, &sym});<br>
+ if (!sym.isInGot()) {<br>
+ in.got->addEntry(sym);<br>
+ mainPart->relaDyn->addReloc(target->tlsGotRel, in.got, sym.getGotOffset(),<br>
+ &sym);<br>
}<br>
} else {<br>
- C.Relocations.push_back(<br>
- {Target->adjustRelaxExpr(Type, nullptr, R_RELAX_TLS_GD_TO_LE), Type,<br>
- Offset, Addend, &Sym});<br>
+ c.relocations.push_back(<br>
+ {target->adjustRelaxExpr(type, nullptr, R_RELAX_TLS_GD_TO_LE), type,<br>
+ offset, addend, &sym});<br>
}<br>
- return Target->getTlsGdRelaxSkip(Type);<br>
+ return target->getTlsGdRelaxSkip(type);<br>
}<br>
<br>
// Initial-Exec relocs can be relaxed to Local-Exec if the symbol is locally<br>
// defined.<br>
if (oneof<R_GOT, R_GOTPLT, R_GOT_PC, R_AARCH64_GOT_PAGE_PC, R_GOT_OFF,<br>
- R_TLSIE_HINT>(Expr) &&<br>
- CanRelax && IsLocalInExecutable) {<br>
- C.Relocations.push_back({R_RELAX_TLS_IE_TO_LE, Type, Offset, Addend, &Sym});<br>
+ R_TLSIE_HINT>(expr) &&<br>
+ canRelax && isLocalInExecutable) {<br>
+ c.relocations.push_back({R_RELAX_TLS_IE_TO_LE, type, offset, addend, &sym});<br>
return 1;<br>
}<br>
<br>
- if (Expr == R_TLSIE_HINT)<br>
+ if (expr == R_TLSIE_HINT)<br>
return 1;<br>
return 0;<br>
}<br>
<br>
-static RelType getMipsPairType(RelType Type, bool IsLocal) {<br>
- switch (Type) {<br>
+static RelType getMipsPairType(RelType type, bool isLocal) {<br>
+ switch (type) {<br>
case R_MIPS_HI16:<br>
return R_MIPS_LO16;<br>
case R_MIPS_GOT16:<br>
@@ -309,9 +309,9 @@ static RelType getMipsPairType(RelType T<br>
// the high 16 bits of the symbol's value. A paired R_MIPS_LO16<br>
// relocations handle low 16 bits of the address. That allows<br>
// to allocate only one GOT entry for every 64 KBytes of local data.<br>
- return IsLocal ? R_MIPS_LO16 : R_MIPS_NONE;<br>
+ return isLocal ? R_MIPS_LO16 : R_MIPS_NONE;<br>
case R_MICROMIPS_GOT16:<br>
- return IsLocal ? R_MICROMIPS_LO16 : R_MIPS_NONE;<br>
+ return isLocal ? R_MICROMIPS_LO16 : R_MIPS_NONE;<br>
case R_MIPS_PCHI16:<br>
return R_MIPS_PCLO16;<br>
case R_MICROMIPS_HI16:<br>
@@ -323,38 +323,38 @@ static RelType getMipsPairType(RelType T<br>
<br>
// True if non-preemptable symbol always has the same value regardless of where<br>
// the DSO is loaded.<br>
-static bool isAbsolute(const Symbol &Sym) {<br>
- if (Sym.isUndefWeak())<br>
+static bool isAbsolute(const Symbol &sym) {<br>
+ if (sym.isUndefWeak())<br>
return true;<br>
- if (const auto *DR = dyn_cast<Defined>(&Sym))<br>
- return DR->Section == nullptr; // Absolute symbol.<br>
+ if (const auto *dr = dyn_cast<Defined>(&sym))<br>
+ return dr->section == nullptr; // Absolute symbol.<br>
return false;<br>
}<br>
<br>
-static bool isAbsoluteValue(const Symbol &Sym) {<br>
- return isAbsolute(Sym) || Sym.isTls();<br>
+static bool isAbsoluteValue(const Symbol &sym) {<br>
+ return isAbsolute(sym) || sym.isTls();<br>
}<br>
<br>
// Returns true if Expr refers a PLT entry.<br>
-static bool needsPlt(RelExpr Expr) {<br>
- return oneof<R_PLT_PC, R_PPC32_PLTREL, R_PPC64_CALL_PLT, R_PLT>(Expr);<br>
+static bool needsPlt(RelExpr expr) {<br>
+ return oneof<R_PLT_PC, R_PPC32_PLTREL, R_PPC64_CALL_PLT, R_PLT>(expr);<br>
}<br>
<br>
// Returns true if Expr refers a GOT entry. Note that this function<br>
// returns false for TLS variables even though they need GOT, because<br>
// TLS variables uses GOT differently than the regular variables.<br>
-static bool needsGot(RelExpr Expr) {<br>
+static bool needsGot(RelExpr expr) {<br>
return oneof<R_GOT, R_GOT_OFF, R_HEXAGON_GOT, R_MIPS_GOT_LOCAL_PAGE,<br>
R_MIPS_GOT_OFF, R_MIPS_GOT_OFF32, R_AARCH64_GOT_PAGE_PC,<br>
- R_GOT_PC, R_GOTPLT>(Expr);<br>
+ R_GOT_PC, R_GOTPLT>(expr);<br>
}<br>
<br>
// True if this expression is of the form Sym - X, where X is a position in the<br>
// file (PC, or GOT for example).<br>
-static bool isRelExpr(RelExpr Expr) {<br>
+static bool isRelExpr(RelExpr expr) {<br>
return oneof<R_PC, R_GOTREL, R_GOTPLTREL, R_MIPS_GOTREL, R_PPC64_CALL,<br>
R_PPC64_RELAX_TOC, R_AARCH64_PAGE_PC, R_RELAX_GOT_PC,<br>
- R_RISCV_PC_INDIRECT>(Expr);<br>
+ R_RISCV_PC_INDIRECT>(expr);<br>
}<br>
<br>
// Returns true if a given relocation can be computed at link-time.<br>
@@ -366,8 +366,8 @@ static bool isRelExpr(RelExpr Expr) {<br>
//<br>
// If this function returns false, that means we need to emit a<br>
// dynamic relocation so that the relocation will be fixed at load-time.<br>
-static bool isStaticLinkTimeConstant(RelExpr E, RelType Type, const Symbol &Sym,<br>
- InputSectionBase &S, uint64_t RelOff) {<br>
+static bool isStaticLinkTimeConstant(RelExpr e, RelType type, const Symbol &sym,<br>
+ InputSectionBase &s, uint64_t relOff) {<br>
// These expressions always compute a constant<br>
if (oneof<R_DTPREL, R_GOTPLT, R_GOT_OFF, R_HEXAGON_GOT, R_TLSLD_GOT_OFF,<br>
R_MIPS_GOT_LOCAL_PAGE, R_MIPS_GOTREL, R_MIPS_GOT_OFF,<br>
@@ -376,33 +376,33 @@ static bool isStaticLinkTimeConstant(Rel<br>
R_PLT_PC, R_TLSGD_GOT, R_TLSGD_GOTPLT, R_TLSGD_PC, R_PPC32_PLTREL,<br>
R_PPC64_CALL_PLT, R_PPC64_RELAX_TOC, R_RISCV_ADD, R_TLSDESC_CALL,<br>
R_TLSDESC_PC, R_AARCH64_TLSDESC_PAGE, R_HINT, R_TLSLD_HINT,<br>
- R_TLSIE_HINT>(E))<br>
+ R_TLSIE_HINT>(e))<br>
return true;<br>
<br>
// These never do, except if the entire file is position dependent or if<br>
// only the low bits are used.<br>
- if (E == R_GOT || E == R_PLT || E == R_TLSDESC)<br>
- return Target->usesOnlyLowPageBits(Type) || !Config->Pic;<br>
+ if (e == R_GOT || e == R_PLT || e == R_TLSDESC)<br>
+ return target->usesOnlyLowPageBits(type) || !config->isPic;<br>
<br>
- if (Sym.IsPreemptible)<br>
+ if (sym.isPreemptible)<br>
return false;<br>
- if (!Config->Pic)<br>
+ if (!config->isPic)<br>
return true;<br>
<br>
// The size of a non preemptible symbol is a constant.<br>
- if (E == R_SIZE)<br>
+ if (e == R_SIZE)<br>
return true;<br>
<br>
// For the target and the relocation, we want to know if they are<br>
// absolute or relative.<br>
- bool AbsVal = isAbsoluteValue(Sym);<br>
- bool RelE = isRelExpr(E);<br>
- if (AbsVal && !RelE)<br>
+ bool absVal = isAbsoluteValue(sym);<br>
+ bool relE = isRelExpr(e);<br>
+ if (absVal && !relE)<br>
return true;<br>
- if (!AbsVal && RelE)<br>
+ if (!absVal && relE)<br>
return true;<br>
- if (!AbsVal && !RelE)<br>
- return Target->usesOnlyLowPageBits(Type);<br>
+ if (!absVal && !relE)<br>
+ return target->usesOnlyLowPageBits(type);<br>
<br>
// Relative relocation to an absolute value. This is normally unrepresentable,<br>
// but if the relocation refers to a weak undefined symbol, we allow it to<br>
@@ -412,22 +412,22 @@ static bool isStaticLinkTimeConstant(Rel<br>
// Another special case is MIPS _gp_disp symbol which represents offset<br>
// between start of a function and '_gp' value and defined as absolute just<br>
// to simplify the code.<br>
- assert(AbsVal && RelE);<br>
- if (Sym.isUndefWeak())<br>
+ assert(absVal && relE);<br>
+ if (sym.isUndefWeak())<br>
return true;<br>
<br>
// We set the final symbols values for linker script defined symbols later.<br>
// They always can be computed as a link time constant.<br>
- if (Sym.ScriptDefined)<br>
+ if (sym.scriptDefined)<br>
return true;<br>
<br>
- error("relocation " + toString(Type) + " cannot refer to absolute symbol: " +<br>
- toString(Sym) + getLocation(S, Sym, RelOff));<br>
+ error("relocation " + toString(type) + " cannot refer to absolute symbol: " +<br>
+ toString(sym) + getLocation(s, sym, relOff));<br>
return true;<br>
}<br>
<br>
-static RelExpr toPlt(RelExpr Expr) {<br>
- switch (Expr) {<br>
+static RelExpr toPlt(RelExpr expr) {<br>
+ switch (expr) {<br>
case R_PPC64_CALL:<br>
return R_PPC64_CALL_PLT;<br>
case R_PC:<br>
@@ -435,14 +435,14 @@ static RelExpr toPlt(RelExpr Expr) {<br>
case R_ABS:<br>
return R_PLT;<br>
default:<br>
- return Expr;<br>
+ return expr;<br>
}<br>
}<br>
<br>
-static RelExpr fromPlt(RelExpr Expr) {<br>
+static RelExpr fromPlt(RelExpr expr) {<br>
// We decided not to use a plt. Optimize a reference to the plt to a<br>
// reference to the symbol itself.<br>
- switch (Expr) {<br>
+ switch (expr) {<br>
case R_PLT_PC:<br>
case R_PPC32_PLTREL:<br>
return R_PC;<br>
@@ -451,21 +451,21 @@ static RelExpr fromPlt(RelExpr Expr) {<br>
case R_PLT:<br>
return R_ABS;<br>
default:<br>
- return Expr;<br>
+ return expr;<br>
}<br>
}<br>
<br>
// Returns true if a given shared symbol is in a read-only segment in a DSO.<br>
-template <class ELFT> static bool isReadOnly(SharedSymbol &SS) {<br>
+template <class ELFT> static bool isReadOnly(SharedSymbol &ss) {<br>
using Elf_Phdr = typename ELFT::Phdr;<br>
<br>
// Determine if the symbol is read-only by scanning the DSO's program headers.<br>
- const SharedFile &File = SS.getFile();<br>
- for (const Elf_Phdr &Phdr :<br>
- check(File.template getObj<ELFT>().program_headers()))<br>
- if ((Phdr.p_type == ELF::PT_LOAD || Phdr.p_type == ELF::PT_GNU_RELRO) &&<br>
- !(Phdr.p_flags & ELF::PF_W) && SS.Value >= Phdr.p_vaddr &&<br>
- SS.Value < Phdr.p_vaddr + Phdr.p_memsz)<br>
+ const SharedFile &file = ss.getFile();<br>
+ for (const Elf_Phdr &phdr :<br>
+ check(file.template getObj<ELFT>().program_headers()))<br>
+ if ((phdr.p_type == ELF::PT_LOAD || phdr.p_type == ELF::PT_GNU_RELRO) &&<br>
+ !(phdr.p_flags & ELF::PF_W) && ss.value >= phdr.p_vaddr &&<br>
+ ss.value < phdr.p_vaddr + phdr.p_memsz)<br>
return true;<br>
return false;<br>
}<br>
@@ -476,22 +476,22 @@ template <class ELFT> static bool isRead<br>
// them are copied by a copy relocation, all of them need to be copied.<br>
// Otherwise, they would refer to different places at runtime.<br>
template <class ELFT><br>
-static SmallSet<SharedSymbol *, 4> getSymbolsAt(SharedSymbol &SS) {<br>
+static SmallSet<SharedSymbol *, 4> getSymbolsAt(SharedSymbol &ss) {<br>
using Elf_Sym = typename ELFT::Sym;<br>
<br>
- SharedFile &File = SS.getFile();<br>
+ SharedFile &file = ss.getFile();<br>
<br>
- SmallSet<SharedSymbol *, 4> Ret;<br>
- for (const Elf_Sym &S : File.template getGlobalELFSyms<ELFT>()) {<br>
- if (S.st_shndx == SHN_UNDEF || S.st_shndx == SHN_ABS ||<br>
- S.getType() == STT_TLS || S.st_value != SS.Value)<br>
+ SmallSet<SharedSymbol *, 4> ret;<br>
+ for (const Elf_Sym &s : file.template getGlobalELFSyms<ELFT>()) {<br>
+ if (s.st_shndx == SHN_UNDEF || s.st_shndx == SHN_ABS ||<br>
+ s.getType() == STT_TLS || s.st_value != ss.value)<br>
continue;<br>
- StringRef Name = check(S.getName(File.getStringTable()));<br>
- Symbol *Sym = Symtab->find(Name);<br>
- if (auto *Alias = dyn_cast_or_null<SharedSymbol>(Sym))<br>
- Ret.insert(Alias);<br>
+ StringRef name = check(s.getName(file.getStringTable()));<br>
+ Symbol *sym = symtab->find(name);<br>
+ if (auto *alias = dyn_cast_or_null<SharedSymbol>(sym))<br>
+ ret.insert(alias);<br>
}<br>
- return Ret;<br>
+ return ret;<br>
}<br>
<br>
// When a symbol is copy relocated or we create a canonical plt entry, it is<br>
@@ -499,21 +499,21 @@ static SmallSet<SharedSymbol *, 4> getSy<br>
// in .bss and in the case of a canonical plt entry it is in .plt. This function<br>
// replaces the existing symbol with a Defined pointing to the appropriate<br>
// location.<br>
-static void replaceWithDefined(Symbol &Sym, SectionBase *Sec, uint64_t Value,<br>
- uint64_t Size) {<br>
- Symbol Old = Sym;<br>
-<br>
- Sym.replace(Defined{Sym.File, Sym.getName(), Sym.Binding, Sym.StOther,<br>
- Sym.Type, Value, Size, Sec});<br>
-<br>
- Sym.PltIndex = Old.PltIndex;<br>
- Sym.GotIndex = Old.GotIndex;<br>
- Sym.VerdefIndex = Old.VerdefIndex;<br>
- Sym.PPC64BranchltIndex = Old.PPC64BranchltIndex;<br>
- Sym.IsPreemptible = true;<br>
- Sym.ExportDynamic = true;<br>
- Sym.IsUsedInRegularObj = true;<br>
- Sym.Used = true;<br>
+static void replaceWithDefined(Symbol &sym, SectionBase *sec, uint64_t value,<br>
+ uint64_t size) {<br>
+ Symbol old = sym;<br>
+<br>
+ sym.replace(Defined{sym.file, sym.getName(), sym.binding, sym.stOther,<br>
+ sym.type, value, size, sec});<br>
+<br>
+ sym.pltIndex = old.pltIndex;<br>
+ sym.gotIndex = old.gotIndex;<br>
+ sym.verdefIndex = old.verdefIndex;<br>
+ sym.ppc64BranchltIndex = old.ppc64BranchltIndex;<br>
+ sym.isPreemptible = true;<br>
+ sym.exportDynamic = true;<br>
+ sym.isUsedInRegularObj = true;<br>
+ sym.used = true;<br>
}<br>
<br>
// Reserve space in .bss or .<a href="http://bss.rel.ro" rel="noreferrer" target="_blank">bss.rel.ro</a> for copy relocation.<br>
@@ -558,29 +558,29 @@ static void replaceWithDefined(Symbol &S<br>
// to the variable in .bss. This kind of issue is sometimes very hard to<br>
// debug. What's a solution? Instead of exporting a varaible V from a DSO,<br>
// define an accessor getV().<br>
-template <class ELFT> static void addCopyRelSymbol(SharedSymbol &SS) {<br>
+template <class ELFT> static void addCopyRelSymbol(SharedSymbol &ss) {<br>
// Copy relocation against zero-sized symbol doesn't make sense.<br>
- uint64_t SymSize = SS.getSize();<br>
- if (SymSize == 0 || SS.Alignment == 0)<br>
- fatal("cannot create a copy relocation for symbol " + toString(SS));<br>
+ uint64_t symSize = ss.getSize();<br>
+ if (symSize == 0 || ss.alignment == 0)<br>
+ fatal("cannot create a copy relocation for symbol " + toString(ss));<br>
<br>
// See if this symbol is in a read-only segment. If so, preserve the symbol's<br>
// memory protection by reserving space in the .<a href="http://bss.rel.ro" rel="noreferrer" target="_blank">bss.rel.ro</a> section.<br>
- bool IsRO = isReadOnly<ELFT>(SS);<br>
- BssSection *Sec =<br>
- make<BssSection>(IsRO ? ".<a href="http://bss.rel.ro" rel="noreferrer" target="_blank">bss.rel.ro</a>" : ".bss", SymSize, SS.Alignment);<br>
- if (IsRO)<br>
- In.BssRelRo->getParent()->addSection(Sec);<br>
+ bool isRO = isReadOnly<ELFT>(ss);<br>
+ BssSection *sec =<br>
+ make<BssSection>(isRO ? ".<a href="http://bss.rel.ro" rel="noreferrer" target="_blank">bss.rel.ro</a>" : ".bss", symSize, ss.alignment);<br>
+ if (isRO)<br>
+ in.bssRelRo->getParent()->addSection(sec);<br>
else<br>
- In.Bss->getParent()->addSection(Sec);<br>
+ in.bss->getParent()->addSection(sec);<br>
<br>
// Look through the DSO's dynamic symbol table for aliases and create a<br>
// dynamic symbol for each one. This causes the copy relocation to correctly<br>
// interpose any aliases.<br>
- for (SharedSymbol *Sym : getSymbolsAt<ELFT>(SS))<br>
- replaceWithDefined(*Sym, Sec, 0, Sym->Size);<br>
+ for (SharedSymbol *sym : getSymbolsAt<ELFT>(ss))<br>
+ replaceWithDefined(*sym, sec, 0, sym->size);<br>
<br>
- Main->RelaDyn->addReloc(Target->CopyRel, Sec, 0, &SS);<br>
+ mainPart->relaDyn->addReloc(target->copyRel, sec, 0, &ss);<br>
}<br>
<br>
// MIPS has an odd notion of "paired" relocations to calculate addends.<br>
@@ -588,34 +588,34 @@ template <class ELFT> static void addCop<br>
// R_MIPS_LO16 relocation after that, and an addend is calculated using<br>
// the two relocations.<br>
template <class ELFT, class RelTy><br>
-static int64_t computeMipsAddend(const RelTy &Rel, const RelTy *End,<br>
- InputSectionBase &Sec, RelExpr Expr,<br>
- bool IsLocal) {<br>
- if (Expr == R_MIPS_GOTREL && IsLocal)<br>
- return Sec.getFile<ELFT>()->MipsGp0;<br>
+static int64_t computeMipsAddend(const RelTy &rel, const RelTy *end,<br>
+ InputSectionBase &sec, RelExpr expr,<br>
+ bool isLocal) {<br>
+ if (expr == R_MIPS_GOTREL && isLocal)<br>
+ return sec.getFile<ELFT>()->mipsGp0;<br>
<br>
// The ABI says that the paired relocation is used only for REL.<br>
// See p. 4-17 at <a href="https://urldefense.proofpoint.com/v2/url?u=ftp-3A__www.linux-2Dmips.org_pub_linux_mips_doc_ABI_mipsabi.pdf&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=RAkf3Vl5MWzirfmkwopuyQjQ-5uEE95ctSfXOidHyHs&e=" rel="noreferrer" target="_blank">https://urldefense.proofpoint.com/v2/url?u=ftp-3A__www.linux-2Dmips.org_pub_linux_mips_doc_ABI_mipsabi.pdf&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=RAkf3Vl5MWzirfmkwopuyQjQ-5uEE95ctSfXOidHyHs&e=</a> <br>
if (RelTy::IsRela)<br>
return 0;<br>
<br>
- RelType Type = Rel.getType(Config->IsMips64EL);<br>
- uint32_t PairTy = getMipsPairType(Type, IsLocal);<br>
- if (PairTy == R_MIPS_NONE)<br>
+ RelType type = rel.getType(config->isMips64EL);<br>
+ uint32_t pairTy = getMipsPairType(type, isLocal);<br>
+ if (pairTy == R_MIPS_NONE)<br>
return 0;<br>
<br>
- const uint8_t *Buf = Sec.data().data();<br>
- uint32_t SymIndex = Rel.getSymbol(Config->IsMips64EL);<br>
+ const uint8_t *buf = sec.data().data();<br>
+ uint32_t symIndex = rel.getSymbol(config->isMips64EL);<br>
<br>
// To make things worse, paired relocations might not be contiguous in<br>
// the relocation table, so we need to do linear search. *sigh*<br>
- for (const RelTy *RI = &Rel; RI != End; ++RI)<br>
- if (RI->getType(Config->IsMips64EL) == PairTy &&<br>
- RI->getSymbol(Config->IsMips64EL) == SymIndex)<br>
- return Target->getImplicitAddend(Buf + RI->r_offset, PairTy);<br>
+ for (const RelTy *ri = &rel; ri != end; ++ri)<br>
+ if (ri->getType(config->isMips64EL) == pairTy &&<br>
+ ri->getSymbol(config->isMips64EL) == symIndex)<br>
+ return target->getImplicitAddend(buf + ri->r_offset, pairTy);<br>
<br>
- warn("can't find matching " + toString(PairTy) + " relocation for " +<br>
- toString(Type));<br>
+ warn("can't find matching " + toString(pairTy) + " relocation for " +<br>
+ toString(type));<br>
return 0;<br>
}<br>
<br>
@@ -623,82 +623,82 @@ static int64_t computeMipsAddend(const R<br>
// is in a relocation itself. If it is REL, we need to read it from an<br>
// input section.<br>
template <class ELFT, class RelTy><br>
-static int64_t computeAddend(const RelTy &Rel, const RelTy *End,<br>
- InputSectionBase &Sec, RelExpr Expr,<br>
- bool IsLocal) {<br>
- int64_t Addend;<br>
- RelType Type = Rel.getType(Config->IsMips64EL);<br>
+static int64_t computeAddend(const RelTy &rel, const RelTy *end,<br>
+ InputSectionBase &sec, RelExpr expr,<br>
+ bool isLocal) {<br>
+ int64_t addend;<br>
+ RelType type = rel.getType(config->isMips64EL);<br>
<br>
if (RelTy::IsRela) {<br>
- Addend = getAddend<ELFT>(Rel);<br>
+ addend = getAddend<ELFT>(rel);<br>
} else {<br>
- const uint8_t *Buf = Sec.data().data();<br>
- Addend = Target->getImplicitAddend(Buf + Rel.r_offset, Type);<br>
+ const uint8_t *buf = sec.data().data();<br>
+ addend = target->getImplicitAddend(buf + rel.r_offset, type);<br>
}<br>
<br>
- if (Config->EMachine == EM_PPC64 && Config->Pic && Type == R_PPC64_TOC)<br>
- Addend += getPPC64TocBase();<br>
- if (Config->EMachine == EM_MIPS)<br>
- Addend += computeMipsAddend<ELFT>(Rel, End, Sec, Expr, IsLocal);<br>
+ if (config->emachine == EM_PPC64 && config->isPic && type == R_PPC64_TOC)<br>
+ addend += getPPC64TocBase();<br>
+ if (config->emachine == EM_MIPS)<br>
+ addend += computeMipsAddend<ELFT>(rel, end, sec, expr, isLocal);<br>
<br>
- return Addend;<br>
+ return addend;<br>
}<br>
<br>
// Custom error message if Sym is defined in a discarded section.<br>
template <class ELFT><br>
-static std::string maybeReportDiscarded(Undefined &Sym) {<br>
- auto *File = dyn_cast_or_null<ObjFile<ELFT>>(Sym.File);<br>
- if (!File || !Sym.DiscardedSecIdx ||<br>
- File->getSections()[Sym.DiscardedSecIdx] != &InputSection::Discarded)<br>
+static std::string maybeReportDiscarded(Undefined &sym) {<br>
+ auto *file = dyn_cast_or_null<ObjFile<ELFT>>(sym.file);<br>
+ if (!file || !sym.discardedSecIdx ||<br>
+ file->getSections()[sym.discardedSecIdx] != &InputSection::discarded)<br>
return "";<br>
- ArrayRef<Elf_Shdr_Impl<ELFT>> ObjSections =<br>
- CHECK(File->getObj().sections(), File);<br>
+ ArrayRef<Elf_Shdr_Impl<ELFT>> objSections =<br>
+ CHECK(file->getObj().sections(), file);<br>
<br>
- std::string Msg;<br>
- if (Sym.Type == ELF::STT_SECTION) {<br>
- Msg = "relocation refers to a discarded section: ";<br>
- Msg += CHECK(<br>
- File->getObj().getSectionName(&ObjSections[Sym.DiscardedSecIdx]), File);<br>
+ std::string msg;<br>
+ if (sym.type == ELF::STT_SECTION) {<br>
+ msg = "relocation refers to a discarded section: ";<br>
+ msg += CHECK(<br>
+ file->getObj().getSectionName(&objSections[sym.discardedSecIdx]), file);<br>
} else {<br>
- Msg = "relocation refers to a symbol in a discarded section: " +<br>
- toString(Sym);<br>
+ msg = "relocation refers to a symbol in a discarded section: " +<br>
+ toString(sym);<br>
}<br>
- Msg += "\n>>> defined in " + toString(File);<br>
+ msg += "\n>>> defined in " + toString(file);<br>
<br>
- Elf_Shdr_Impl<ELFT> ELFSec = ObjSections[Sym.DiscardedSecIdx - 1];<br>
- if (ELFSec.sh_type != SHT_GROUP)<br>
- return Msg;<br>
+ Elf_Shdr_Impl<ELFT> elfSec = objSections[sym.discardedSecIdx - 1];<br>
+ if (elfSec.sh_type != SHT_GROUP)<br>
+ return msg;<br>
<br>
// If the discarded section is a COMDAT.<br>
- StringRef Signature = File->getShtGroupSignature(ObjSections, ELFSec);<br>
- if (const InputFile *Prevailing =<br>
- Symtab->ComdatGroups.lookup(CachedHashStringRef(Signature)))<br>
- Msg += "\n>>> section group signature: " + Signature.str() +<br>
- "\n>>> prevailing definition is in " + toString(Prevailing);<br>
- return Msg;<br>
+ StringRef signature = file->getShtGroupSignature(objSections, elfSec);<br>
+ if (const InputFile *prevailing =<br>
+ symtab->comdatGroups.lookup(CachedHashStringRef(signature)))<br>
+ msg += "\n>>> section group signature: " + signature.str() +<br>
+ "\n>>> prevailing definition is in " + toString(prevailing);<br>
+ return msg;<br>
}<br>
<br>
// Undefined diagnostics are collected in a vector and emitted once all of<br>
// them are known, so that some postprocessing on the list of undefined symbols<br>
// can happen before lld emits diagnostics.<br>
struct UndefinedDiag {<br>
- Symbol *Sym;<br>
+ Symbol *sym;<br>
struct Loc {<br>
- InputSectionBase *Sec;<br>
- uint64_t Offset;<br>
+ InputSectionBase *sec;<br>
+ uint64_t offset;<br>
};<br>
- std::vector<Loc> Locs;<br>
- bool IsWarning;<br>
+ std::vector<Loc> locs;<br>
+ bool isWarning;<br>
};<br>
<br>
-static std::vector<UndefinedDiag> Undefs;<br>
+static std::vector<UndefinedDiag> undefs;<br>
<br>
template <class ELFT><br>
-static void reportUndefinedSymbol(const UndefinedDiag &Undef) {<br>
- Symbol &Sym = *Undef.Sym;<br>
+static void reportUndefinedSymbol(const UndefinedDiag &undef) {<br>
+ Symbol &sym = *undef.sym;<br>
<br>
- auto Visibility = [&]() -> std::string {<br>
- switch (Sym.Visibility) {<br>
+ auto visibility = [&]() -> std::string {<br>
+ switch (sym.visibility) {<br>
case STV_INTERNAL:<br>
return "internal ";<br>
case STV_HIDDEN:<br>
@@ -710,71 +710,71 @@ static void reportUndefinedSymbol(const<br>
}<br>
};<br>
<br>
- std::string Msg = maybeReportDiscarded<ELFT>(cast<Undefined>(Sym));<br>
- if (Msg.empty())<br>
- Msg = "undefined " + Visibility() + "symbol: " + toString(Sym);<br>
-<br>
- const size_t MaxUndefReferences = 10;<br>
- size_t I = 0;<br>
- for (UndefinedDiag::Loc L : Undef.Locs) {<br>
- if (I >= MaxUndefReferences)<br>
+ std::string msg = maybeReportDiscarded<ELFT>(cast<Undefined>(sym));<br>
+ if (msg.empty())<br>
+ msg = "undefined " + visibility() + "symbol: " + toString(sym);<br>
+<br>
+ const size_t maxUndefReferences = 10;<br>
+ size_t i = 0;<br>
+ for (UndefinedDiag::Loc l : undef.locs) {<br>
+ if (i >= maxUndefReferences)<br>
break;<br>
- InputSectionBase &Sec = *L.Sec;<br>
- uint64_t Offset = L.Offset;<br>
+ InputSectionBase &sec = *l.sec;<br>
+ uint64_t offset = l.offset;<br>
<br>
- Msg += "\n>>> referenced by ";<br>
- std::string Src = Sec.getSrcMsg(Sym, Offset);<br>
- if (!Src.empty())<br>
- Msg += Src + "\n>>> ";<br>
- Msg += Sec.getObjMsg(Offset);<br>
- I++;<br>
+ msg += "\n>>> referenced by ";<br>
+ std::string src = sec.getSrcMsg(sym, offset);<br>
+ if (!src.empty())<br>
+ msg += src + "\n>>> ";<br>
+ msg += sec.getObjMsg(offset);<br>
+ i++;<br>
}<br>
<br>
- if (I < Undef.Locs.size())<br>
- Msg += ("\n>>> referenced " + Twine(Undef.Locs.size() - I) + " more times")<br>
+ if (i < undef.locs.size())<br>
+ msg += ("\n>>> referenced " + Twine(undef.locs.size() - i) + " more times")<br>
.str();<br>
<br>
- if (Sym.getName().startswith("_ZTV"))<br>
- Msg += "\nthe vtable symbol may be undefined because the class is missing "<br>
+ if (sym.getName().startswith("_ZTV"))<br>
+ msg += "\nthe vtable symbol may be undefined because the class is missing "<br>
"its key function (see <a href="https://urldefense.proofpoint.com/v2/url?u=https-3A__lld.llvm.org_missingkeyfunction&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=JH-BkRDg7ipWrG1X8NiQgMKCXDvJVHRblR015SyHI8w&e=" rel="noreferrer" target="_blank">https://urldefense.proofpoint.com/v2/url?u=https-3A__lld.llvm.org_missingkeyfunction&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=JH-BkRDg7ipWrG1X8NiQgMKCXDvJVHRblR015SyHI8w&e=</a> )";<br>
<br>
- if (Undef.IsWarning)<br>
- warn(Msg);<br>
+ if (undef.isWarning)<br>
+ warn(msg);<br>
else<br>
- error(Msg);<br>
+ error(msg);<br>
}<br>
<br>
template <class ELFT> void elf::reportUndefinedSymbols() {<br>
// Find the first "undefined symbol" diagnostic for each diagnostic, and<br>
// collect all "referenced from" lines at the first diagnostic.<br>
- DenseMap<Symbol *, UndefinedDiag *> FirstRef;<br>
- for (UndefinedDiag &Undef : Undefs) {<br>
- assert(Undef.Locs.size() == 1);<br>
- if (UndefinedDiag *Canon = FirstRef.lookup(Undef.Sym)) {<br>
- Canon->Locs.push_back(Undef.Locs[0]);<br>
- Undef.Locs.clear();<br>
+ DenseMap<Symbol *, UndefinedDiag *> firstRef;<br>
+ for (UndefinedDiag &undef : undefs) {<br>
+ assert(undef.locs.size() == 1);<br>
+ if (UndefinedDiag *canon = firstRef.lookup(undef.sym)) {<br>
+ canon->locs.push_back(undef.locs[0]);<br>
+ undef.locs.clear();<br>
} else<br>
- FirstRef[Undef.Sym] = &Undef;<br>
+ firstRef[undef.sym] = &undef;<br>
}<br>
<br>
- for (const UndefinedDiag &Undef : Undefs) {<br>
- if (!Undef.Locs.empty())<br>
- reportUndefinedSymbol<ELFT>(Undef);<br>
+ for (const UndefinedDiag &undef : undefs) {<br>
+ if (!undef.locs.empty())<br>
+ reportUndefinedSymbol<ELFT>(undef);<br>
}<br>
- Undefs.clear();<br>
+ undefs.clear();<br>
}<br>
<br>
// Report an undefined symbol if necessary.<br>
// Returns true if the undefined symbol will produce an error message.<br>
template <class ELFT><br>
-static bool maybeReportUndefined(Symbol &Sym, InputSectionBase &Sec,<br>
- uint64_t Offset) {<br>
- if (!Sym.isUndefined() || Sym.isWeak())<br>
+static bool maybeReportUndefined(Symbol &sym, InputSectionBase &sec,<br>
+ uint64_t offset) {<br>
+ if (!sym.isUndefined() || sym.isWeak())<br>
return false;<br>
<br>
- bool CanBeExternal = !Sym.isLocal() && Sym.computeBinding() != STB_LOCAL &&<br>
- Sym.Visibility == STV_DEFAULT;<br>
- if (Config->UnresolvedSymbols == UnresolvedPolicy::Ignore && CanBeExternal)<br>
+ bool canBeExternal = !sym.isLocal() && sym.computeBinding() != STB_LOCAL &&<br>
+ sym.visibility == STV_DEFAULT;<br>
+ if (config->unresolvedSymbols == UnresolvedPolicy::Ignore && canBeExternal)<br>
return false;<br>
<br>
// clang (as of 2019-06-12) / gcc (as of 8.2.1) PPC64 may emit a .rela.toc<br>
@@ -782,15 +782,15 @@ static bool maybeReportUndefined(Symbol<br>
// .toc and the .rela.toc are incorrectly not placed in the comdat. The ELF<br>
// spec says references from outside the group to a STB_LOCAL symbol are not<br>
// allowed. Work around the bug.<br>
- if (Config->EMachine == EM_PPC64 &&<br>
- cast<Undefined>(Sym).DiscardedSecIdx != 0 && Sec.Name == ".toc")<br>
+ if (config->emachine == EM_PPC64 &&<br>
+ cast<Undefined>(sym).discardedSecIdx != 0 && <a href="http://sec.name" rel="noreferrer" target="_blank">sec.name</a> == ".toc")<br>
return false;<br>
<br>
- bool IsWarning =<br>
- (Config->UnresolvedSymbols == UnresolvedPolicy::Warn && CanBeExternal) ||<br>
- Config->NoinhibitExec;<br>
- Undefs.push_back({&Sym, {{&Sec, Offset}}, IsWarning});<br>
- return !IsWarning;<br>
+ bool isWarning =<br>
+ (config->unresolvedSymbols == UnresolvedPolicy::Warn && canBeExternal) ||<br>
+ config->noinhibitExec;<br>
+ undefs.push_back({&sym, {{&sec, offset}}, isWarning});<br>
+ return !isWarning;<br>
}<br>
<br>
// MIPS N32 ABI treats series of successive relocations with the same offset<br>
@@ -798,14 +798,14 @@ static bool maybeReportUndefined(Symbol<br>
// packs all relocations into the single relocation record. Here we emulate<br>
// this for the N32 ABI. Iterate over relocation with the same offset and put<br>
// theirs types into the single bit-set.<br>
-template <class RelTy> static RelType getMipsN32RelType(RelTy *&Rel, RelTy *End) {<br>
- RelType Type = 0;<br>
- uint64_t Offset = Rel->r_offset;<br>
-<br>
- int N = 0;<br>
- while (Rel != End && Rel->r_offset == Offset)<br>
- Type |= (Rel++)->getType(Config->IsMips64EL) << (8 * N++);<br>
- return Type;<br>
+template <class RelTy> static RelType getMipsN32RelType(RelTy *&rel, RelTy *end) {<br>
+ RelType type = 0;<br>
+ uint64_t offset = rel->r_offset;<br>
+<br>
+ int n = 0;<br>
+ while (rel != end && rel->r_offset == offset)<br>
+ type |= (rel++)->getType(config->isMips64EL) << (8 * n++);<br>
+ return type;<br>
}<br>
<br>
// .eh_frame sections are mergeable input sections, so their input<br>
@@ -822,42 +822,42 @@ template <class RelTy> static RelType ge<br>
namespace {<br>
class OffsetGetter {<br>
public:<br>
- explicit OffsetGetter(InputSectionBase &Sec) {<br>
- if (auto *Eh = dyn_cast<EhInputSection>(&Sec))<br>
- Pieces = Eh->Pieces;<br>
+ explicit OffsetGetter(InputSectionBase &sec) {<br>
+ if (auto *eh = dyn_cast<EhInputSection>(&sec))<br>
+ pieces = eh->pieces;<br>
}<br>
<br>
// Translates offsets in input sections to offsets in output sections.<br>
// Given offset must increase monotonically. We assume that Piece is<br>
// sorted by InputOff.<br>
- uint64_t get(uint64_t Off) {<br>
- if (Pieces.empty())<br>
- return Off;<br>
-<br>
- while (I != Pieces.size() && Pieces[I].InputOff + Pieces[I].Size <= Off)<br>
- ++I;<br>
- if (I == Pieces.size())<br>
+ uint64_t get(uint64_t off) {<br>
+ if (pieces.empty())<br>
+ return off;<br>
+<br>
+ while (i != pieces.size() && pieces[i].inputOff + pieces[i].size <= off)<br>
+ ++i;<br>
+ if (i == pieces.size())<br>
fatal(".eh_frame: relocation is not in any piece");<br>
<br>
// Pieces must be contiguous, so there must be no holes in between.<br>
- assert(Pieces[I].InputOff <= Off && "Relocation not in any piece");<br>
+ assert(pieces[i].inputOff <= off && "Relocation not in any piece");<br>
<br>
// Offset -1 means that the piece is dead (i.e. garbage collected).<br>
- if (Pieces[I].OutputOff == -1)<br>
+ if (pieces[i].outputOff == -1)<br>
return -1;<br>
- return Pieces[I].OutputOff + Off - Pieces[I].InputOff;<br>
+ return pieces[i].outputOff + off - pieces[i].inputOff;<br>
}<br>
<br>
private:<br>
- ArrayRef<EhSectionPiece> Pieces;<br>
- size_t I = 0;<br>
+ ArrayRef<EhSectionPiece> pieces;<br>
+ size_t i = 0;<br>
};<br>
} // namespace<br>
<br>
-static void addRelativeReloc(InputSectionBase *IS, uint64_t OffsetInSec,<br>
- Symbol *Sym, int64_t Addend, RelExpr Expr,<br>
- RelType Type) {<br>
- Partition &Part = IS->getPartition();<br>
+static void addRelativeReloc(InputSectionBase *isec, uint64_t offsetInSec,<br>
+ Symbol *sym, int64_t addend, RelExpr expr,<br>
+ RelType type) {<br>
+ Partition &part = isec->getPartition();<br>
<br>
// Add a relative relocation. If RelrDyn section is enabled, and the<br>
// relocation offset is guaranteed to be even, add the relocation to<br>
@@ -865,29 +865,29 @@ static void addRelativeReloc(InputSectio<br>
// RelrDyn sections don't support odd offsets. Also, RelrDyn sections<br>
// don't store the addend values, so we must write it to the relocated<br>
// address.<br>
- if (Part.RelrDyn && IS->Alignment >= 2 && OffsetInSec % 2 == 0) {<br>
- IS->Relocations.push_back({Expr, Type, OffsetInSec, Addend, Sym});<br>
- Part.RelrDyn->Relocs.push_back({IS, OffsetInSec});<br>
+ if (part.relrDyn && isec->alignment >= 2 && offsetInSec % 2 == 0) {<br>
+ isec->relocations.push_back({expr, type, offsetInSec, addend, sym});<br>
+ part.relrDyn->relocs.push_back({isec, offsetInSec});<br>
return;<br>
}<br>
- Part.RelaDyn->addReloc(Target->RelativeRel, IS, OffsetInSec, Sym, Addend,<br>
- Expr, Type);<br>
+ part.relaDyn->addReloc(target->relativeRel, isec, offsetInSec, sym, addend,<br>
+ expr, type);<br>
}<br>
<br>
template <class ELFT, class GotPltSection><br>
-static void addPltEntry(PltSection *Plt, GotPltSection *GotPlt,<br>
- RelocationBaseSection *Rel, RelType Type, Symbol &Sym) {<br>
- Plt->addEntry<ELFT>(Sym);<br>
- GotPlt->addEntry(Sym);<br>
- Rel->addReloc(<br>
- {Type, GotPlt, Sym.getGotPltOffset(), !Sym.IsPreemptible, &Sym, 0});<br>
+static void addPltEntry(PltSection *plt, GotPltSection *gotPlt,<br>
+ RelocationBaseSection *rel, RelType type, Symbol &sym) {<br>
+ plt->addEntry<ELFT>(sym);<br>
+ gotPlt->addEntry(sym);<br>
+ rel->addReloc(<br>
+ {type, gotPlt, sym.getGotPltOffset(), !sym.isPreemptible, &sym, 0});<br>
}<br>
<br>
-static void addGotEntry(Symbol &Sym) {<br>
- In.Got->addEntry(Sym);<br>
+static void addGotEntry(Symbol &sym) {<br>
+ in.got->addEntry(sym);<br>
<br>
- RelExpr Expr = Sym.isTls() ? R_TLS : R_ABS;<br>
- uint64_t Off = Sym.getGotOffset();<br>
+ RelExpr expr = sym.isTls() ? R_TLS : R_ABS;<br>
+ uint64_t off = sym.getGotOffset();<br>
<br>
// If a GOT slot value can be calculated at link-time, which is now,<br>
// we can just fill that out.<br>
@@ -896,42 +896,42 @@ static void addGotEntry(Symbol &Sym) {<br>
// add a static relocation to a Relocations vector so that<br>
// InputSection::relocate will do the work for us. We may be able<br>
// to just write a value now, but it is a TODO.)<br>
- bool IsLinkTimeConstant =<br>
- !Sym.IsPreemptible && (!Config->Pic || isAbsolute(Sym));<br>
- if (IsLinkTimeConstant) {<br>
- In.Got->Relocations.push_back({Expr, Target->SymbolicRel, Off, 0, &Sym});<br>
+ bool isLinkTimeConstant =<br>
+ !sym.isPreemptible && (!config->isPic || isAbsolute(sym));<br>
+ if (isLinkTimeConstant) {<br>
+ in.got->relocations.push_back({expr, target->symbolicRel, off, 0, &sym});<br>
return;<br>
}<br>
<br>
// Otherwise, we emit a dynamic relocation to .rel[a].dyn so that<br>
// the GOT slot will be fixed at load-time.<br>
- if (!Sym.isTls() && !Sym.IsPreemptible && Config->Pic && !isAbsolute(Sym)) {<br>
- addRelativeReloc(In.Got, Off, &Sym, 0, R_ABS, Target->SymbolicRel);<br>
+ if (!sym.isTls() && !sym.isPreemptible && config->isPic && !isAbsolute(sym)) {<br>
+ addRelativeReloc(in.got, off, &sym, 0, R_ABS, target->symbolicRel);<br>
return;<br>
}<br>
- Main->RelaDyn->addReloc(<br>
- Sym.isTls() ? Target->TlsGotRel : Target->GotRel, In.Got, Off, &Sym, 0,<br>
- Sym.IsPreemptible ? R_ADDEND : R_ABS, Target->SymbolicRel);<br>
+ mainPart->relaDyn->addReloc(<br>
+ sym.isTls() ? target->tlsGotRel : target->gotRel, in.got, off, &sym, 0,<br>
+ sym.isPreemptible ? R_ADDEND : R_ABS, target->symbolicRel);<br>
}<br>
<br>
// Return true if we can define a symbol in the executable that<br>
// contains the value/function of a symbol defined in a shared<br>
// library.<br>
-static bool canDefineSymbolInExecutable(Symbol &Sym) {<br>
+static bool canDefineSymbolInExecutable(Symbol &sym) {<br>
// If the symbol has default visibility the symbol defined in the<br>
// executable will preempt it.<br>
// Note that we want the visibility of the shared symbol itself, not<br>
// the visibility of the symbol in the output file we are producing. That is<br>
// why we use Sym.StOther.<br>
- if ((Sym.StOther & 0x3) == STV_DEFAULT)<br>
+ if ((sym.stOther & 0x3) == STV_DEFAULT)<br>
return true;<br>
<br>
// If we are allowed to break address equality of functions, defining<br>
// a plt entry will allow the program to call the function in the<br>
// .so, but the .so and the executable will no agree on the address<br>
// of the function. Similar logic for objects.<br>
- return ((Sym.isFunc() && Config->IgnoreFunctionAddressEquality) ||<br>
- (Sym.isObject() && Config->IgnoreDataAddressEquality));<br>
+ return ((sym.isFunc() && config->ignoreFunctionAddressEquality) ||<br>
+ (sym.isObject() && config->ignoreDataAddressEquality));<br>
}<br>
<br>
// The reason we have to do this early scan is as follows<br>
@@ -948,9 +948,9 @@ static bool canDefineSymbolInExecutable(<br>
// complicates things for the dynamic linker and means we would have to reserve<br>
// space for the extra PT_LOAD even if we end up not using it.<br>
template <class ELFT, class RelTy><br>
-static void processRelocAux(InputSectionBase &Sec, RelExpr Expr, RelType Type,<br>
- uint64_t Offset, Symbol &Sym, const RelTy &Rel,<br>
- int64_t Addend) {<br>
+static void processRelocAux(InputSectionBase &sec, RelExpr expr, RelType type,<br>
+ uint64_t offset, Symbol &sym, const RelTy &rel,<br>
+ int64_t addend) {<br>
// If the relocation is known to be a link-time constant, we know no dynamic<br>
// relocation will be created, pass the control to relocateAlloc() or<br>
// relocateNonAlloc() to resolve it.<br>
@@ -958,23 +958,23 @@ static void processRelocAux(InputSection<br>
// The behavior of an undefined weak reference is implementation defined. If<br>
// the relocation is to a weak undef, and we are producing an executable, let<br>
// relocate{,Non}Alloc() resolve it.<br>
- if (isStaticLinkTimeConstant(Expr, Type, Sym, Sec, Offset) ||<br>
- (!Config->Shared && Sym.isUndefWeak())) {<br>
- Sec.Relocations.push_back({Expr, Type, Offset, Addend, &Sym});<br>
+ if (isStaticLinkTimeConstant(expr, type, sym, sec, offset) ||<br>
+ (!config->shared && sym.isUndefWeak())) {<br>
+ sec.relocations.push_back({expr, type, offset, addend, &sym});<br>
return;<br>
}<br>
<br>
- bool CanWrite = (Sec.Flags & SHF_WRITE) || !Config->ZText;<br>
- if (CanWrite) {<br>
- RelType Rel = Target->getDynRel(Type);<br>
- if (Expr == R_GOT || (Rel == Target->SymbolicRel && !Sym.IsPreemptible)) {<br>
- addRelativeReloc(&Sec, Offset, &Sym, Addend, Expr, Type);<br>
+ bool canWrite = (sec.flags & SHF_WRITE) || !config->zText;<br>
+ if (canWrite) {<br>
+ RelType rel = target->getDynRel(type);<br>
+ if (expr == R_GOT || (rel == target->symbolicRel && !sym.isPreemptible)) {<br>
+ addRelativeReloc(&sec, offset, &sym, addend, expr, type);<br>
return;<br>
- } else if (Rel != 0) {<br>
- if (Config->EMachine == EM_MIPS && Rel == Target->SymbolicRel)<br>
- Rel = Target->RelativeRel;<br>
- Sec.getPartition().RelaDyn->addReloc(Rel, &Sec, Offset, &Sym, Addend,<br>
- R_ADDEND, Type);<br>
+ } else if (rel != 0) {<br>
+ if (config->emachine == EM_MIPS && rel == target->symbolicRel)<br>
+ rel = target->relativeRel;<br>
+ sec.getPartition().relaDyn->addReloc(rel, &sec, offset, &sym, addend,<br>
+ R_ADDEND, type);<br>
<br>
// MIPS ABI turns using of GOT and dynamic relocations inside out.<br>
// While regular ABI uses dynamic relocations to fill up GOT entries<br>
@@ -991,19 +991,19 @@ static void processRelocAux(InputSection<br>
// to the GOT entry and reads the GOT entry when it needs to perform<br>
// a dynamic relocation.<br>
// <a href="https://urldefense.proofpoint.com/v2/url?u=ftp-3A__www.linux-2Dmips.org_pub_linux_mips_doc_ABI_mipsabi.pdf&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=RAkf3Vl5MWzirfmkwopuyQjQ-5uEE95ctSfXOidHyHs&e=" rel="noreferrer" target="_blank">https://urldefense.proofpoint.com/v2/url?u=ftp-3A__www.linux-2Dmips.org_pub_linux_mips_doc_ABI_mipsabi.pdf&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=RAkf3Vl5MWzirfmkwopuyQjQ-5uEE95ctSfXOidHyHs&e=</a> p.4-19<br>
- if (Config->EMachine == EM_MIPS)<br>
- In.MipsGot->addEntry(*Sec.File, Sym, Addend, Expr);<br>
+ if (config->emachine == EM_MIPS)<br>
+ in.mipsGot->addEntry(*sec.file, sym, addend, expr);<br>
return;<br>
}<br>
}<br>
<br>
- if (!CanWrite && (Config->Pic && !isRelExpr(Expr))) {<br>
+ if (!canWrite && (config->isPic && !isRelExpr(expr))) {<br>
error(<br>
- "can't create dynamic relocation " + toString(Type) + " against " +<br>
- (Sym.getName().empty() ? "local symbol" : "symbol: " + toString(Sym)) +<br>
+ "can't create dynamic relocation " + toString(type) + " against " +<br>
+ (sym.getName().empty() ? "local symbol" : "symbol: " + toString(sym)) +<br>
" in readonly segment; recompile object files with -fPIC "<br>
"or pass '-Wl,-z,notext' to allow text relocations in the output" +<br>
- getLocation(Sec, Sym, Offset));<br>
+ getLocation(sec, sym, offset));<br>
return;<br>
}<br>
<br>
@@ -1013,40 +1013,40 @@ static void processRelocAux(InputSection<br>
// Among R_ABS relocatoin types, SymbolicRel has the same size as the word<br>
// size. Others have fewer bits and may cause runtime overflow in -pie/-shared<br>
// mode. Disallow them.<br>
- if (Config->Shared ||<br>
- (Config->Pie && Expr == R_ABS && Type != Target->SymbolicRel)) {<br>
+ if (config->shared ||<br>
+ (config->pie && expr == R_ABS && type != target->symbolicRel)) {<br>
errorOrWarn(<br>
- "relocation " + toString(Type) + " cannot be used against " +<br>
- (Sym.getName().empty() ? "local symbol" : "symbol " + toString(Sym)) +<br>
- "; recompile with -fPIC" + getLocation(Sec, Sym, Offset));<br>
+ "relocation " + toString(type) + " cannot be used against " +<br>
+ (sym.getName().empty() ? "local symbol" : "symbol " + toString(sym)) +<br>
+ "; recompile with -fPIC" + getLocation(sec, sym, offset));<br>
return;<br>
}<br>
<br>
// If the symbol is undefined we already reported any relevant errors.<br>
- if (Sym.isUndefined())<br>
+ if (sym.isUndefined())<br>
return;<br>
<br>
- if (!canDefineSymbolInExecutable(Sym)) {<br>
- error("cannot preempt symbol: " + toString(Sym) +<br>
- getLocation(Sec, Sym, Offset));<br>
+ if (!canDefineSymbolInExecutable(sym)) {<br>
+ error("cannot preempt symbol: " + toString(sym) +<br>
+ getLocation(sec, sym, offset));<br>
return;<br>
}<br>
<br>
- if (Sym.isObject()) {<br>
+ if (sym.isObject()) {<br>
// Produce a copy relocation.<br>
- if (auto *SS = dyn_cast<SharedSymbol>(&Sym)) {<br>
- if (!Config->ZCopyreloc)<br>
- error("unresolvable relocation " + toString(Type) +<br>
- " against symbol '" + toString(*SS) +<br>
+ if (auto *ss = dyn_cast<SharedSymbol>(&sym)) {<br>
+ if (!config->zCopyreloc)<br>
+ error("unresolvable relocation " + toString(type) +<br>
+ " against symbol '" + toString(*ss) +<br>
"'; recompile with -fPIC or remove '-z nocopyreloc'" +<br>
- getLocation(Sec, Sym, Offset));<br>
- addCopyRelSymbol<ELFT>(*SS);<br>
+ getLocation(sec, sym, offset));<br>
+ addCopyRelSymbol<ELFT>(*ss);<br>
}<br>
- Sec.Relocations.push_back({Expr, Type, Offset, Addend, &Sym});<br>
+ sec.relocations.push_back({expr, type, offset, addend, &sym});<br>
return;<br>
}<br>
<br>
- if (Sym.isFunc()) {<br>
+ if (sym.isFunc()) {<br>
// This handles a non PIC program call to function in a shared library. In<br>
// an ideal world, we could just report an error saying the relocation can<br>
// overflow at runtime. In the real world with glibc, crt1.o has a<br>
@@ -1074,65 +1074,65 @@ static void processRelocAux(InputSection<br>
// compiled without -fPIE/-fPIC and doesn't maintain ebx.<br>
// * If a library definition gets preempted to the executable, it will have<br>
// the wrong ebx value.<br>
- if (Config->Pie && Config->EMachine == EM_386)<br>
- errorOrWarn("symbol '" + toString(Sym) +<br>
+ if (config->pie && config->emachine == EM_386)<br>
+ errorOrWarn("symbol '" + toString(sym) +<br>
"' cannot be preempted; recompile with -fPIE" +<br>
- getLocation(Sec, Sym, Offset));<br>
- if (!Sym.isInPlt())<br>
- addPltEntry<ELFT>(In.Plt, In.GotPlt, In.RelaPlt, Target->PltRel, Sym);<br>
- if (!Sym.isDefined())<br>
+ getLocation(sec, sym, offset));<br>
+ if (!sym.isInPlt())<br>
+ addPltEntry<ELFT>(in.plt, in.gotPlt, in.relaPlt, target->pltRel, sym);<br>
+ if (!sym.isDefined())<br>
replaceWithDefined(<br>
- Sym, In.Plt,<br>
- Target->PltHeaderSize + Target->PltEntrySize * Sym.PltIndex, 0);<br>
- Sym.NeedsPltAddr = true;<br>
- Sec.Relocations.push_back({Expr, Type, Offset, Addend, &Sym});<br>
+ sym, in.plt,<br>
+ target->pltHeaderSize + target->pltEntrySize * sym.pltIndex, 0);<br>
+ sym.needsPltAddr = true;<br>
+ sec.relocations.push_back({expr, type, offset, addend, &sym});<br>
return;<br>
}<br>
<br>
- errorOrWarn("symbol '" + toString(Sym) + "' has no type" +<br>
- getLocation(Sec, Sym, Offset));<br>
+ errorOrWarn("symbol '" + toString(sym) + "' has no type" +<br>
+ getLocation(sec, sym, offset));<br>
}<br>
<br>
struct IRelativeReloc {<br>
- RelType Type;<br>
- InputSectionBase *Sec;<br>
- uint64_t Offset;<br>
- Symbol *Sym;<br>
+ RelType type;<br>
+ InputSectionBase *sec;<br>
+ uint64_t offset;<br>
+ Symbol *sym;<br>
};<br>
<br>
-static std::vector<IRelativeReloc> IRelativeRelocs;<br>
+static std::vector<IRelativeReloc> iRelativeRelocs;<br>
<br>
template <class ELFT, class RelTy><br>
-static void scanReloc(InputSectionBase &Sec, OffsetGetter &GetOffset, RelTy *&I,<br>
- RelTy *End) {<br>
- const RelTy &Rel = *I;<br>
- uint32_t SymIndex = Rel.getSymbol(Config->IsMips64EL);<br>
- Symbol &Sym = Sec.getFile<ELFT>()->getSymbol(SymIndex);<br>
- RelType Type;<br>
+static void scanReloc(InputSectionBase &sec, OffsetGetter &getOffset, RelTy *&i,<br>
+ RelTy *end) {<br>
+ const RelTy &rel = *i;<br>
+ uint32_t symIndex = rel.getSymbol(config->isMips64EL);<br>
+ Symbol &sym = sec.getFile<ELFT>()->getSymbol(symIndex);<br>
+ RelType type;<br>
<br>
// Deal with MIPS oddity.<br>
- if (Config->MipsN32Abi) {<br>
- Type = getMipsN32RelType(I, End);<br>
+ if (config->mipsN32Abi) {<br>
+ type = getMipsN32RelType(i, end);<br>
} else {<br>
- Type = Rel.getType(Config->IsMips64EL);<br>
- ++I;<br>
+ type = rel.getType(config->isMips64EL);<br>
+ ++i;<br>
}<br>
<br>
// Get an offset in an output section this relocation is applied to.<br>
- uint64_t Offset = GetOffset.get(Rel.r_offset);<br>
- if (Offset == uint64_t(-1))<br>
+ uint64_t offset = getOffset.get(rel.r_offset);<br>
+ if (offset == uint64_t(-1))<br>
return;<br>
<br>
// Error if the target symbol is undefined. Symbol index 0 may be used by<br>
// marker relocations, e.g. R_*_NONE and R_ARM_V4BX. Don't error on them.<br>
- if (SymIndex != 0 && maybeReportUndefined<ELFT>(Sym, Sec, Rel.r_offset))<br>
+ if (symIndex != 0 && maybeReportUndefined<ELFT>(sym, sec, rel.r_offset))<br>
return;<br>
<br>
- const uint8_t *RelocatedAddr = Sec.data().begin() + Rel.r_offset;<br>
- RelExpr Expr = Target->getRelExpr(Type, Sym, RelocatedAddr);<br>
+ const uint8_t *relocatedAddr = sec.data().begin() + rel.r_offset;<br>
+ RelExpr expr = target->getRelExpr(type, sym, relocatedAddr);<br>
<br>
// Ignore "hint" relocations because they are only markers for relaxation.<br>
- if (oneof<R_HINT, R_NONE>(Expr))<br>
+ if (oneof<R_HINT, R_NONE>(expr))<br>
return;<br>
<br>
// We can separate the small code model relocations into 2 categories:<br>
@@ -1143,21 +1143,21 @@ static void scanReloc(InputSectionBase &<br>
// got-based small code model relocs. The .toc sections get placed after the<br>
// end of the linker allocated .got section and we do sort those so sections<br>
// addressed with small code model relocations come first.<br>
- if (Config->EMachine == EM_PPC64 && isPPC64SmallCodeModelTocReloc(Type))<br>
- Sec.File->PPC64SmallCodeModelTocRelocs = true;<br>
+ if (config->emachine == EM_PPC64 && isPPC64SmallCodeModelTocReloc(type))<br>
+ sec.file->ppc64SmallCodeModelTocRelocs = true;<br>
<br>
- if (Sym.isGnuIFunc() && !Config->ZText && Config->WarnIfuncTextrel) {<br>
+ if (sym.isGnuIFunc() && !config->zText && config->warnIfuncTextrel) {<br>
warn("using ifunc symbols when text relocations are allowed may produce "<br>
"a binary that will segfault, if the object file is linked with "<br>
"old version of glibc (glibc 2.28 and earlier). If this applies to "<br>
"you, consider recompiling the object files without -fPIC and "<br>
"without -Wl,-z,notext option. Use -no-warn-ifunc-textrel to "<br>
"turn off this warning." +<br>
- getLocation(Sec, Sym, Offset));<br>
+ getLocation(sec, sym, offset));<br>
}<br>
<br>
// Read an addend.<br>
- int64_t Addend = computeAddend<ELFT>(Rel, End, Sec, Expr, Sym.isLocal());<br>
+ int64_t addend = computeAddend<ELFT>(rel, end, sec, expr, sym.isLocal());<br>
<br>
// Relax relocations.<br>
//<br>
@@ -1167,15 +1167,15 @@ static void scanReloc(InputSectionBase &<br>
// be resolved within the executable will actually be resolved that way at<br>
// runtime, because the main exectuable is always at the beginning of a search<br>
// list. We can leverage that fact.<br>
- if (!Sym.IsPreemptible && (!Sym.isGnuIFunc() || Config->ZIfuncNoplt)) {<br>
- if (Expr == R_GOT_PC && !isAbsoluteValue(Sym)) {<br>
- Expr = Target->adjustRelaxExpr(Type, RelocatedAddr, Expr);<br>
+ if (!sym.isPreemptible && (!sym.isGnuIFunc() || config->zIfuncNoplt)) {<br>
+ if (expr == R_GOT_PC && !isAbsoluteValue(sym)) {<br>
+ expr = target->adjustRelaxExpr(type, relocatedAddr, expr);<br>
} else {<br>
// Addend of R_PPC_PLTREL24 is used to choose call stub type. It should be<br>
// ignored if optimized to R_PC.<br>
- if (Config->EMachine == EM_PPC && Expr == R_PPC32_PLTREL)<br>
- Addend = 0;<br>
- Expr = fromPlt(Expr);<br>
+ if (config->emachine == EM_PPC && expr == R_PPC32_PLTREL)<br>
+ addend = 0;<br>
+ expr = fromPlt(expr);<br>
}<br>
}<br>
<br>
@@ -1183,39 +1183,39 @@ static void scanReloc(InputSectionBase &<br>
// uses their addresses, we need GOT or GOTPLT to be created.<br>
//<br>
// The 4 types that relative GOTPLT are all x86 and x86-64 specific.<br>
- if (oneof<R_GOTPLTONLY_PC, R_GOTPLTREL, R_GOTPLT, R_TLSGD_GOTPLT>(Expr)) {<br>
- In.GotPlt->HasGotPltOffRel = true;<br>
+ if (oneof<R_GOTPLTONLY_PC, R_GOTPLTREL, R_GOTPLT, R_TLSGD_GOTPLT>(expr)) {<br>
+ in.gotPlt->hasGotPltOffRel = true;<br>
} else if (oneof<R_GOTONLY_PC, R_GOTREL, R_PPC64_TOCBASE, R_PPC64_RELAX_TOC>(<br>
- Expr)) {<br>
- In.Got->HasGotOffRel = true;<br>
+ expr)) {<br>
+ in.got->hasGotOffRel = true;<br>
}<br>
<br>
// Process some TLS relocations, including relaxing TLS relocations.<br>
// Note that this function does not handle all TLS relocations.<br>
- if (unsigned Processed =<br>
- handleTlsRelocation<ELFT>(Type, Sym, Sec, Offset, Addend, Expr)) {<br>
- I += (Processed - 1);<br>
+ if (unsigned processed =<br>
+ handleTlsRelocation<ELFT>(type, sym, sec, offset, addend, expr)) {<br>
+ i += (processed - 1);<br>
return;<br>
}<br>
<br>
// We were asked not to generate PLT entries for ifuncs. Instead, pass the<br>
// direct relocation on through.<br>
- if (Sym.isGnuIFunc() && Config->ZIfuncNoplt) {<br>
- Sym.ExportDynamic = true;<br>
- Main->RelaDyn->addReloc(Type, &Sec, Offset, &Sym, Addend, R_ADDEND, Type);<br>
+ if (sym.isGnuIFunc() && config->zIfuncNoplt) {<br>
+ sym.exportDynamic = true;<br>
+ mainPart->relaDyn->addReloc(type, &sec, offset, &sym, addend, R_ADDEND, type);<br>
return;<br>
}<br>
<br>
// Non-preemptible ifuncs require special handling. First, handle the usual<br>
// case where the symbol isn't one of these.<br>
- if (!Sym.isGnuIFunc() || Sym.IsPreemptible) {<br>
+ if (!sym.isGnuIFunc() || sym.isPreemptible) {<br>
// If a relocation needs PLT, we create PLT and GOTPLT slots for the symbol.<br>
- if (needsPlt(Expr) && !Sym.isInPlt())<br>
- addPltEntry<ELFT>(In.Plt, In.GotPlt, In.RelaPlt, Target->PltRel, Sym);<br>
+ if (needsPlt(expr) && !sym.isInPlt())<br>
+ addPltEntry<ELFT>(in.plt, in.gotPlt, in.relaPlt, target->pltRel, sym);<br>
<br>
// Create a GOT slot if a relocation needs GOT.<br>
- if (needsGot(Expr)) {<br>
- if (Config->EMachine == EM_MIPS) {<br>
+ if (needsGot(expr)) {<br>
+ if (config->emachine == EM_MIPS) {<br>
// MIPS ABI has special rules to process GOT entries and doesn't<br>
// require relocation entries for them. A special case is TLS<br>
// relocations. In that case dynamic loader applies dynamic<br>
@@ -1223,9 +1223,9 @@ static void scanReloc(InputSectionBase &<br>
// See "Global Offset Table" in Chapter 5 in the following document<br>
// for detailed description:<br>
// <a href="https://urldefense.proofpoint.com/v2/url?u=ftp-3A__www.linux-2Dmips.org_pub_linux_mips_doc_ABI_mipsabi.pdf&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=RAkf3Vl5MWzirfmkwopuyQjQ-5uEE95ctSfXOidHyHs&e=" rel="noreferrer" target="_blank">https://urldefense.proofpoint.com/v2/url?u=ftp-3A__www.linux-2Dmips.org_pub_linux_mips_doc_ABI_mipsabi.pdf&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=RAkf3Vl5MWzirfmkwopuyQjQ-5uEE95ctSfXOidHyHs&e=</a> <br>
- In.MipsGot->addEntry(*Sec.File, Sym, Addend, Expr);<br>
- } else if (!Sym.isInGot()) {<br>
- addGotEntry(Sym);<br>
+ in.mipsGot->addEntry(*sec.file, sym, addend, expr);<br>
+ } else if (!sym.isInGot()) {<br>
+ addGotEntry(sym);<br>
}<br>
}<br>
} else {<br>
@@ -1275,9 +1275,9 @@ static void scanReloc(InputSectionBase &<br>
// the exact same way as a GOT entry, so we can avoid needing to make the<br>
// PLT entry canonical by translating such relocations into IRELATIVE<br>
// relocations in the RelaIplt.<br>
- if (!Sym.isInPlt()) {<br>
+ if (!sym.isInPlt()) {<br>
// Create PLT and GOTPLT slots for the symbol.<br>
- Sym.IsInIplt = true;<br>
+ sym.isInIplt = true;<br>
<br>
// Create a copy of the symbol to use as the target of the IRELATIVE<br>
// relocation in the IgotPlt. This is in case we make the PLT canonical<br>
@@ -1286,12 +1286,12 @@ static void scanReloc(InputSectionBase &<br>
// FIXME: Creating a copy of the symbol here is a bit of a hack. All<br>
// that's really needed to create the IRELATIVE is the section and value,<br>
// so ideally we should just need to copy those.<br>
- auto *DirectSym = make<Defined>(cast<Defined>(Sym));<br>
- addPltEntry<ELFT>(In.Iplt, In.IgotPlt, In.RelaIplt, Target->IRelativeRel,<br>
- *DirectSym);<br>
- Sym.PltIndex = DirectSym->PltIndex;<br>
+ auto *directSym = make<Defined>(cast<Defined>(sym));<br>
+ addPltEntry<ELFT>(in.iplt, in.igotPlt, in.relaIplt, target->iRelativeRel,<br>
+ *directSym);<br>
+ sym.pltIndex = directSym->pltIndex;<br>
}<br>
- if (Expr == R_ABS && Addend == 0 && (Sec.Flags & SHF_WRITE)) {<br>
+ if (expr == R_ABS && addend == 0 && (sec.flags & SHF_WRITE)) {<br>
// We might be able to represent this as an IRELATIVE. But we don't know<br>
// yet whether some later relocation will make the symbol point to a<br>
// canonical PLT, which would make this either a dynamic RELATIVE (PIC) or<br>
@@ -1299,32 +1299,32 @@ static void scanReloc(InputSectionBase &<br>
// required to process the relocation, and after scanRelocs() has been<br>
// called on all relocations, the relocation is resolved by<br>
// addIRelativeRelocs().<br>
- IRelativeRelocs.push_back({Type, &Sec, Offset, &Sym});<br>
+ iRelativeRelocs.push_back({type, &sec, offset, &sym});<br>
return;<br>
}<br>
- if (needsGot(Expr)) {<br>
+ if (needsGot(expr)) {<br>
// Redirect GOT accesses to point to the Igot.<br>
//<br>
// This field is also used to keep track of whether we ever needed a GOT<br>
// entry. If we did and we make the PLT canonical later, we'll need to<br>
// create a GOT entry pointing to the PLT entry for Sym.<br>
- Sym.GotInIgot = true;<br>
- } else if (!needsPlt(Expr)) {<br>
+ sym.gotInIgot = true;<br>
+ } else if (!needsPlt(expr)) {<br>
// Make the ifunc's PLT entry canonical by changing the value of its<br>
// symbol to redirect all references to point to it.<br>
- unsigned EntryOffset = Sym.PltIndex * Target->PltEntrySize;<br>
- if (Config->ZRetpolineplt)<br>
- EntryOffset += Target->PltHeaderSize;<br>
-<br>
- auto &D = cast<Defined>(Sym);<br>
- D.Section = In.Iplt;<br>
- D.Value = EntryOffset;<br>
- D.Size = 0;<br>
+ unsigned entryOffset = sym.pltIndex * target->pltEntrySize;<br>
+ if (config->zRetpolineplt)<br>
+ entryOffset += target->pltHeaderSize;<br>
+<br>
+ auto &d = cast<Defined>(sym);<br>
+ d.section = in.iplt;<br>
+ d.value = entryOffset;<br>
+ d.size = 0;<br>
// It's important to set the symbol type here so that dynamic loaders<br>
// don't try to call the PLT as if it were an ifunc resolver.<br>
- D.Type = STT_FUNC;<br>
+ d.type = STT_FUNC;<br>
<br>
- if (Sym.GotInIgot) {<br>
+ if (sym.gotInIgot) {<br>
// We previously encountered a GOT generating reference that we<br>
// redirected to the Igot. Now that the PLT entry is canonical we must<br>
// clear the redirection to the Igot and add a GOT entry. As we've<br>
@@ -1333,74 +1333,74 @@ static void scanReloc(InputSectionBase &<br>
//<br>
// We don't need to worry about creating a MIPS GOT here because ifuncs<br>
// aren't a thing on MIPS.<br>
- Sym.GotInIgot = false;<br>
- addGotEntry(Sym);<br>
+ sym.gotInIgot = false;<br>
+ addGotEntry(sym);<br>
}<br>
}<br>
}<br>
<br>
- processRelocAux<ELFT>(Sec, Expr, Type, Offset, Sym, Rel, Addend);<br>
+ processRelocAux<ELFT>(sec, expr, type, offset, sym, rel, addend);<br>
}<br>
<br>
template <class ELFT, class RelTy><br>
-static void scanRelocs(InputSectionBase &Sec, ArrayRef<RelTy> Rels) {<br>
- OffsetGetter GetOffset(Sec);<br>
+static void scanRelocs(InputSectionBase &sec, ArrayRef<RelTy> rels) {<br>
+ OffsetGetter getOffset(sec);<br>
<br>
// Not all relocations end up in Sec.Relocations, but a lot do.<br>
- Sec.Relocations.reserve(Rels.size());<br>
+ sec.relocations.reserve(rels.size());<br>
<br>
- for (auto I = Rels.begin(), End = Rels.end(); I != End;)<br>
- scanReloc<ELFT>(Sec, GetOffset, I, End);<br>
+ for (auto i = rels.begin(), end = rels.end(); i != end;)<br>
+ scanReloc<ELFT>(sec, getOffset, i, end);<br>
<br>
// Sort relocations by offset for more efficient searching for<br>
// R_RISCV_PCREL_HI20 and R_PPC64_ADDR64.<br>
- if (Config->EMachine == EM_RISCV ||<br>
- (Config->EMachine == EM_PPC64 && Sec.Name == ".toc"))<br>
- llvm::stable_sort(Sec.Relocations,<br>
- [](const Relocation &LHS, const Relocation &RHS) {<br>
- return LHS.Offset < RHS.Offset;<br>
+ if (config->emachine == EM_RISCV ||<br>
+ (config->emachine == EM_PPC64 && <a href="http://sec.name" rel="noreferrer" target="_blank">sec.name</a> == ".toc"))<br>
+ llvm::stable_sort(sec.relocations,<br>
+ [](const Relocation &lhs, const Relocation &rhs) {<br>
+ return lhs.offset < rhs.offset;<br>
});<br>
}<br>
<br>
-template <class ELFT> void elf::scanRelocations(InputSectionBase &S) {<br>
- if (S.AreRelocsRela)<br>
- scanRelocs<ELFT>(S, S.relas<ELFT>());<br>
+template <class ELFT> void elf::scanRelocations(InputSectionBase &s) {<br>
+ if (s.areRelocsRela)<br>
+ scanRelocs<ELFT>(s, s.relas<ELFT>());<br>
else<br>
- scanRelocs<ELFT>(S, S.rels<ELFT>());<br>
+ scanRelocs<ELFT>(s, s.rels<ELFT>());<br>
}<br>
<br>
// Figure out which representation to use for any absolute relocs to<br>
// non-preemptible ifuncs that we visited during scanRelocs().<br>
void elf::addIRelativeRelocs() {<br>
- for (IRelativeReloc &R : IRelativeRelocs) {<br>
- if (R.Sym->Type == STT_GNU_IFUNC)<br>
- In.RelaIplt->addReloc(<br>
- {Target->IRelativeRel, R.Sec, R.Offset, true, R.Sym, 0});<br>
- else if (Config->Pic)<br>
- addRelativeReloc(R.Sec, R.Offset, R.Sym, 0, R_ABS, R.Type);<br>
+ for (IRelativeReloc &r : iRelativeRelocs) {<br>
+ if (r.sym->type == STT_GNU_IFUNC)<br>
+ in.relaIplt->addReloc(<br>
+ {target->iRelativeRel, r.sec, r.offset, true, r.sym, 0});<br>
+ else if (config->isPic)<br>
+ addRelativeReloc(r.sec, r.offset, r.sym, 0, R_ABS, r.type);<br>
else<br>
- R.Sec->Relocations.push_back({R_ABS, R.Type, R.Offset, 0, R.Sym});<br>
+ r.sec->relocations.push_back({R_ABS, r.type, r.offset, 0, r.sym});<br>
}<br>
- IRelativeRelocs.clear();<br>
+ iRelativeRelocs.clear();<br>
}<br>
<br>
-static bool mergeCmp(const InputSection *A, const InputSection *B) {<br>
+static bool mergeCmp(const InputSection *a, const InputSection *b) {<br>
// std::merge requires a strict weak ordering.<br>
- if (A->OutSecOff < B->OutSecOff)<br>
+ if (a->outSecOff < b->outSecOff)<br>
return true;<br>
<br>
- if (A->OutSecOff == B->OutSecOff) {<br>
- auto *TA = dyn_cast<ThunkSection>(A);<br>
- auto *TB = dyn_cast<ThunkSection>(B);<br>
+ if (a->outSecOff == b->outSecOff) {<br>
+ auto *ta = dyn_cast<ThunkSection>(a);<br>
+ auto *tb = dyn_cast<ThunkSection>(b);<br>
<br>
// Check if Thunk is immediately before any specific Target<br>
// InputSection for example Mips LA25 Thunks.<br>
- if (TA && TA->getTargetInputSection() == B)<br>
+ if (ta && ta->getTargetInputSection() == b)<br>
return true;<br>
<br>
// Place Thunk Sections without specific targets before<br>
// non-Thunk Sections.<br>
- if (TA && !TB && !TA->getTargetInputSection())<br>
+ if (ta && !tb && !ta->getTargetInputSection())<br>
return true;<br>
}<br>
<br>
@@ -1410,14 +1410,14 @@ static bool mergeCmp(const InputSection<br>
// Call Fn on every executable InputSection accessed via the linker script<br>
// InputSectionDescription::Sections.<br>
static void forEachInputSectionDescription(<br>
- ArrayRef<OutputSection *> OutputSections,<br>
- llvm::function_ref<void(OutputSection *, InputSectionDescription *)> Fn) {<br>
- for (OutputSection *OS : OutputSections) {<br>
- if (!(OS->Flags & SHF_ALLOC) || !(OS->Flags & SHF_EXECINSTR))<br>
+ ArrayRef<OutputSection *> outputSections,<br>
+ llvm::function_ref<void(OutputSection *, InputSectionDescription *)> fn) {<br>
+ for (OutputSection *os : outputSections) {<br>
+ if (!(os->flags & SHF_ALLOC) || !(os->flags & SHF_EXECINSTR))<br>
continue;<br>
- for (BaseCommand *BC : OS->SectionCommands)<br>
- if (auto *ISD = dyn_cast<InputSectionDescription>(BC))<br>
- Fn(OS, ISD);<br>
+ for (BaseCommand *bc : os->sectionCommands)<br>
+ if (auto *isd = dyn_cast<InputSectionDescription>(bc))<br>
+ fn(os, isd);<br>
}<br>
}<br>
<br>
@@ -1512,54 +1512,54 @@ static void forEachInputSectionDescripti<br>
// in the Sections vector, and recalculate the InputSection output section<br>
// offsets.<br>
// This may invalidate any output section offsets stored outside of InputSection<br>
-void ThunkCreator::mergeThunks(ArrayRef<OutputSection *> OutputSections) {<br>
+void ThunkCreator::mergeThunks(ArrayRef<OutputSection *> outputSections) {<br>
forEachInputSectionDescription(<br>
- OutputSections, [&](OutputSection *OS, InputSectionDescription *ISD) {<br>
- if (ISD->ThunkSections.empty())<br>
+ outputSections, [&](OutputSection *os, InputSectionDescription *isd) {<br>
+ if (isd->thunkSections.empty())<br>
return;<br>
<br>
// Remove any zero sized precreated Thunks.<br>
- llvm::erase_if(ISD->ThunkSections,<br>
- [](const std::pair<ThunkSection *, uint32_t> &TS) {<br>
- return TS.first->getSize() == 0;<br>
+ llvm::erase_if(isd->thunkSections,<br>
+ [](const std::pair<ThunkSection *, uint32_t> &ts) {<br>
+ return ts.first->getSize() == 0;<br>
});<br>
<br>
// ISD->ThunkSections contains all created ThunkSections, including<br>
// those inserted in previous passes. Extract the Thunks created this<br>
// pass and order them in ascending OutSecOff.<br>
- std::vector<ThunkSection *> NewThunks;<br>
- for (const std::pair<ThunkSection *, uint32_t> TS : ISD->ThunkSections)<br>
- if (TS.second == Pass)<br>
- NewThunks.push_back(TS.first);<br>
- llvm::stable_sort(NewThunks,<br>
- [](const ThunkSection *A, const ThunkSection *B) {<br>
- return A->OutSecOff < B->OutSecOff;<br>
+ std::vector<ThunkSection *> newThunks;<br>
+ for (const std::pair<ThunkSection *, uint32_t> ts : isd->thunkSections)<br>
+ if (ts.second == pass)<br>
+ newThunks.push_back(ts.first);<br>
+ llvm::stable_sort(newThunks,<br>
+ [](const ThunkSection *a, const ThunkSection *b) {<br>
+ return a->outSecOff < b->outSecOff;<br>
});<br>
<br>
// Merge sorted vectors of Thunks and InputSections by OutSecOff<br>
- std::vector<InputSection *> Tmp;<br>
- Tmp.reserve(ISD->Sections.size() + NewThunks.size());<br>
+ std::vector<InputSection *> tmp;<br>
+ tmp.reserve(isd->sections.size() + newThunks.size());<br>
<br>
- std::merge(ISD->Sections.begin(), ISD->Sections.end(),<br>
- NewThunks.begin(), NewThunks.end(), std::back_inserter(Tmp),<br>
+ std::merge(isd->sections.begin(), isd->sections.end(),<br>
+ newThunks.begin(), newThunks.end(), std::back_inserter(tmp),<br>
mergeCmp);<br>
<br>
- ISD->Sections = std::move(Tmp);<br>
+ isd->sections = std::move(tmp);<br>
});<br>
}<br>
<br>
// Find or create a ThunkSection within the InputSectionDescription (ISD) that<br>
// is in range of Src. An ISD maps to a range of InputSections described by a<br>
// linker script section pattern such as { .text .text.* }.<br>
-ThunkSection *ThunkCreator::getISDThunkSec(OutputSection *OS, InputSection *IS,<br>
- InputSectionDescription *ISD,<br>
- uint32_t Type, uint64_t Src) {<br>
- for (std::pair<ThunkSection *, uint32_t> TP : ISD->ThunkSections) {<br>
- ThunkSection *TS = TP.first;<br>
- uint64_t TSBase = OS->Addr + TS->OutSecOff;<br>
- uint64_t TSLimit = TSBase + TS->getSize();<br>
- if (Target->inBranchRange(Type, Src, (Src > TSLimit) ? TSBase : TSLimit))<br>
- return TS;<br>
+ThunkSection *ThunkCreator::getISDThunkSec(OutputSection *os, InputSection *isec,<br>
+ InputSectionDescription *isd,<br>
+ uint32_t type, uint64_t src) {<br>
+ for (std::pair<ThunkSection *, uint32_t> tp : isd->thunkSections) {<br>
+ ThunkSection *ts = tp.first;<br>
+ uint64_t tsBase = os->addr + ts->outSecOff;<br>
+ uint64_t tsLimit = tsBase + ts->getSize();<br>
+ if (target->inBranchRange(type, src, (src > tsLimit) ? tsBase : tsLimit))<br>
+ return ts;<br>
}<br>
<br>
// No suitable ThunkSection exists. This can happen when there is a branch<br>
@@ -1567,40 +1567,40 @@ ThunkSection *ThunkCreator::getISDThunkS<br>
// many Thunks. Create a new ThunkSection as close to the InputSection as<br>
// possible. Error if InputSection is so large we cannot place ThunkSection<br>
// anywhere in Range.<br>
- uint64_t ThunkSecOff = IS->OutSecOff;<br>
- if (!Target->inBranchRange(Type, Src, OS->Addr + ThunkSecOff)) {<br>
- ThunkSecOff = IS->OutSecOff + IS->getSize();<br>
- if (!Target->inBranchRange(Type, Src, OS->Addr + ThunkSecOff))<br>
+ uint64_t thunkSecOff = isec->outSecOff;<br>
+ if (!target->inBranchRange(type, src, os->addr + thunkSecOff)) {<br>
+ thunkSecOff = isec->outSecOff + isec->getSize();<br>
+ if (!target->inBranchRange(type, src, os->addr + thunkSecOff))<br>
fatal("InputSection too large for range extension thunk " +<br>
- IS->getObjMsg(Src - (OS->Addr + IS->OutSecOff)));<br>
+ isec->getObjMsg(src - (os->addr + isec->outSecOff)));<br>
}<br>
- return addThunkSection(OS, ISD, ThunkSecOff);<br>
+ return addThunkSection(os, isd, thunkSecOff);<br>
}<br>
<br>
// Add a Thunk that needs to be placed in a ThunkSection that immediately<br>
// precedes its Target.<br>
-ThunkSection *ThunkCreator::getISThunkSec(InputSection *IS) {<br>
- ThunkSection *TS = ThunkedSections.lookup(IS);<br>
- if (TS)<br>
- return TS;<br>
+ThunkSection *ThunkCreator::getISThunkSec(InputSection *isec) {<br>
+ ThunkSection *ts = thunkedSections.lookup(isec);<br>
+ if (ts)<br>
+ return ts;<br>
<br>
// Find InputSectionRange within Target Output Section (TOS) that the<br>
// InputSection (IS) that we need to precede is in.<br>
- OutputSection *TOS = IS->getParent();<br>
- for (BaseCommand *BC : TOS->SectionCommands) {<br>
- auto *ISD = dyn_cast<InputSectionDescription>(BC);<br>
- if (!ISD || ISD->Sections.empty())<br>
+ OutputSection *tos = isec->getParent();<br>
+ for (BaseCommand *bc : tos->sectionCommands) {<br>
+ auto *isd = dyn_cast<InputSectionDescription>(bc);<br>
+ if (!isd || isd->sections.empty())<br>
continue;<br>
<br>
- InputSection *First = ISD->Sections.front();<br>
- InputSection *Last = ISD->Sections.back();<br>
+ InputSection *first = isd->sections.front();<br>
+ InputSection *last = isd->sections.back();<br>
<br>
- if (IS->OutSecOff < First->OutSecOff || Last->OutSecOff < IS->OutSecOff)<br>
+ if (isec->outSecOff < first->outSecOff || last->outSecOff < isec->outSecOff)<br>
continue;<br>
<br>
- TS = addThunkSection(TOS, ISD, IS->OutSecOff);<br>
- ThunkedSections[IS] = TS;<br>
- return TS;<br>
+ ts = addThunkSection(tos, isd, isec->outSecOff);<br>
+ thunkedSections[isec] = ts;<br>
+ return ts;<br>
}<br>
<br>
return nullptr;<br>
@@ -1623,93 +1623,93 @@ ThunkSection *ThunkCreator::getISThunkSe<br>
// distance from a thunk to its target will be sufficiently small to<br>
// allow for the creation of a short thunk.<br>
void ThunkCreator::createInitialThunkSections(<br>
- ArrayRef<OutputSection *> OutputSections) {<br>
- uint32_t ThunkSectionSpacing = Target->getThunkSectionSpacing();<br>
+ ArrayRef<OutputSection *> outputSections) {<br>
+ uint32_t thunkSectionSpacing = target->getThunkSectionSpacing();<br>
<br>
forEachInputSectionDescription(<br>
- OutputSections, [&](OutputSection *OS, InputSectionDescription *ISD) {<br>
- if (ISD->Sections.empty())<br>
+ outputSections, [&](OutputSection *os, InputSectionDescription *isd) {<br>
+ if (isd->sections.empty())<br>
return;<br>
<br>
- uint32_t ISDBegin = ISD->Sections.front()->OutSecOff;<br>
- uint32_t ISDEnd =<br>
- ISD->Sections.back()->OutSecOff + ISD->Sections.back()->getSize();<br>
- uint32_t LastThunkLowerBound = -1;<br>
- if (ISDEnd - ISDBegin > ThunkSectionSpacing * 2)<br>
- LastThunkLowerBound = ISDEnd - ThunkSectionSpacing;<br>
-<br>
- uint32_t ISLimit;<br>
- uint32_t PrevISLimit = ISDBegin;<br>
- uint32_t ThunkUpperBound = ISDBegin + ThunkSectionSpacing;<br>
-<br>
- for (const InputSection *IS : ISD->Sections) {<br>
- ISLimit = IS->OutSecOff + IS->getSize();<br>
- if (ISLimit > ThunkUpperBound) {<br>
- addThunkSection(OS, ISD, PrevISLimit);<br>
- ThunkUpperBound = PrevISLimit + ThunkSectionSpacing;<br>
+ uint32_t isdBegin = isd->sections.front()->outSecOff;<br>
+ uint32_t isdEnd =<br>
+ isd->sections.back()->outSecOff + isd->sections.back()->getSize();<br>
+ uint32_t lastThunkLowerBound = -1;<br>
+ if (isdEnd - isdBegin > thunkSectionSpacing * 2)<br>
+ lastThunkLowerBound = isdEnd - thunkSectionSpacing;<br>
+<br>
+ uint32_t isecLimit;<br>
+ uint32_t prevISLimit = isdBegin;<br>
+ uint32_t thunkUpperBound = isdBegin + thunkSectionSpacing;<br>
+<br>
+ for (const InputSection *isec : isd->sections) {<br>
+ isecLimit = isec->outSecOff + isec->getSize();<br>
+ if (isecLimit > thunkUpperBound) {<br>
+ addThunkSection(os, isd, prevISLimit);<br>
+ thunkUpperBound = prevISLimit + thunkSectionSpacing;<br>
}<br>
- if (ISLimit > LastThunkLowerBound)<br>
+ if (isecLimit > lastThunkLowerBound)<br>
break;<br>
- PrevISLimit = ISLimit;<br>
+ prevISLimit = isecLimit;<br>
}<br>
- addThunkSection(OS, ISD, ISLimit);<br>
+ addThunkSection(os, isd, isecLimit);<br>
});<br>
}<br>
<br>
-ThunkSection *ThunkCreator::addThunkSection(OutputSection *OS,<br>
- InputSectionDescription *ISD,<br>
- uint64_t Off) {<br>
- auto *TS = make<ThunkSection>(OS, Off);<br>
- TS->Partition = OS->Partition;<br>
- ISD->ThunkSections.push_back({TS, Pass});<br>
- return TS;<br>
+ThunkSection *ThunkCreator::addThunkSection(OutputSection *os,<br>
+ InputSectionDescription *isd,<br>
+ uint64_t off) {<br>
+ auto *ts = make<ThunkSection>(os, off);<br>
+ ts->partition = os->partition;<br>
+ isd->thunkSections.push_back({ts, pass});<br>
+ return ts;<br>
}<br>
<br>
-static bool isThunkSectionCompatible(InputSection *Source,<br>
- SectionBase *Target) {<br>
+static bool isThunkSectionCompatible(InputSection *source,<br>
+ SectionBase *target) {<br>
// We can't reuse thunks in different loadable partitions because they might<br>
// not be loaded. But partition 1 (the main partition) will always be loaded.<br>
- if (Source->Partition != Target->Partition)<br>
- return Target->Partition == 1;<br>
+ if (source->partition != target->partition)<br>
+ return target->partition == 1;<br>
return true;<br>
}<br>
<br>
-std::pair<Thunk *, bool> ThunkCreator::getThunk(InputSection *IS,<br>
- Relocation &Rel, uint64_t Src) {<br>
- std::vector<Thunk *> *ThunkVec = nullptr;<br>
+std::pair<Thunk *, bool> ThunkCreator::getThunk(InputSection *isec,<br>
+ Relocation &rel, uint64_t src) {<br>
+ std::vector<Thunk *> *thunkVec = nullptr;<br>
<br>
// We use (section, offset) pair to find the thunk position if possible so<br>
// that we create only one thunk for aliased symbols or ICFed sections.<br>
- if (auto *D = dyn_cast<Defined>(Rel.Sym))<br>
- if (!D->isInPlt() && D->Section)<br>
- ThunkVec = &ThunkedSymbolsBySection[{D->Section->Repl, D->Value}];<br>
- if (!ThunkVec)<br>
- ThunkVec = &ThunkedSymbols[Rel.Sym];<br>
+ if (auto *d = dyn_cast<Defined>(rel.sym))<br>
+ if (!d->isInPlt() && d->section)<br>
+ thunkVec = &thunkedSymbolsBySection[{d->section->repl, d->value}];<br>
+ if (!thunkVec)<br>
+ thunkVec = &thunkedSymbols[rel.sym];<br>
<br>
// Check existing Thunks for Sym to see if they can be reused<br>
- for (Thunk *T : *ThunkVec)<br>
- if (isThunkSectionCompatible(IS, T->getThunkTargetSym()->Section) &&<br>
- T->isCompatibleWith(*IS, Rel) &&<br>
- Target->inBranchRange(Rel.Type, Src, T->getThunkTargetSym()->getVA()))<br>
- return std::make_pair(T, false);<br>
+ for (Thunk *t : *thunkVec)<br>
+ if (isThunkSectionCompatible(isec, t->getThunkTargetSym()->section) &&<br>
+ t->isCompatibleWith(*isec, rel) &&<br>
+ target->inBranchRange(rel.type, src, t->getThunkTargetSym()->getVA()))<br>
+ return std::make_pair(t, false);<br>
<br>
// No existing compatible Thunk in range, create a new one<br>
- Thunk *T = addThunk(*IS, Rel);<br>
- ThunkVec->push_back(T);<br>
- return std::make_pair(T, true);<br>
+ Thunk *t = addThunk(*isec, rel);<br>
+ thunkVec->push_back(t);<br>
+ return std::make_pair(t, true);<br>
}<br>
<br>
// Return true if the relocation target is an in range Thunk.<br>
// Return false if the relocation is not to a Thunk. If the relocation target<br>
// was originally to a Thunk, but is no longer in range we revert the<br>
// relocation back to its original non-Thunk target.<br>
-bool ThunkCreator::normalizeExistingThunk(Relocation &Rel, uint64_t Src) {<br>
- if (Thunk *T = Thunks.lookup(Rel.Sym)) {<br>
- if (Target->inBranchRange(Rel.Type, Src, Rel.Sym->getVA()))<br>
+bool ThunkCreator::normalizeExistingThunk(Relocation &rel, uint64_t src) {<br>
+ if (Thunk *t = thunks.lookup(rel.sym)) {<br>
+ if (target->inBranchRange(rel.type, src, rel.sym->getVA()))<br>
return true;<br>
- Rel.Sym = &T->Destination;<br>
- if (Rel.Sym->isInPlt())<br>
- Rel.Expr = toPlt(Rel.Expr);<br>
+ rel.sym = &t->destination;<br>
+ if (rel.sym->isInPlt())<br>
+ rel.expr = toPlt(rel.expr);<br>
}<br>
return false;<br>
}<br>
@@ -1739,15 +1739,15 @@ bool ThunkCreator::normalizeExistingThun<br>
// made no changes. If the target requires range extension thunks, currently<br>
// ARM, then any future change in offset between caller and callee risks a<br>
// relocation out of range error.<br>
-bool ThunkCreator::createThunks(ArrayRef<OutputSection *> OutputSections) {<br>
- bool AddressesChanged = false;<br>
+bool ThunkCreator::createThunks(ArrayRef<OutputSection *> outputSections) {<br>
+ bool addressesChanged = false;<br>
<br>
- if (Pass == 0 && Target->getThunkSectionSpacing())<br>
- createInitialThunkSections(OutputSections);<br>
+ if (pass == 0 && target->getThunkSectionSpacing())<br>
+ createInitialThunkSections(outputSections);<br>
<br>
// With Thunk Size much smaller than branch range we expect to<br>
// converge quickly; if we get to 10 something has gone wrong.<br>
- if (Pass == 10)<br>
+ if (pass == 10)<br>
fatal("thunk creation not converged");<br>
<br>
// Create all the Thunks and insert them into synthetic ThunkSections. The<br>
@@ -1756,57 +1756,57 @@ bool ThunkCreator::createThunks(ArrayRef<br>
// ThunkSections as ThunkSections are not always inserted into the same<br>
// InputSectionDescription as the caller.<br>
forEachInputSectionDescription(<br>
- OutputSections, [&](OutputSection *OS, InputSectionDescription *ISD) {<br>
- for (InputSection *IS : ISD->Sections)<br>
- for (Relocation &Rel : IS->Relocations) {<br>
- uint64_t Src = IS->getVA(Rel.Offset);<br>
+ outputSections, [&](OutputSection *os, InputSectionDescription *isd) {<br>
+ for (InputSection *isec : isd->sections)<br>
+ for (Relocation &rel : isec->relocations) {<br>
+ uint64_t src = isec->getVA(rel.offset);<br>
<br>
// If we are a relocation to an existing Thunk, check if it is<br>
// still in range. If not then Rel will be altered to point to its<br>
// original target so another Thunk can be generated.<br>
- if (Pass > 0 && normalizeExistingThunk(Rel, Src))<br>
+ if (pass > 0 && normalizeExistingThunk(rel, src))<br>
continue;<br>
<br>
- if (!Target->needsThunk(Rel.Expr, Rel.Type, IS->File, Src,<br>
- *Rel.Sym))<br>
+ if (!target->needsThunk(rel.expr, rel.type, isec->file, src,<br>
+ *rel.sym))<br>
continue;<br>
<br>
- Thunk *T;<br>
- bool IsNew;<br>
- std::tie(T, IsNew) = getThunk(IS, Rel, Src);<br>
+ Thunk *t;<br>
+ bool isNew;<br>
+ std::tie(t, isNew) = getThunk(isec, rel, src);<br>
<br>
- if (IsNew) {<br>
+ if (isNew) {<br>
// Find or create a ThunkSection for the new Thunk<br>
- ThunkSection *TS;<br>
- if (auto *TIS = T->getTargetInputSection())<br>
- TS = getISThunkSec(TIS);<br>
+ ThunkSection *ts;<br>
+ if (auto *tis = t->getTargetInputSection())<br>
+ ts = getISThunkSec(tis);<br>
else<br>
- TS = getISDThunkSec(OS, IS, ISD, Rel.Type, Src);<br>
- TS->addThunk(T);<br>
- Thunks[T->getThunkTargetSym()] = T;<br>
+ ts = getISDThunkSec(os, isec, isd, rel.type, src);<br>
+ ts->addThunk(t);<br>
+ thunks[t->getThunkTargetSym()] = t;<br>
}<br>
<br>
// Redirect relocation to Thunk, we never go via the PLT to a Thunk<br>
- Rel.Sym = T->getThunkTargetSym();<br>
- Rel.Expr = fromPlt(Rel.Expr);<br>
+ rel.sym = t->getThunkTargetSym();<br>
+ rel.expr = fromPlt(rel.expr);<br>
<br>
// The addend of R_PPC_PLTREL24 should be ignored after changing to<br>
// R_PC.<br>
- if (Config->EMachine == EM_PPC && Rel.Type == R_PPC_PLTREL24)<br>
- Rel.Addend = 0;<br>
+ if (config->emachine == EM_PPC && rel.type == R_PPC_PLTREL24)<br>
+ rel.addend = 0;<br>
}<br>
<br>
- for (auto &P : ISD->ThunkSections)<br>
- AddressesChanged |= P.first->assignOffsets();<br>
+ for (auto &p : isd->thunkSections)<br>
+ addressesChanged |= p.first->assignOffsets();<br>
});<br>
<br>
- for (auto &P : ThunkedSections)<br>
- AddressesChanged |= P.second->assignOffsets();<br>
+ for (auto &p : thunkedSections)<br>
+ addressesChanged |= p.second->assignOffsets();<br>
<br>
// Merge all created synthetic ThunkSections back into OutputSection<br>
- mergeThunks(OutputSections);<br>
- ++Pass;<br>
- return AddressesChanged;<br>
+ mergeThunks(outputSections);<br>
+ ++pass;<br>
+ return addressesChanged;<br>
}<br>
<br>
template void elf::scanRelocations<ELF32LE>(InputSectionBase &);<br>
<br>
Modified: lld/trunk/ELF/Relocations.h<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_ELF_Relocations.h-3Frev-3D365595-26r1-3D365594-26r2-3D365595-26view-3Ddiff&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=IZNXgUqBVso44zhxE6L07NsZ4SDVaDvumSQi1pNMQYw&e=" rel="noreferrer" target="_blank">https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_ELF_Relocations.h-3Frev-3D365595-26r1-3D365594-26r2-3D365595-26view-3Ddiff&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=IZNXgUqBVso44zhxE6L07NsZ4SDVaDvumSQi1pNMQYw&e=</a> <br>
==============================================================================<br>
--- lld/trunk/ELF/Relocations.h (original)<br>
+++ lld/trunk/ELF/Relocations.h Tue Jul 9 22:00:37 2019<br>
@@ -102,11 +102,11 @@ enum RelExpr {<br>
<br>
// Architecture-neutral representation of relocation.<br>
struct Relocation {<br>
- RelExpr Expr;<br>
- RelType Type;<br>
- uint64_t Offset;<br>
- int64_t Addend;<br>
- Symbol *Sym;<br>
+ RelExpr expr;<br>
+ RelType type;<br>
+ uint64_t offset;<br>
+ int64_t addend;<br>
+ Symbol *sym;<br>
};<br>
<br>
// This function writes undefined symbol diagnostics to an internal buffer.<br>
@@ -125,57 +125,57 @@ struct InputSectionDescription;<br>
class ThunkCreator {<br>
public:<br>
// Return true if Thunks have been added to OutputSections<br>
- bool createThunks(ArrayRef<OutputSection *> OutputSections);<br>
+ bool createThunks(ArrayRef<OutputSection *> outputSections);<br>
<br>
// The number of completed passes of createThunks this permits us<br>
// to do one time initialization on Pass 0 and put a limit on the<br>
// number of times it can be called to prevent infinite loops.<br>
- uint32_t Pass = 0;<br>
+ uint32_t pass = 0;<br>
<br>
private:<br>
- void mergeThunks(ArrayRef<OutputSection *> OutputSections);<br>
+ void mergeThunks(ArrayRef<OutputSection *> outputSections);<br>
<br>
- ThunkSection *getISDThunkSec(OutputSection *OS, InputSection *IS,<br>
- InputSectionDescription *ISD, uint32_t Type,<br>
- uint64_t Src);<br>
+ ThunkSection *getISDThunkSec(OutputSection *os, InputSection *isec,<br>
+ InputSectionDescription *isd, uint32_t type,<br>
+ uint64_t src);<br>
<br>
- ThunkSection *getISThunkSec(InputSection *IS);<br>
+ ThunkSection *getISThunkSec(InputSection *isec);<br>
<br>
- void createInitialThunkSections(ArrayRef<OutputSection *> OutputSections);<br>
+ void createInitialThunkSections(ArrayRef<OutputSection *> outputSections);<br>
<br>
- std::pair<Thunk *, bool> getThunk(InputSection *IS, Relocation &Rel,<br>
- uint64_t Src);<br>
+ std::pair<Thunk *, bool> getThunk(InputSection *isec, Relocation &rel,<br>
+ uint64_t src);<br>
<br>
- ThunkSection *addThunkSection(OutputSection *OS, InputSectionDescription *,<br>
- uint64_t Off);<br>
+ ThunkSection *addThunkSection(OutputSection *os, InputSectionDescription *,<br>
+ uint64_t off);<br>
<br>
- bool normalizeExistingThunk(Relocation &Rel, uint64_t Src);<br>
+ bool normalizeExistingThunk(Relocation &rel, uint64_t src);<br>
<br>
// Record all the available Thunks for a Symbol<br>
llvm::DenseMap<std::pair<SectionBase *, uint64_t>, std::vector<Thunk *>><br>
- ThunkedSymbolsBySection;<br>
- llvm::DenseMap<Symbol *, std::vector<Thunk *>> ThunkedSymbols;<br>
+ thunkedSymbolsBySection;<br>
+ llvm::DenseMap<Symbol *, std::vector<Thunk *>> thunkedSymbols;<br>
<br>
// Find a Thunk from the Thunks symbol definition, we can use this to find<br>
// the Thunk from a relocation to the Thunks symbol definition.<br>
- llvm::DenseMap<Symbol *, Thunk *> Thunks;<br>
+ llvm::DenseMap<Symbol *, Thunk *> thunks;<br>
<br>
// Track InputSections that have an inline ThunkSection placed in front<br>
// an inline ThunkSection may have control fall through to the section below<br>
// so we need to make sure that there is only one of them.<br>
// The Mips LA25 Thunk is an example of an inline ThunkSection.<br>
- llvm::DenseMap<InputSection *, ThunkSection *> ThunkedSections;<br>
+ llvm::DenseMap<InputSection *, ThunkSection *> thunkedSections;<br>
};<br>
<br>
// Return a int64_t to make sure we get the sign extension out of the way as<br>
// early as possible.<br>
template <class ELFT><br>
-static inline int64_t getAddend(const typename ELFT::Rel &Rel) {<br>
+static inline int64_t getAddend(const typename ELFT::Rel &rel) {<br>
return 0;<br>
}<br>
template <class ELFT><br>
-static inline int64_t getAddend(const typename ELFT::Rela &Rel) {<br>
- return Rel.r_addend;<br>
+static inline int64_t getAddend(const typename ELFT::Rela &rel) {<br>
+ return rel.r_addend;<br>
}<br>
} // namespace elf<br>
} // namespace lld<br>
<br>
Modified: lld/trunk/ELF/ScriptLexer.cpp<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_ELF_ScriptLexer.cpp-3Frev-3D365595-26r1-3D365594-26r2-3D365595-26view-3Ddiff&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=bogt4b2e5vJ4_FiRFVmkIhIrMcuGzzNb6KD7U0ZrSTo&e=" rel="noreferrer" target="_blank">https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_ELF_ScriptLexer.cpp-3Frev-3D365595-26r1-3D365594-26r2-3D365595-26view-3Ddiff&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=bogt4b2e5vJ4_FiRFVmkIhIrMcuGzzNb6KD7U0ZrSTo&e=</a> <br>
==============================================================================<br>
--- lld/trunk/ELF/ScriptLexer.cpp (original)<br>
+++ lld/trunk/ELF/ScriptLexer.cpp Tue Jul 9 22:00:37 2019<br>
@@ -41,169 +41,169 @@ using namespace lld::elf;<br>
<br>
// Returns a whole line containing the current token.<br>
StringRef ScriptLexer::getLine() {<br>
- StringRef S = getCurrentMB().getBuffer();<br>
- StringRef Tok = Tokens[Pos - 1];<br>
+ StringRef s = getCurrentMB().getBuffer();<br>
+ StringRef tok = tokens[pos - 1];<br>
<br>
- size_t Pos = S.rfind('\n', Tok.data() - S.data());<br>
- if (Pos != StringRef::npos)<br>
- S = S.substr(Pos + 1);<br>
- return S.substr(0, S.find_first_of("\r\n"));<br>
+ size_t pos = s.rfind('\n', tok.data() - s.data());<br>
+ if (pos != StringRef::npos)<br>
+ s = s.substr(pos + 1);<br>
+ return s.substr(0, s.find_first_of("\r\n"));<br>
}<br>
<br>
// Returns 1-based line number of the current token.<br>
size_t ScriptLexer::getLineNumber() {<br>
- StringRef S = getCurrentMB().getBuffer();<br>
- StringRef Tok = Tokens[Pos - 1];<br>
- return S.substr(0, Tok.data() - S.data()).count('\n') + 1;<br>
+ StringRef s = getCurrentMB().getBuffer();<br>
+ StringRef tok = tokens[pos - 1];<br>
+ return s.substr(0, tok.data() - s.data()).count('\n') + 1;<br>
}<br>
<br>
// Returns 0-based column number of the current token.<br>
size_t ScriptLexer::getColumnNumber() {<br>
- StringRef Tok = Tokens[Pos - 1];<br>
- return Tok.data() - getLine().data();<br>
+ StringRef tok = tokens[pos - 1];<br>
+ return tok.data() - getLine().data();<br>
}<br>
<br>
std::string ScriptLexer::getCurrentLocation() {<br>
- std::string Filename = getCurrentMB().getBufferIdentifier();<br>
- return (Filename + ":" + Twine(getLineNumber())).str();<br>
+ std::string filename = getCurrentMB().getBufferIdentifier();<br>
+ return (filename + ":" + Twine(getLineNumber())).str();<br>
}<br>
<br>
-ScriptLexer::ScriptLexer(MemoryBufferRef MB) { tokenize(MB); }<br>
+ScriptLexer::ScriptLexer(MemoryBufferRef mb) { tokenize(mb); }<br>
<br>
// We don't want to record cascading errors. Keep only the first one.<br>
-void ScriptLexer::setError(const Twine &Msg) {<br>
+void ScriptLexer::setError(const Twine &msg) {<br>
if (errorCount())<br>
return;<br>
<br>
- std::string S = (getCurrentLocation() + ": " + Msg).str();<br>
- if (Pos)<br>
- S += "\n>>> " + getLine().str() + "\n>>> " +<br>
+ std::string s = (getCurrentLocation() + ": " + msg).str();<br>
+ if (pos)<br>
+ s += "\n>>> " + getLine().str() + "\n>>> " +<br>
std::string(getColumnNumber(), ' ') + "^";<br>
- error(S);<br>
+ error(s);<br>
}<br>
<br>
// Split S into linker script tokens.<br>
-void ScriptLexer::tokenize(MemoryBufferRef MB) {<br>
- std::vector<StringRef> Vec;<br>
- MBs.push_back(MB);<br>
- StringRef S = MB.getBuffer();<br>
- StringRef Begin = S;<br>
+void ScriptLexer::tokenize(MemoryBufferRef mb) {<br>
+ std::vector<StringRef> vec;<br>
+ mbs.push_back(mb);<br>
+ StringRef s = mb.getBuffer();<br>
+ StringRef begin = s;<br>
<br>
for (;;) {<br>
- S = skipSpace(S);<br>
- if (S.empty())<br>
+ s = skipSpace(s);<br>
+ if (s.empty())<br>
break;<br>
<br>
// Quoted token. Note that double-quote characters are parts of a token<br>
// because, in a glob match context, only unquoted tokens are interpreted<br>
// as glob patterns. Double-quoted tokens are literal patterns in that<br>
// context.<br>
- if (S.startswith("\"")) {<br>
- size_t E = S.find("\"", 1);<br>
- if (E == StringRef::npos) {<br>
- StringRef Filename = MB.getBufferIdentifier();<br>
- size_t Lineno = Begin.substr(0, S.data() - Begin.data()).count('\n');<br>
- error(Filename + ":" + Twine(Lineno + 1) + ": unclosed quote");<br>
+ if (s.startswith("\"")) {<br>
+ size_t e = s.find("\"", 1);<br>
+ if (e == StringRef::npos) {<br>
+ StringRef filename = mb.getBufferIdentifier();<br>
+ size_t lineno = begin.substr(0, s.data() - begin.data()).count('\n');<br>
+ error(filename + ":" + Twine(lineno + 1) + ": unclosed quote");<br>
return;<br>
}<br>
<br>
- Vec.push_back(S.take_front(E + 1));<br>
- S = S.substr(E + 1);<br>
+ vec.push_back(s.take_front(e + 1));<br>
+ s = s.substr(e + 1);<br>
continue;<br>
}<br>
<br>
// ">foo" is parsed to ">" and "foo", but ">>" is parsed to ">>".<br>
// "|", "||", "&" and "&&" are different operators.<br>
- if (S.startswith("<<") || S.startswith("<=") || S.startswith(">>") ||<br>
- S.startswith(">=") || S.startswith("||") || S.startswith("&&")) {<br>
- Vec.push_back(S.substr(0, 2));<br>
- S = S.substr(2);<br>
+ if (s.startswith("<<") || s.startswith("<=") || s.startswith(">>") ||<br>
+ s.startswith(">=") || s.startswith("||") || s.startswith("&&")) {<br>
+ vec.push_back(s.substr(0, 2));<br>
+ s = s.substr(2);<br>
continue;<br>
}<br>
<br>
// Unquoted token. This is more relaxed than tokens in C-like language,<br>
// so that you can write "file-name.cpp" as one bare token, for example.<br>
- size_t Pos = S.find_first_not_of(<br>
+ size_t pos = s.find_first_not_of(<br>
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"<br>
"0123456789_.$/\\~=+[]*?-!^:");<br>
<br>
// A character that cannot start a word (which is usually a<br>
// punctuation) forms a single character token.<br>
- if (Pos == 0)<br>
- Pos = 1;<br>
- Vec.push_back(S.substr(0, Pos));<br>
- S = S.substr(Pos);<br>
+ if (pos == 0)<br>
+ pos = 1;<br>
+ vec.push_back(s.substr(0, pos));<br>
+ s = s.substr(pos);<br>
}<br>
<br>
- Tokens.insert(Tokens.begin() + Pos, Vec.begin(), Vec.end());<br>
+ tokens.insert(tokens.begin() + pos, vec.begin(), vec.end());<br>
}<br>
<br>
// Skip leading whitespace characters or comments.<br>
-StringRef ScriptLexer::skipSpace(StringRef S) {<br>
+StringRef ScriptLexer::skipSpace(StringRef s) {<br>
for (;;) {<br>
- if (S.startswith("/*")) {<br>
- size_t E = S.find("*/", 2);<br>
- if (E == StringRef::npos) {<br>
+ if (s.startswith("/*")) {<br>
+ size_t e = s.find("*/", 2);<br>
+ if (e == StringRef::npos) {<br>
error("unclosed comment in a linker script");<br>
return "";<br>
}<br>
- S = S.substr(E + 2);<br>
+ s = s.substr(e + 2);<br>
continue;<br>
}<br>
- if (S.startswith("#")) {<br>
- size_t E = S.find('\n', 1);<br>
- if (E == StringRef::npos)<br>
- E = S.size() - 1;<br>
- S = S.substr(E + 1);<br>
+ if (s.startswith("#")) {<br>
+ size_t e = s.find('\n', 1);<br>
+ if (e == StringRef::npos)<br>
+ e = s.size() - 1;<br>
+ s = s.substr(e + 1);<br>
continue;<br>
}<br>
- size_t Size = S.size();<br>
- S = S.ltrim();<br>
- if (S.size() == Size)<br>
- return S;<br>
+ size_t size = s.size();<br>
+ s = s.ltrim();<br>
+ if (s.size() == size)<br>
+ return s;<br>
}<br>
}<br>
<br>
// An erroneous token is handled as if it were the last token before EOF.<br>
-bool ScriptLexer::atEOF() { return errorCount() || Tokens.size() == Pos; }<br>
+bool ScriptLexer::atEOF() { return errorCount() || tokens.size() == pos; }<br>
<br>
// Split a given string as an expression.<br>
// This function returns "3", "*" and "5" for "3*5" for example.<br>
-static std::vector<StringRef> tokenizeExpr(StringRef S) {<br>
- StringRef Ops = "+-*/:!~=<>"; // List of operators<br>
+static std::vector<StringRef> tokenizeExpr(StringRef s) {<br>
+ StringRef ops = "+-*/:!~=<>"; // List of operators<br>
<br>
// Quoted strings are literal strings, so we don't want to split it.<br>
- if (S.startswith("\""))<br>
- return {S};<br>
+ if (s.startswith("\""))<br>
+ return {s};<br>
<br>
// Split S with operators as separators.<br>
- std::vector<StringRef> Ret;<br>
- while (!S.empty()) {<br>
- size_t E = S.find_first_of(Ops);<br>
+ std::vector<StringRef> ret;<br>
+ while (!s.empty()) {<br>
+ size_t e = s.find_first_of(ops);<br>
<br>
// No need to split if there is no operator.<br>
- if (E == StringRef::npos) {<br>
- Ret.push_back(S);<br>
+ if (e == StringRef::npos) {<br>
+ ret.push_back(s);<br>
break;<br>
}<br>
<br>
// Get a token before the opreator.<br>
- if (E != 0)<br>
- Ret.push_back(S.substr(0, E));<br>
+ if (e != 0)<br>
+ ret.push_back(s.substr(0, e));<br>
<br>
// Get the operator as a token.<br>
// Keep !=, ==, >=, <=, << and >> operators as a single tokens.<br>
- if (S.substr(E).startswith("!=") || S.substr(E).startswith("==") ||<br>
- S.substr(E).startswith(">=") || S.substr(E).startswith("<=") ||<br>
- S.substr(E).startswith("<<") || S.substr(E).startswith(">>")) {<br>
- Ret.push_back(S.substr(E, 2));<br>
- S = S.substr(E + 2);<br>
+ if (s.substr(e).startswith("!=") || s.substr(e).startswith("==") ||<br>
+ s.substr(e).startswith(">=") || s.substr(e).startswith("<=") ||<br>
+ s.substr(e).startswith("<<") || s.substr(e).startswith(">>")) {<br>
+ ret.push_back(s.substr(e, 2));<br>
+ s = s.substr(e + 2);<br>
} else {<br>
- Ret.push_back(S.substr(E, 1));<br>
- S = S.substr(E + 1);<br>
+ ret.push_back(s.substr(e, 1));<br>
+ s = s.substr(e + 1);<br>
}<br>
}<br>
- return Ret;<br>
+ return ret;<br>
}<br>
<br>
// In contexts where expressions are expected, the lexer should apply<br>
@@ -216,14 +216,14 @@ static std::vector<StringRef> tokenizeEx<br>
//<br>
// This function may split the current token into multiple tokens.<br>
void ScriptLexer::maybeSplitExpr() {<br>
- if (!InExpr || errorCount() || atEOF())<br>
+ if (!inExpr || errorCount() || atEOF())<br>
return;<br>
<br>
- std::vector<StringRef> V = tokenizeExpr(Tokens[Pos]);<br>
- if (V.size() == 1)<br>
+ std::vector<StringRef> v = tokenizeExpr(tokens[pos]);<br>
+ if (v.size() == 1)<br>
return;<br>
- Tokens.erase(Tokens.begin() + Pos);<br>
- Tokens.insert(Tokens.begin() + Pos, V.begin(), V.end());<br>
+ tokens.erase(tokens.begin() + pos);<br>
+ tokens.insert(tokens.begin() + pos, v.begin(), v.end());<br>
}<br>
<br>
StringRef ScriptLexer::next() {<br>
@@ -235,28 +235,28 @@ StringRef ScriptLexer::next() {<br>
setError("unexpected EOF");<br>
return "";<br>
}<br>
- return Tokens[Pos++];<br>
+ return tokens[pos++];<br>
}<br>
<br>
StringRef ScriptLexer::peek() {<br>
- StringRef Tok = next();<br>
+ StringRef tok = next();<br>
if (errorCount())<br>
return "";<br>
- Pos = Pos - 1;<br>
- return Tok;<br>
+ pos = pos - 1;<br>
+ return tok;<br>
}<br>
<br>
StringRef ScriptLexer::peek2() {<br>
skip();<br>
- StringRef Tok = next();<br>
+ StringRef tok = next();<br>
if (errorCount())<br>
return "";<br>
- Pos = Pos - 2;<br>
- return Tok;<br>
+ pos = pos - 2;<br>
+ return tok;<br>
}<br>
<br>
-bool ScriptLexer::consume(StringRef Tok) {<br>
- if (peek() == Tok) {<br>
+bool ScriptLexer::consume(StringRef tok) {<br>
+ if (peek() == tok) {<br>
skip();<br>
return true;<br>
}<br>
@@ -264,12 +264,12 @@ bool ScriptLexer::consume(StringRef Tok)<br>
}<br>
<br>
// Consumes Tok followed by ":". Space is allowed between Tok and ":".<br>
-bool ScriptLexer::consumeLabel(StringRef Tok) {<br>
- if (consume((Tok + ":").str()))<br>
+bool ScriptLexer::consumeLabel(StringRef tok) {<br>
+ if (consume((tok + ":").str()))<br>
return true;<br>
- if (Tokens.size() >= Pos + 2 && Tokens[Pos] == Tok &&<br>
- Tokens[Pos + 1] == ":") {<br>
- Pos += 2;<br>
+ if (tokens.size() >= pos + 2 && tokens[pos] == tok &&<br>
+ tokens[pos + 1] == ":") {<br>
+ pos += 2;<br>
return true;<br>
}<br>
return false;<br>
@@ -277,24 +277,24 @@ bool ScriptLexer::consumeLabel(StringRef<br>
<br>
void ScriptLexer::skip() { (void)next(); }<br>
<br>
-void ScriptLexer::expect(StringRef Expect) {<br>
+void ScriptLexer::expect(StringRef expect) {<br>
if (errorCount())<br>
return;<br>
- StringRef Tok = next();<br>
- if (Tok != Expect)<br>
- setError(Expect + " expected, but got " + Tok);<br>
+ StringRef tok = next();<br>
+ if (tok != expect)<br>
+ setError(expect + " expected, but got " + tok);<br>
}<br>
<br>
// Returns true if S encloses T.<br>
-static bool encloses(StringRef S, StringRef T) {<br>
- return S.bytes_begin() <= T.bytes_begin() && T.bytes_end() <= S.bytes_end();<br>
+static bool encloses(StringRef s, StringRef t) {<br>
+ return s.bytes_begin() <= t.bytes_begin() && t.bytes_end() <= s.bytes_end();<br>
}<br>
<br>
MemoryBufferRef ScriptLexer::getCurrentMB() {<br>
// Find input buffer containing the current token.<br>
- assert(!MBs.empty() && Pos > 0);<br>
- for (MemoryBufferRef MB : MBs)<br>
- if (encloses(MB.getBuffer(), Tokens[Pos - 1]))<br>
- return MB;<br>
+ assert(!mbs.empty() && pos > 0);<br>
+ for (MemoryBufferRef mb : mbs)<br>
+ if (encloses(mb.getBuffer(), tokens[pos - 1]))<br>
+ return mb;<br>
llvm_unreachable("getCurrentMB: failed to find a token");<br>
}<br>
<br>
Modified: lld/trunk/ELF/ScriptLexer.h<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_ELF_ScriptLexer.h-3Frev-3D365595-26r1-3D365594-26r2-3D365595-26view-3Ddiff&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=8bcI67_1ONNJvMd_7f1oRNJDqxMewX8FIUsqPlyyTLQ&e=" rel="noreferrer" target="_blank">https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_lld_trunk_ELF_ScriptLexer.h-3Frev-3D365595-26r1-3D365594-26r2-3D365595-26view-3Ddiff&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=8bcI67_1ONNJvMd_7f1oRNJDqxMewX8FIUsqPlyyTLQ&e=</a> <br>
==============================================================================<br>
--- lld/trunk/ELF/ScriptLexer.h (original)<br>
+++ lld/trunk/ELF/ScriptLexer.h Tue Jul 9 22:00:37 2019<br>
@@ -20,25 +20,25 @@ namespace elf {<br>
<br>
class ScriptLexer {<br>
public:<br>
- explicit ScriptLexer(MemoryBufferRef MB);<br>
+ explicit ScriptLexer(MemoryBufferRef mb);<br>
<br>
- void setError(const Twine &Msg);<br>
- void tokenize(MemoryBufferRef MB);<br>
- static StringRef skipSpace(StringRef S);<br>
+ void setError(const Twine &msg);<br>
+ void tokenize(MemoryBufferRef mb);<br>
+ static StringRef skipSpace(StringRef s);<br>
bool atEOF();<br>
StringRef next();<br>
StringRef peek();<br>
StringRef peek2();<br>
void skip();<br>
- bool consume(StringRef Tok);<br>
- void expect(StringRef Expect);<br>
- bool consumeLabel(StringRef Tok);<br>
+ bool consume(StringRef tok);<br>
+ void expect(StringRef expect);<br>
+ bool consumeLabel(StringRef tok);<br>
std::string getCurrentLocation();<br>
<br>
- std::vector<MemoryBufferRef> MBs;<br>
- std::vector<StringRef> Tokens;<br>
- bool InExpr = false;<br>
- size_t Pos = 0;<br>
+ std::vector<MemoryBufferRef> mbs;<br>
+ std::vector<StringRef> tokens;<br>
+ bool inExpr = false;<br>
+ size_t pos = 0;<br>
<br>
private:<br>
void maybeSplitExpr();<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a><br>
<a href="https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.llvm.org_cgi-2Dbin_mailman_listinfo_llvm-2Dcommits&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=DClm3bAkJCRXvX7Qg6Lof3Sv4VvnPQVozNHWV5zPg-8&e=" rel="noreferrer" target="_blank">https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.llvm.org_cgi-2Dbin_mailman_listinfo_llvm-2Dcommits&d=DwIGaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=o3kDXzdBUE3ljQXKeTWOMw&m=Eb7MNyrx6jtX9VvjFSFeXuc-dD82W7PUYvgHXx9M-wg&s=DClm3bAkJCRXvX7Qg6Lof3Sv4VvnPQVozNHWV5zPg-8&e=</a> <br>
<br>
<br>
</blockquote></div></div>