mirror of
https://github.com/rui314/mold.git
synced 2024-09-22 02:20:51 +03:00
temporary
This commit is contained in:
parent
9cbb74faa1
commit
a61911b3d2
@ -46,7 +46,6 @@ void InputSection::copy_buf() {
|
|||||||
|
|
||||||
switch (rel.getType(false)) {
|
switch (rel.getType(false)) {
|
||||||
case R_X86_64_NONE:
|
case R_X86_64_NONE:
|
||||||
case R_X86_64_DTPOFF32:
|
|
||||||
break;
|
break;
|
||||||
case R_X86_64_64:
|
case R_X86_64_64:
|
||||||
*(u64 *)loc = S + A;
|
*(u64 *)loc = S + A;
|
||||||
@ -100,9 +99,7 @@ void InputSection::copy_buf() {
|
|||||||
if (sym.tlsld_idx == -1) {
|
if (sym.tlsld_idx == -1) {
|
||||||
// Relax LD to LE
|
// Relax LD to LE
|
||||||
static const u8 insn[] = {
|
static const u8 insn[] = {
|
||||||
0x66, 0x66, // .word 0x6666
|
0x66, 0x66, 0x66, 0x64, 0x48, 0x8b, 0x04, 0x25, 0, 0, 0, 0, // mov %fs:0, %rax
|
||||||
0x66, // .byte 0x66
|
|
||||||
0x64, 0x48, 0x8b, 0x04, 0x25, 0, 0, 0, 0, // mov %fs:0, %rax
|
|
||||||
};
|
};
|
||||||
memcpy(loc - 3, insn, sizeof(insn));
|
memcpy(loc - 3, insn, sizeof(insn));
|
||||||
i++;
|
i++;
|
||||||
@ -110,12 +107,13 @@ void InputSection::copy_buf() {
|
|||||||
*(u32 *)loc = sym.get_tlsld_addr() + A - P;
|
*(u32 *)loc = sym.get_tlsld_addr() + A - P;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case R_X86_64_GOTTPOFF:
|
case R_X86_64_DTPOFF32:
|
||||||
*(u32 *)loc = sym.get_gottpoff_addr() + A - P;
|
|
||||||
break;
|
|
||||||
case R_X86_64_TPOFF32:
|
case R_X86_64_TPOFF32:
|
||||||
*(u32 *)loc = S - out::tls_end;
|
*(u32 *)loc = S - out::tls_end;
|
||||||
break;
|
break;
|
||||||
|
case R_X86_64_GOTTPOFF:
|
||||||
|
*(u32 *)loc = sym.get_gottpoff_addr() + A - P;
|
||||||
|
break;
|
||||||
case R_X86_64_PC64:
|
case R_X86_64_PC64:
|
||||||
*(u64 *)loc = S + A - P;
|
*(u64 *)loc = S + A - P;
|
||||||
break;
|
break;
|
||||||
|
10
mold.h
10
mold.h
@ -261,6 +261,7 @@ public:
|
|||||||
|
|
||||||
virtual void scan_relocations() {}
|
virtual void scan_relocations() {}
|
||||||
virtual void copy_buf() {}
|
virtual void copy_buf() {}
|
||||||
|
u64 get_addr() const;
|
||||||
|
|
||||||
ObjectFile *file;
|
ObjectFile *file;
|
||||||
const ELF64LE::Shdr &shdr;
|
const ELF64LE::Shdr &shdr;
|
||||||
@ -762,11 +763,8 @@ private:
|
|||||||
inline u64 Symbol::get_addr() const {
|
inline u64 Symbol::get_addr() const {
|
||||||
if (piece_ref.piece)
|
if (piece_ref.piece)
|
||||||
return piece_ref.piece->get_addr() + piece_ref.addend;
|
return piece_ref.piece->get_addr() + piece_ref.addend;
|
||||||
|
|
||||||
if (input_section)
|
if (input_section)
|
||||||
return input_section->output_section->shdr.sh_addr +
|
return input_section->get_addr() + value;
|
||||||
input_section->offset + value;
|
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -805,6 +803,10 @@ inline u64 StringPiece::get_addr() const {
|
|||||||
return is->parent.shdr.sh_addr + is->offset + output_offset;
|
return is->parent.shdr.sh_addr + is->offset + output_offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline u64 InputChunk::get_addr() const {
|
||||||
|
return output_section->shdr.sh_addr + offset;
|
||||||
|
}
|
||||||
|
|
||||||
inline void write_string(u8 *buf, StringRef str) {
|
inline void write_string(u8 *buf, StringRef str) {
|
||||||
memcpy(buf, str.data(), str.size());
|
memcpy(buf, str.data(), str.size());
|
||||||
buf[str.size()] = '\0';
|
buf[str.size()] = '\0';
|
||||||
|
29
test/tls-ld.c
Normal file
29
test/tls-ld.c
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
// RUN: cc -ftls-model=local-dynamic -fPIC -c -o %t1.o %s
|
||||||
|
// RUN: echo '_Thread_local int foo = 3;' | cc -xc -c -fPIC -o %t2.o -
|
||||||
|
// RUN: mold -o %t.exe /usr/lib/x86_64-linux-gnu/crt1.o \
|
||||||
|
// RUN: /usr/lib/x86_64-linux-gnu/crti.o \
|
||||||
|
// RUN: /usr/lib/gcc/x86_64-linux-gnu/9/crtbegin.o \
|
||||||
|
// RUN: %t1.o %t2.o \
|
||||||
|
// RUN: /usr/lib/gcc/x86_64-linux-gnu/9/libgcc.a \
|
||||||
|
// RUN: /usr/lib/x86_64-linux-gnu/libgcc_s.so.1 \
|
||||||
|
// RUN: /lib/x86_64-linux-gnu/libc.so.6 \
|
||||||
|
// RUN: /usr/lib/x86_64-linux-gnu/libc_nonshared.a \
|
||||||
|
// RUN: /lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 \
|
||||||
|
// RUN: /usr/lib/gcc/x86_64-linux-gnu/9/crtend.o \
|
||||||
|
// RUN: /usr/lib/x86_64-linux-gnu/crtn.o
|
||||||
|
// RUN: %t.exe | grep '3 5 3 5'
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
extern _Thread_local int foo;
|
||||||
|
static _Thread_local int bar;
|
||||||
|
|
||||||
|
int *get_foo_addr() { return &foo; }
|
||||||
|
int *get_bar_addr() { return &bar; }
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
bar = 5;
|
||||||
|
|
||||||
|
printf("%d %d %d %d\n", *get_foo_addr(), *get_bar_addr(), foo, bar);
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user