Skip to content

Solaris ld raises reloc errors in JIT_WriteBarrier_Debug and ThePreStub #35154

Description

@am11

When linking libcoreclr.so, Solaris linker on SmartOS errors out as follow:

[vagrant@08-00-27-42-a0-69 ~/runtime]$ cd /home/vagrant/runtime/artifacts/obj/coreclr/SunOS.x64.Debug/src/dlls/mscoree/coreclr && /opt/tools/bin/cmake -E cmake_link_script CMakeFiles/coreclr.dir/link.txt --verbose=1

/opt/tools/bin/g++ -fPIC  -fstack-protector -g  -shared -Wl,-hlibcoreclr.so -o libcoreclr.so CMakeFiles/coreclr.dir/__/mscoree.cpp.o CMakeFiles/coreclr.dir/__/unixinterface.cpp.o CMakeFiles/coreclr.dir/__/__/__/__/version.c.o  ../../../utilcode/libutilcode.a ../../../debug/ee/wks/libcordbee_wks.a ../../../debug/debug-pal/libdebug-pal.a ../../../unwinder/libunwinder_wks.a ../../../vm/wks/libcee_wks.a ../../../binder/libv3binder.a ../../../md/compiler/libmdcompiler_wks.a ../../../md/runtime/libmdruntime_wks.a ../../../md/enc/libmdruntimerw_wks.a ../../../md/hotdata/libmdhotdata_full.a ../../../classlibnative/bcltype/libbcltype.a ../../../md/ceefilegen/libceefgen.a ../../../classlibnative/float/libcomfloat_wks.a ../../../inc/libcorguids.a ../../../gcinfo/libgcinfo.a ../../../debug/ildbsymlib/libildbsymlib.a ../../../utilcode/libutilcode.a ../../../binder/libv3binder.a ../../../libraries-native/liblibraries-native.a ../../../libraries-native/System.Globalization.Native/libSystem.Globalization.Native.a ../../../interop/libinterop.a ../../../pal/src/libcoreclrpal.a ../../mscorrc/libmscorrc.a ../../../palrt/libpalrt.a ../../../vm/eventing/eventpipe/libeventpipe.a ../../../pal/src/eventprovider/dummyprovider/libeventprovider.a ../../../nativeresources/libnativeresourcestring.a -lpthread -lrt 

Text relocation remains                 	referenced
    against symbol		    offset	in file
JIT_WriteBarrier_Debug              0x21      	../../../vm/wks/libcee_wks.a(jithelpers_fast.S.o)
ThePreStub                          0x15      	../../../vm/wks/libcee_wks.a(unixasmhelpers.S.o)
ld: fatal: relocations remain against allocatable but non-writable sections
collect2: error: ld returned 1 exit status

I have workaround this error by using -mimpure-text -Wl,-ztextoff linker flags.
Is this an indication of something that can be fixed in the highlighted stubs?

