Compare commits

...
2 Commits
Author SHA1 Message Date
Rui Ueyama e390a70f6c Bump mold version to 0.9.6 2021-09-27 14:54:15 +09:00
Rui Ueyama d7412d60cc [ELF] Fix "recompile with -fPIC" error
mold used to emit a spurious "recompile with -fPIC" error when creating
a position-dependent executable. This is because we alwyas create
dynamic relocations for importe symbols. If the relocated place is
read-only, we can't apply a dynamic relocation, and we printed out the
error message.

This patch fixes the issue by creating copy relocations and PLTs for
such symbols.

Fixes https://github.com/rui314/mold/issues/116
2021-09-27 14:53:56 +09:00
8 changed files with 14 additions and 10 deletions

No files matched your search

+1 -1
View File
@@ -11,7 +11,7 @@ GIT_HASH ?= $(shell [ -d .git ] && git rev-parse HEAD)
OS ?= $(shell uname -s)
CPPFLAGS = -g -pthread -std=c++20 -fPIE \
-DMOLD_VERSION=\"0.9.5\" \
-DMOLD_VERSION=\"0.9.6\" \
-DGIT_HASH=\"$(GIT_HASH)\" \
$(EXTRA_CPPFLAGS)
LDFLAGS += $(EXTRA_LDFLAGS)
+1 -1
View File
@@ -61,7 +61,7 @@ environment, you can build mold by the following commands.
$ sudo apt-get install build-essential libstdc++-10-dev cmake clang libssl-dev zlib1g-dev libxxhash-dev git
$ git clone https://github.com/rui314/mold.git
$ cd mold
$ git checkout v0.9.5
$ git checkout v0.9.6
$ make
```
+1 -1
View File
@@ -398,7 +398,7 @@ void InputSection<AARCH64>::scan_relocations(Context<AARCH64> &ctx) {
// Absolute Local Imported data Imported code
{ NONE, BASEREL, DYNREL, DYNREL }, // DSO
{ NONE, BASEREL, DYNREL, DYNREL }, // PIE
{ NONE, NONE, DYNREL, DYNREL }, // PDE
{ NONE, NONE, COPYREL, PLT }, // PDE
};
dispatch(ctx, table, i);
break;
+1 -1
View File
@@ -404,7 +404,7 @@ void InputSection<I386>::scan_relocations(Context<I386> &ctx) {
// Absolute Local Imported data Imported code
{ NONE, BASEREL, DYNREL, DYNREL }, // DSO
{ NONE, BASEREL, DYNREL, DYNREL }, // PIE
{ NONE, NONE, DYNREL, DYNREL }, // PDE
{ NONE, NONE, COPYREL, PLT }, // PDE
};
dispatch(ctx, table, i);
break;
+1 -1
View File
@@ -556,7 +556,7 @@ void InputSection<X86_64>::scan_relocations(Context<X86_64> &ctx) {
// Absolute Local Imported data Imported code
{ NONE, BASEREL, DYNREL, DYNREL }, // DSO
{ NONE, BASEREL, DYNREL, DYNREL }, // PIE
{ NONE, NONE, DYNREL, DYNREL }, // PDE
{ NONE, NONE, COPYREL, PLT }, // PDE
};
dispatch(ctx, table, i);
break;
+1 -2
View File
@@ -861,7 +861,6 @@ void GotSection<E>::copy_buf(Context<E> &ctx) {
template <typename E>
void PltSection<E>::add_symbol(Context<E> &ctx, Symbol<E> *sym) {
ASSERT(!sym->has_plt(ctx));
ASSERT(!sym->has_got(ctx));
if (this->shdr.sh_size == 0) {
this->shdr.sh_size = E::plt_hdr_size;
@@ -1005,7 +1004,7 @@ void DynsymSection<E>::copy_buf(Context<E> &ctx) {
} else if (sym.file->is_dso || sym.esym().is_undef()) {
esym.st_shndx = SHN_UNDEF;
esym.st_size = 0;
if (!ctx.arg.pic && sym.has_plt(ctx) && !sym.has_got(ctx)) {
if (sym.has_plt(ctx) && !ctx.arg.pic) {
// Emit an address for a canonical PLT
esym.st_value = sym.get_plt_addr(ctx);
}
+4 -1
View File
@@ -531,7 +531,10 @@ void scan_rels(Context<E> &ctx) {
ctx.got->add_got_symbol(ctx, sym);
if (sym->flags & NEEDS_PLT) {
if (sym->flags & NEEDS_GOT)
// If we need to create a canonical PLT (i.e. ctx.arg.pic is false),
// we can't use .plt.got because otherwise .plt.got and .plt would
// refer each other, resulting in an infinite loop at runtime.
if ((sym->flags & NEEDS_GOT) && !ctx.arg.pic)
ctx.pltgot->add_symbol(ctx, sym);
else
ctx.plt->add_symbol(ctx, sym);
+4 -2
View File
@@ -10,11 +10,13 @@ cat <<EOF | cc -shared -o $t/a.so -xc -
void fn() {}
EOF
cat <<EOF | cc -o $t/b.o -c -xc -
cat <<EOF | cc -o $t/b.o -c -xc -fno-PIC -
#include <stdio.h>
typedef void Func();
void fn();
void (*ptr)() = fn;
Func *const ptr = fn;
int main() {
printf("%d\n", fn == ptr);