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

lld-linked FreeBSD libc contains .text relocations #27187

Closed
emaste opened this issue Mar 2, 2016 · 3 comments
Closed

lld-linked FreeBSD libc contains .text relocations #27187

emaste opened this issue Mar 2, 2016 · 3 comments
Labels
bugzilla duplicate lld

Comments

@emaste
Copy link
Member

@emaste emaste commented Mar 2, 2016

Bugzilla Link 26813
Resolution DUPLICATE
Resolved on Mar 03, 2016 15:10
Version unspecified
OS FreeBSD
Blocks #23588

Extended Description

Found during ongoing attempts to link the FreeBSD base system with lld.

For processing .text relocations the runtime loader temporarily maps the segment with write permission. I discovered that we have an issue in FreeBSD's runtime loader: it expects the first PT_LOAD segment to be .text, and unprotects only that one. (That issue is tracked in http://bugs.freebsd.org/207631.)

This uncovered two lld issues, however.

First, lld should set DT_TEXTREL or DF_TEXTREL if the output contains relocations in non-writable segments.

DF_TEXTREL
If this flag is not set, no relocation entry should cause a modification to a non-writable segment, as specified by the segment permissions in the program header table. If this flag is set, one or more relocation entries might request modifications to a non-writable segment, and the dynamic linker can prepare accordingly.

The real issue here though is that the relocation exists at all.

feynman% findtextrel lib/libc.so.7 | head
lib/libc.so.7: ELF object contains text relocation records:
lib/libc.so.7: off: 0x9d0ac, func: __sys_numa_setaffinity
lib/libc.so.7: off: 0x9d0cc, func: __sys_numa_getaffinity
lib/libc.so.7: off: 0x9d0ec, func: _procctl
...

feynman% readelf -r lib/libc.so.7 | grep 9d0ac
00000009d0ac 09ab00000002 R_X86_64_PC32 00000000001a62c4 .cerror + fffffffffffffffc

These all come from the autogenerated libc syscall wrappers.

#define RSYSCALL(name) ENTRY(_sys##name); \
WEAK_REFERENCE(_sys##name, name); \
WEAK_REFERENCE(_sys##name, ##name); \
mov $SYS
##name,%eax; KERNCALL; \
jb HIDENAME(cerror); ret; \
END(_sys##name)

@emaste
Copy link
Member Author

@emaste emaste commented Mar 2, 2016

DF_TEXTREL/DT_TEXTREL issue moved to separate PR 26814 for tracking.

@llvmbot
Copy link
Collaborator

@llvmbot llvmbot commented Mar 3, 2016

This is just version scripts not being implemented. It reduces to

$ cat cerror.s
.globl .cerror
.cerror:
$ cat ioctl.s
jb .cerror
$ cat Version.map
FOO {
local: *;
};

Without the version map both ld.lld and the system linker produce a relocation since cerror is not hidden.

Just marking cerror as hidden would avoid this and is probably a good thing anyway.

@emaste
Copy link
Member Author

@emaste emaste commented Mar 3, 2016

Marked as duplicate of the version script PR.

We have a workaround (PR 26814 or hack to FreeBSD rtld) to continue with the FreeBSD buildworld testing, and there's nothing specific to do for this PR.

*** This bug has been marked as a duplicate of bug llvm/llvm-bugzilla-archive#23231 ***

@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 duplicate lld
Projects
None yet
Development

No branches or pull requests

2 participants