[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Bug binutils/31000] New: objcopy: add support for changing ELF symbol v
From: |
i at maskray dot me |
Subject: |
[Bug binutils/31000] New: objcopy: add support for changing ELF symbol visibility |
Date: |
Thu, 26 Oct 2023 05:24:25 +0000 |
https://sourceware.org/bugzilla/show_bug.cgi?id=31000
Bug ID: 31000
Summary: objcopy: add support for changing ELF symbol
visibility
Product: binutils
Version: unspecified
Status: NEW
Severity: normal
Priority: P2
Component: binutils
Assignee: unassigned at sourceware dot org
Reporter: i at maskray dot me
Target Milestone: ---
Recently I have been dealing with a benign multiple definition related to
compiler-rt/lib/builtins and rust-lang/compiler-builtins.
I need a workaround to convert certain symbols with hidden visibility to
default visibility.
(If you are curious, see
https://discourse.llvm.org/t/relocatable-file-definitions-shared-with-dso/74391
related to an improved linker error --no-allow-shlib-undefined)
It appears that objcopy does not provide a direct way to set symbol visibility,
but I have found a workaround:
objcopy --strip-symbol __udivmodti4 --add-symbol
__udivmodti4=.text.__udivmodti4:0,weak udivmodti4.c.o
Running this command on an archive will add __udivmodti4 to every archive
member, which is not desired. So, I needed to determine which archive member
defines __udivmodti4. I ended up implementing something like this in Bazel:
"""$(AR) x --output=$(@D)/lib $(OUTS)
for o in $(@D)/lib/*.o; do
$(NM) -gU $$o | grep -qw __udivmodti4 && $(OBJCOPY) --strip-symbol
__udivmodti4 --add-symbol __udivmodti4=.text.__udivmodti4:0,weak $$o
done
$(AR) r $(OUTS) $(@D)/lib/*.o
rm -rf $(@D)/lib"""
This is cumbersome.
Suppose you want to convert a symbol from default visibility to hidden
visibility. Unfortunately, I couldn't find a straightforward way to do it.
However, llvm-objcopy provides two extension:
# objcopy --strip-symbol __udivmodti4 --add-symbol
__udivmodti4=.text.__udivmodti4:0,weak,hidden udivmodti4.c.o # unrecognized
symbol flag `hidden'
llvm-objcopy --strip-symbol __udivmodti4 --add-symbol
__udivmodti4=.text.__udivmodti4:0,weak,hidden udivmodti4.c.o
llvm-objcopy --strip-symbol __udivmodti4 --add-symbol
__udivmodti4=.text.__udivmodti4:0,weak --new-symbol-visibility=hidden
udivmodti4.c.o
https://llvm.org/docs/CommandGuide/llvm-objcopy.html#cmdoption-llvm-objcopy-new-symbol-visibility
--new-symbol-visibility also affects `_binary_*_{start,end,size}` symbols
created by
llvm-objcopy --new-symbol-visibility hidden -I binary -B i386:x86-64 a.txt a.o
This feature request tracks these possible extensions:
* 'hidden' in --add-symbol
* --new-symbol-visibility=hidden
* An option like --set-symbol-flags that can operate on an existing symbol
--
You are receiving this mail because:
You are on the CC list for the bug.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Bug binutils/31000] New: objcopy: add support for changing ELF symbol visibility,
i at maskray dot me <=