Linking with -znocopyreloc has no effect on ARM. The result binary still contains an R_ARM_COPY relocation. $ cat data-ref.s .globl _start .p2align 4 _start: bkpt .data .globl data_object object_reference: .long data_object .size object_reference,4 $ cat libdata.s .data .globl data_object .type data_object, %object .size data_object, 4 data_object: .long 123 $ as -o data-ref.o data-ref.s $ as -o libdata.o libdata.s $ ld.bfd -shared -o libdata.so libdata.o $ ld.bfd -znocopyreloc -o data-ref data-ref.o libdata.so $ readelf -r data-ref Relocation section '.rel.dyn' at offset 0x20c contains 1 entries: Offset Info Type Sym.Value Sym. Name 000202c0 00000314 R_ARM_COPY 000202c0 data_object Linking with ld.gold does the right thing: Relocation section '.rel.dyn' at offset 0x19c contains 1 entries: Offset Info Type Sym.Value Sym. Name 00009240 00000102 R_ARM_ABS32 00000000 data_object Related to bug 16177 (I borrowed the example program from there).
Created attachment 9208 [details] Proposed patch Hi David, Please try out this patch. Cheers Nick
Hi David, Any feedback on Nick's patch?
It's reported that the same issue exists for aarch64 (and Nicks patch is meanwhile on master but only addresses arm).
Created attachment 12792 [details] Proposed patch FYI - here is a proposed, but completely untested, patch for the AArch64...
So with current master binutils, without additional changes I don't see copy relocs on aarch64 with the (adjusted for data size) example: % cat data-ref.s .globl _start .p2align 4 _start: ret .data .globl data_object # .section .rodata,"a",@progbits object_reference: .quad data_object .size object_reference,8 % cat libdata.s .data .globl data_object .type data_object, %object .size data_object, 8 data_object: .quad 123 % ./gas/as-new -o data-ref.o data-ref.s % ./gas/as-new -o libdata.o libdata.s % ./ld/ld-new -shared -o libdata.so libdata.o % ./ld/ld-new -znocopyreloc -o data-ref data-ref.o libdata.so % readelf -rW data-ref Relocation section '.rela.dyn' at offset 0x230 contains 1 entry: Offset Info Type Symbol's Value Symbol's Name + Addend 0000000000411000 0000000100000101 R_AARCH64_ABS64 0000000000000000 data_object + 0 This doesn't change when the '.section rodata' directive is uncommented, i.e. when the reference comes from a read-only section. Still no copy-reloc. (Without the -znocopyreloc linker option we do generate a copy reloc, but that's expected). So, right now I don't see anything in need for fixing. This all was somewhat related to a go problem: https://github.com/golang/go/issues/22040 . If that one still exists then it's different from _this_ problem report here. If there's new info or a reproducer that still shows a problem, please reopen.
(And just FWIW: aarch64 binutils 2.36 and 2.37 don't have the problem either).