Giter Site home page Giter Site logo

Comments (1)

japaric avatar japaric commented on September 25, 2024

This won't work on msvc because there is no libgcc_s.so there. Instead we can link to msvcrt.lib, which contains the intrinsics we want to test against. However, the intrinsics in msvcrt.lib are named differently from the ones in gcc_s/compiler-rt. This is good because we can statically link against that library without worrying about name collisions but it's also annoying because we must now translate from msvcrt naming to compiler-rt naming.

@retep998 has provided us with a list of the intrinsics available in msvcrt.lib. But we still need to translate the names from msvcrt to compiler-rt. That can be done by looking into llvm source code. For example there are code sections like:

// lib/Target/X86/X86ISelLowering.cpp

  if (Subtarget.isTargetKnownWindowsMSVC()) {
    // Setup Windows compiler runtime calls.
    setLibcallName(RTLIB::SDIV_I64, "_alldiv");
    setLibcallName(RTLIB::UDIV_I64, "_aulldiv");
    setLibcallName(RTLIB::SREM_I64, "_allrem");
    setLibcallName(RTLIB::UREM_I64, "_aullrem");
    setLibcallName(RTLIB::MUL_I64, "_allmul");
    setLibcallCallingConv(RTLIB::SDIV_I64, CallingConv::X86_StdCall);
    setLibcallCallingConv(RTLIB::UDIV_I64, CallingConv::X86_StdCall);
    setLibcallCallingConv(RTLIB::SREM_I64, CallingConv::X86_StdCall);
    setLibcallCallingConv(RTLIB::UREM_I64, CallingConv::X86_StdCall);
    setLibcallCallingConv(RTLIB::MUL_I64, CallingConv::X86_StdCall);
  }

that contain the msvcrt names. And other sections like this one:

// lib/Target/ARM/ARMISelLowering.cpp

    } LibraryCalls[] = {
      // ...

      // Integer division functions
      // RTABI chapter 4.3.1
      { RTLIB::SDIV_I8,  "__aeabi_idiv",     CallingConv::ARM_AAPCS, ISD::SETCC_INVALID },
      { RTLIB::SDIV_I16, "__aeabi_idiv",     CallingConv::ARM_AAPCS, ISD::SETCC_INVALID },
      { RTLIB::SDIV_I32, "__aeabi_idiv",     CallingConv::ARM_AAPCS, ISD::SETCC_INVALID },
      { RTLIB::SDIV_I64, "__aeabi_ldivmod",  CallingConv::ARM_AAPCS, ISD::SETCC_INVALID },
      { RTLIB::UDIV_I8,  "__aeabi_uidiv",    CallingConv::ARM_AAPCS, ISD::SETCC_INVALID },
      { RTLIB::UDIV_I16, "__aeabi_uidiv",    CallingConv::ARM_AAPCS, ISD::SETCC_INVALID },
      { RTLIB::UDIV_I32, "__aeabi_uidiv",    CallingConv::ARM_AAPCS, ISD::SETCC_INVALID },
      { RTLIB::UDIV_I64, "__aeabi_uldivmod", CallingConv::ARM_AAPCS, ISD::SETCC_INVALID },
    };

that contain the compiler-rt names. Using that information you can conclude that RTLIB::UDIV_I64 === __aeabi_uldivmod === _allmul.

With that background information, here are the next steps:

  • Create a msvcrt crate that links to msvcrt.lib and binds to the msvcrt intrinsics. That crate must expose the same API as the gcc_s crate. Basically, it must provide functions like __muldi3: fn() -> Option<extern unsafe fn(u64, u64) -> u64>. The crate must handle the differences in naming and signature of intrinsics between msvcrt and compiler-rt.
  • Then, probably, we only need to add a #[cfg(target_env = "msvc")] extern crate msvcrt as gcc_s to the root of the rustc-builtins crate (for tests only).

from compiler-builtins.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.