Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Link failure with -z notext (it changes behaviour, not just allows DT_TEXTREL) #35068

Closed
emaste opened this issue Dec 21, 2017 · 7 comments
Closed
Labels
bugzilla Issues migrated from bugzilla lld:ELF

Comments

@emaste
Copy link
Member

emaste commented Dec 21, 2017

Bugzilla Link 35720
Resolution FIXED
Resolved on Dec 26, 2017 23:44
Version unspecified
OS FreeBSD
Blocks #23588
Attachments FreeBSD 'hello world' -Wl,-z,notext build failure reproducer

Extended Description

-z notext should allow relocations in a read-only (i.e., the .text) segment, but lld changes behaviour when -z notext is specified and linking a trivial application on FreeBSD fails:

% cc -Wl,-z,notext hello.c
/usr/bin/ld: error: relocation R_X86_64_PC32 cannot be used against shared object; recompile with -fPIC

defined in /lib/libc.so.7
referenced by crt1.c:63 (/usr/home/emaste/src/freebsd/lib/csu/amd64/crt1.c:63)
/usr/lib/crt1.o:(_start)
cc: error: linker command failed with exit code 1 (use -v to see invocation)

I do not have a reduced test case, but can attach a reproducer for the hello world link if desired. However, I observe that RelExpr() bypasses the special case for Sym.isFunc() if !Config->ZText. There's a comment in RelExpr() that describes this same issue occurring with glibc.

@emaste
Copy link
Member Author

emaste commented Dec 22, 2017

Also I think the sense of this comment is backwards:

// Or, if we are allowed to create dynamic relocations against
// read-only sections (i.e. unless "-z notext" is given),
// we can create a dynamic relocation as we want, too.
if (!Config->ZText)
return Expr;

That should be "i.e., if "-z notext" is given"

@llvmbot
Copy link
Collaborator

llvmbot commented Dec 22, 2017

Also I think the sense of this comment is backwards:

// Or, if we are allowed to create dynamic relocations against
// read-only sections (i.e. unless "-z notext" is given),
// we can create a dynamic relocation as we want, too.
if (!Config->ZText)
return Expr;

That should be "i.e., if "-z notext" is given"

Looking at this.

But you also helped to find bug in google translate :)
It translates "unless" to russian "if", and not to "if ... not":
https://translate.google.ru/#en/ru/unless
notice, when pressing switch message button, backward translation from
russian is "if" then.

@llvmbot
Copy link
Collaborator

llvmbot commented Dec 22, 2017

Reduced test case is following.

main.s:
.text
_start:
callq atexit

dso.s:
.text
.global atexit
atexit:
nop

llvm-mc -filetype=obj -triple=x86_64-pc-linux main.s -o main.o
llvm-mc -filetype=obj -triple=x86_64-pc-linux dso.s -o dso.o
ld.lld -shared dso.o -o dso.so

ld.lld test.o -o out dso.so -z notext

error: relocation R_X86_64_PC32 cannot be used against shared object; recompile with -fPIC

@llvmbot
Copy link
Collaborator

llvmbot commented Dec 22, 2017

Fix: https://reviews.llvm.org/D41541

@llvmbot
Copy link
Collaborator

llvmbot commented Dec 23, 2017

First fix for 'hello world' was committed as r321400.

@llvmbot
Copy link
Collaborator

llvmbot commented Dec 23, 2017

Second fix is https://reviews.llvm.org/D41551,
I checked that 'hello world' provided links fine with it.

@llvmbot
Copy link
Collaborator

llvmbot commented Dec 27, 2017

Last piece: r321473.

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 10, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla lld:ELF
Projects
None yet
Development

No branches or pull requests

2 participants