]>
Commit | Line | Data |
---|---|---|
e26d185c JP |
1 | From 2aa24949c7214c20cfc943a4862b5ff63470112f Mon Sep 17 00:00:00 2001 |
2 | From: Rui Ueyama <ruiu@bluewhale.systems> | |
3 | Date: Wed, 19 Oct 2022 19:33:18 +0800 | |
4 | Subject: [PATCH] [ELF][i386] Allow R_386_PC32 after R_386_TLS_{GD,LDM} | |
5 | ||
6 | I don't know why GCC sometimes creates a PC32 relocation instead of | |
7 | PLT32 after a TLS_GD/TLS_LDM. I believe it's strictly speaking a | |
8 | violation of the psABI. But we need to handle such input. | |
9 | ||
10 | Fixes https://github.com/rui314/mold/issues/794 | |
11 | --- | |
12 | elf/arch-i386.cc | 6 ++++-- | |
13 | 1 file changed, 4 insertions(+), 2 deletions(-) | |
14 | ||
15 | diff --git a/elf/arch-i386.cc b/elf/arch-i386.cc | |
16 | index 46391844..20563faa 100644 | |
17 | --- a/elf/arch-i386.cc | |
18 | +++ b/elf/arch-i386.cc | |
19 | @@ -485,7 +485,8 @@ void InputSection<E>::scan_relocations(Context<E> &ctx) { | |
20 | Fatal(ctx) << *this << ": TLS_GD reloc must be followed by PLT or GOT32"; | |
21 | ||
22 | if (u32 ty = rels[i + 1].r_type; | |
23 | - ty != R_386_PLT32 && ty != R_386_GOT32 && ty != R_386_GOT32X) | |
24 | + ty != R_386_PLT32 && ty != R_386_PC32 && | |
25 | + ty != R_386_GOT32 && ty != R_386_GOT32X) | |
26 | Fatal(ctx) << *this << ": TLS_GD reloc must be followed by PLT or GOT32"; | |
27 | ||
28 | if (relax_tlsgd(ctx, sym)) | |
29 | @@ -498,7 +499,8 @@ void InputSection<E>::scan_relocations(Context<E> &ctx) { | |
30 | Fatal(ctx) << *this << ": TLS_LDM reloc must be followed by PLT or GOT32"; | |
31 | ||
32 | if (u32 ty = rels[i + 1].r_type; | |
33 | - ty != R_386_PLT32 && ty != R_386_GOT32 && ty != R_386_GOT32X) | |
34 | + ty != R_386_PLT32 && ty != R_386_PC32 && | |
35 | + ty != R_386_GOT32 && ty != R_386_GOT32X) | |
36 | Fatal(ctx) << *this << ": TLS_LDM reloc must be followed by PLT or GOT32"; | |
37 | ||
38 | if (relax_tlsld(ctx)) | |
39 | From 288cd5b4007a0a20da9aab52ab56067ad46866e8 Mon Sep 17 00:00:00 2001 | |
40 | From: Rui Ueyama <ruiu@bluewhale.systems> | |
41 | Date: Wed, 19 Oct 2022 20:14:53 +0800 | |
42 | Subject: [PATCH] [ELF][i386] Fix assertion failure | |
43 | ||
44 | https://github.com/rui314/mold/issues/794 | |
45 | --- | |
46 | elf/arch-i386.cc | 6 ++++-- | |
47 | 1 file changed, 4 insertions(+), 2 deletions(-) | |
48 | ||
49 | diff --git a/elf/arch-i386.cc b/elf/arch-i386.cc | |
50 | index 20563faa..87524fd1 100644 | |
51 | --- a/elf/arch-i386.cc | |
52 | +++ b/elf/arch-i386.cc | |
53 | @@ -234,7 +234,8 @@ void InputSection<E>::apply_reloc_alloc(Context<E> &ctx, u8 *base) { | |
54 | } else { | |
55 | // Relax GD to LE | |
56 | switch (rels[i + 1].r_type) { | |
57 | - case R_386_PLT32: { | |
58 | + case R_386_PLT32: | |
59 | + case R_386_PC32: { | |
60 | static const u8 insn[] = { | |
61 | 0x65, 0xa1, 0, 0, 0, 0, // mov %gs:0, %eax | |
62 | 0x81, 0xe8, 0, 0, 0, 0, // add $val, %eax | |
63 | @@ -266,7 +267,8 @@ void InputSection<E>::apply_reloc_alloc(Context<E> &ctx, u8 *base) { | |
64 | } else { | |
65 | // Relax LD to LE | |
66 | switch (rels[i + 1].r_type) { | |
67 | - case R_386_PLT32: { | |
68 | + case R_386_PLT32: | |
69 | + case R_386_PC32: { | |
70 | static const u8 insn[] = { | |
71 | 0x31, 0xc0, // xor %eax, %eax | |
72 | 0x65, 0x8b, 0x00, // mov %gs:(%eax), %eax |