Activity

  1. added
    area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
    untriagedNew issue has not been triaged by the area owner
    on Apr 18, 2020
  2. added
    os-SunOSSunOS, currently not officially supported
    and removed
    area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
    on Apr 18, 2020
  3. jkotas commented on Apr 18, 2020

    @jkotas
    Member

    jmp C_FUNC(JIT_WriteBarrier_Debug) and jmp C_FUNC(ThePreStub) are obviously causing this problem.

    Try compiling extern void ThePreStub(); void Test() { ThePreStub(); } with gcc -fvisibility=hidden -O2 -S test.c and look at what the jmp looks like. The hand-written assembly should mimic that.

  4. am11 commented on Apr 18, 2020

    @am11
    MemberAuthor

    This is the output from SmartOS x64:

    $ echo "extern void ThePreStub(); void Test() { ThePreStub(); }" |\
         gcc -x c -fvisibility=hidden -O2 -S - -o- |\
         grep -B8 -A8 ThePreStub
    
    .LFB0:
    	pushq	%rbp
    .LCFI0:
    	xorl	%eax, %eax
    	movq	%rsp, %rbp
    .LCFI1:
    	popq	%rbp
    .LCFI2:
    	jmp	ThePreStub
    .LFE0:
    	.size	Test, .-Test
    	.section	.eh_frame,"a",@unwind
    .Lframe1:
    	.long	.LECIE1-.LSCIE1
    .LSCIE1:
    	.long	0
    	.byte	0x1

    and on Ubuntu x64:

    	.p2align 4,,15
    	.globl	Test
    	.hidden	Test
    	.type	Test, @function
    Test:
    .LFB0:
    	.cfi_startproc
    	xorl	%eax, %eax
    	jmp	ThePreStub@PLT
    	.cfi_endproc
    .LFE0:
    	.size	Test, .-Test
    	.ident	"GCC: (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0"
    	.section	.note.GNU-stack,"",@progbits
  5. jkotas commented on Apr 18, 2020

    @jkotas
    Member

    Hmm, this jmp ThePreStub looks exactly like the one in the asm code.

    Maybe you can try to add a call to ThePreStub in tailcall position somewhere in the C/C++ code and see whether it links fine?

  6. am11 commented on Apr 18, 2020

    @am11
    MemberAuthor

    With -fPIC, this compiles fine on SmartOS and Ubuntu:

    echo "int ThePreStub() {return 0;} int Test() { return ThePreStub(); } void Start() { Test(); }" \
        | gcc -x c -fvisibility=hidden -shared -O2 -fPIC -

    without -fPIC, it gives the same error on SmartOS but not on Ubuntu:

    Text relocation remains                         referenced
        against symbol                  offset      in file
    .text (section)                     0x20        /var/tmp//ccFfambs.o
    .text (section)                     0x38        /var/tmp//ccFfambs.o
    .text (section)                     0x50        /var/tmp//ccFfambs.o
    ld: fatal: relocations remain against allocatable but non-writable sections
    collect2: error: ld returned 1 exit status
    

    and we are compiling coreclr with -fPIC on both SmartOS and Ubuntu, so should be fine.

  7. jkotas commented on Apr 18, 2020

    @jkotas
    Member

    What is the output of -S with -fPIC ? Is it different from the above?

  8. am11 commented on Apr 18, 2020

    @am11
    MemberAuthor

    It adds @PLT with -fPIC:

    --- without_fPIC
    +++ with_fPIC
    @@ -13,7 +13,7 @@
     .LCFI1:
            popq    %rbp
     .LCFI2:
    -       jmp     ThePreStub
    +       jmp     ThePreStub@PLT
     .LFE0:
            .size   Test, .-Test
            .section        .eh_frame,"a",@unwind
    @@ -27,7 +27,7 @@
            .sleb128 -8
            .byte   0x10
            .uleb128 0x1
    -       .byte   0x3
    +       .byte   0x1b
            .byte   0xc
            .uleb128 0x7
            .uleb128 0x8
    @@ -39,7 +39,7 @@
            .long   .LEFDE1-.LASFDE1
     .LASFDE1:
            .long   .LASFDE1-.Lframe1
    -       .long   .LFB0
    +       .long   .LFB0-.
            .long   .LFE0-.LFB0
            .uleb128 0
            .byte   0x4
  9. jkotas commented on Apr 18, 2020

    @jkotas
    Member

    Does the error go away if you replace jmp C_FUNC(ThePreStub) with jmp ThePreStub@PLT in unixasmhelpers.S ?

  10. am11 commented on Apr 19, 2020

    @am11
    MemberAuthor

    I had some other undefined symbols errors due to missing SunOS linker options for EXPORTS_FILE (-M for Illumos ld is similar as --version-file in GNU ld). Adding that linker options in few CMateLists.txt files automagically resolved this reloc issue. The build now succeeds on SmartOS without -mimpure-text option.

    Thanks for your help @jkotas.

  11. janvorli commented on Apr 20, 2020

    @janvorli
    Member

    @am11 the C_PLTFUNC macro is what you want to use instead of manually adding the @plt.

  12. am11 commented on Apr 20, 2020

    @am11
    MemberAuthor

    @janvorli, ack. I did not had to explicitly modify anything to fix this. It was implicitly fixed when I fixed other missing symbol issue; by adding some linker flags. PR has all the required changes: #35173.

  13. ghost locked as resolved and limited conversation to collaborators on Dec 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-VM-coreclros-SunOSSunOS, currently not officially supporteduntriagedNew issue has not been triaged by the area owner

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions