在 2024/4/1 下午9:51, Xi Ruoyao 写道:
Is this patch targeting GCC 14 or 15?  If 14 I guess we'd commit now...

Generally we don't add features in stage 4, but if we keep trad as the
default I think it'd be OK.  And RISC-V guys plan to push their TLS desc
implementation this week too.

I've rebase the code to the latest commit, and if the test is okay I'll bring it up right away.

Thanks!:-)


On Tue, 2024-03-19 at 09:54 +0800, mengqinggang wrote:
Add support for TLS descriptors on normal code model and extreme code model.

Normal code model instruction sequence:
   -mno-explicit-relocs:
     la.tls.desc        $r4, s
     add.d      $r12, $r4, $r2
   -mexplicit-relocs:
     pcalau12i  $r4,%desc_pc_hi20(s)
     addi.d     $r4,$r4,%desc_pc_lo12(s)
     ld.d       $r1,$r4,%desc_ld(s)
     jirl       $r1,$r1,%desc_call(s)
     add.d      $r12, $r4, $r2

Extreme code model instruction sequence:
   -mno-explicit-relocs:
     la.tls.desc        $r4, $r12, s
     add.d      $r12, $r4, $r2
   -mexplicit-relocs:
     pcalau12i  $r4,%desc_pc_hi20(s)
     addi.d     $r12,$r0,%desc_pc_lo12(s)
     lu32i.d    $r12,%desc64_pc_lo20(s)
     lu52i.d    $r12,$r12,%desc64_pc_hi12(s)
     add.d      $r4,$r4,$r12
     ld.d       $r1,$r4,%desc_ld(s)
     jirl       $r1,$r1,%desc_call(s)
     add.d      $r12, $r4, $r2

The default is still traditional TLS model, but can be configured with
--with-tls={trad,desc}. The default can change to TLS descriptors once
libc and LLVM support this.

gcc/ChangeLog:

        * config.gcc: Add --with-tls option to change TLS flavor.
        * config/loongarch/genopts/loongarch.opt.in: Add -mtls-dialect to
        configure TLS flavor.
        * config/loongarch/loongarch-def.h (struct loongarch_target): Add
        tls_dialect.
        * config/loongarch/loongarch-driver.cc (la_driver_init): Add tls
        flavor.
        * config/loongarch/loongarch-opts.cc (loongarch_init_target): Add
        tls_dialect.
        (loongarch_config_target): Ditto.
        (loongarch_update_gcc_opt_status): Ditto.
        * config/loongarch/loongarch-opts.h (loongarch_init_target):Ditto.
        (TARGET_TLS_DESC): New define.
        * config/loongarch/loongarch.cc (loongarch_symbol_insns): Add TLS DESC
        instructions sequence length.
        (loongarch_legitimize_tls_address): New TLS DESC instruction sequence.
        (loongarch_option_override_internal): Add la_opt_tls_dialect.
        (loongarch_option_restore): Add la_target.tls_dialect.
        * config/loongarch/loongarch.md (@got_load_tls_desc<mode>): Normal
        code model for TLS DESC.
        (got_load_tls_desc_off64): Extreme code model for TLS DESC.
        * config/loongarch/loongarch.opt: Regenerated.

gcc/testsuite/ChangeLog:

        * gcc.target/loongarch/cmodel-extreme-1.c: Add -mtls-dialect=trad.
        * gcc.target/loongarch/cmodel-extreme-2.c: Ditto.
        * gcc.target/loongarch/explicit-relocs-auto-tls-ld-gd.c: Ditto.
        * gcc.target/loongarch/explicit-relocs-medium-call36-auto-tls-ld-gd.c:
        Ditto.
        * gcc.target/loongarch/func-call-medium-1.c: Ditto.
        * gcc.target/loongarch/func-call-medium-2.c: Ditto.
        * gcc.target/loongarch/func-call-medium-3.c: Ditto.
        * gcc.target/loongarch/func-call-medium-4.c: Ditto.
        * gcc.target/loongarch/tls-extreme-macro.c: Ditto.
        * gcc.target/loongarch/tls-gd-noplt.c: Ditto.
        * gcc.target/loongarch/explicit-relocs-auto-extreme-tls-desc.c: New 
test.
        * gcc.target/loongarch/explicit-relocs-auto-tls-desc.c: New test.
        * gcc.target/loongarch/explicit-relocs-extreme-tls-desc.c: New test.
        * gcc.target/loongarch/explicit-relocs-tls-desc.c: New test.

Co-authored-by: Lulu Cheng <chengl...@loongson.cn>
Co-authored-by: Xi Ruoyao <xry...@xry111.site>

Reply via email to