CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 13 of 13
  1. #1
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,835

    [RESOLVED] File Extension ".S"

    I'm trying to build a 64-bit library called libffi using MSVC. It contains a bunch of 'C' files and another file with the extension .S whose file contents seem to be mostly assembler - but with certain 'C' traits, such as #defines / #includes etc. The file contents look something like this:-

    Code:
    #define LIBFFI_ASM
    #include <fficonfig.h>
    #include <ffi.h>
    	
    /* Constants for ffi_call_win64 */	
    #define STACK 0
    #define PREP_ARGS_FN 32
    #define ECIF 40
    #define CIF_BYTES 48
    #define CIF_FLAGS 56
    #define RVALUE 64
    #define FN 72
    
    /* ffi_call_win64 (void (*prep_args_fn)(char *, extended_cif *),
                       extended_cif *ecif, unsigned bytes, unsigned flags,
                       unsigned *rvalue, void (*fn)());
     */
    
    #ifdef _MSC_VER
    PUBLIC	ffi_call_win64
    
    EXTRN	__chkstk:NEAR
    EXTRN	ffi_closure_win64_inner:NEAR
    
    _TEXT	SEGMENT
    
    ;;; ffi_closure_win64 will be called with these registers set:
    ;;;    rax points to 'closure'
    ;;;    r11 contains a bit mask that specifies which of the
    ;;;    first four parameters are float or double
    ;;;
    ;;; It must move the parameters passed in registers to their stack location,
    ;;; call ffi_closure_win64_inner for the actual work, then return the result.
    ;;; 
    ffi_closure_win64 PROC FRAME
    	;; copy register arguments onto stack
    	test	r11, 1
    	jne	first_is_float	
    	mov	QWORD PTR [rsp+8], rcx
    	jmp	second
    first_is_float:
    	movlpd	QWORD PTR [rsp+8], xmm0
    
    second:
    	test	r11, 2
    	jne	second_is_float	
    	mov	QWORD PTR [rsp+16], rdx
    	jmp	third
    second_is_float:
    	movlpd	QWORD PTR [rsp+16], xmm1
    
    third:
    	test	r11, 4
    	jne	third_is_float	
    	mov	QWORD PTR [rsp+24], r8
    	jmp	fourth
    third_is_float:
    	movlpd	QWORD PTR [rsp+24], xmm2
    
    // tons of other stuff
    
    #endif
    As you can see, the presence of #ifdef _MSC_VER creates the impression that it should be buildable with MSVC - but if I add it to a VS2015 project, VS2015 doesn't even seem to recognise it (clicking 'Properties' for the file simply says Does not participate in build).

    I tried changing the file extension to .c but that didn't help either. I just got loads of compiler errors - starting with error C2061: syntax error: identifier 'ffi_call_win64' which occurs at the line I've indicated in blue.

    What am I doing wrong

    [Edit...] I think I'm starting to understand what's wrong... where I see the text:- Does not participate in build, I realised later that it's an entry in a drop-down list. If I go back to my previous compiler (VS2005) the relevant entry in that list box says:- Microsoft Macro Assembler. However, that option isn't present with VS2015 (Community Edition). Is the Macro Assembler an additional tool that I need to install separately? Or is assembly language just not supported in the Community Edition?
    Last edited by John E; August 12th, 2016 at 03:13 AM.
    "A problem well stated is a problem half solved.” - Charles F. Kettering

  2. #2
    Join Date
    May 2001
    Location
    Germany
    Posts
    1,158

    Re: File Extension ".S"


  3. #3
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,825

    Re: File Extension ".S"

    Is the Macro Assembler an additional tool that I need to install separately? Or is assembly language just not supported in the Community Edition?
    The macro assembler is part of VS2015 community and is installed. To find it from a command line prompt
    Code:
    cd \
    dir ml*.exe /s/a/o/p
    ml.exe is the 32 bit assembler
    ml64.exe is the 64 bit assembler
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  4. #4
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,835

    Re: File Extension ".S"

    Thanks guys,

    ml64.exe is pre-installed but it's in 2 x folders:- VC\bin\amd64 and \VC\bin\x86_amd64 (whereas my CPU is an Intel).

    So as an experiment I decided to surround all the assembler with __asm{} and build as a 'C' file. But when I tried that, it gave me:- error C4235: nonstandard extension used: '__asm' keyword not supported on this architecture

    I'm a bit baffled at the moment...
    "A problem well stated is a problem half solved.” - Charles F. Kettering

  5. #5
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,825

    Re: File Extension ".S"

    In-line assembler is not support for 64bit
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  6. #6
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,835

    Re: File Extension ".S"

    Quote Originally Posted by 2kaud View Post
    In-line assembler is not support for 64bit
    Okay, that explains one problem but I'm still puzzled about why I've no entry for Microsoft Macro Assembler.

    2kaud - could you select a source file in your Solution Explorer and then select its Properties. Under General->Item Type can you see if any of the items refers to MASM? On my system it simply doesn't appear in the list of build tools.

    Quote Originally Posted by John E View Post
    ml64.exe is pre-installed but it's in 2 x folders:- VC\bin\amd64 and \VC\bin\x86_amd64 (whereas my CPU is an Intel)
    Maybe I need to add those folders to my system path or something??
    "A problem well stated is a problem half solved.” - Charles F. Kettering

  7. #7
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,825

    Re: File Extension ".S"

    could you select a source file in your Solution Explorer and then select its Properties. Under General->Item Type can you see if any of the items refers to MASM?
    Nothing on my VS2015 either that refers to assembler.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  8. #8
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,825

    Re: File Extension ".S"

    ml64.exe is pre-installed but it's in 2 x folders:- VC\bin\amd64 and \VC\bin\x86_amd64 (whereas my CPU is an Intel).
    I think it's the amd64 one but I'm not an assembler expert. You might want to consider asking in the assembler forum?
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  9. #9
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,835

    Re: File Extension ".S"

    Will do, thanks.
    "A problem well stated is a problem half solved.” - Charles F. Kettering

  10. #10
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,825

    Re: File Extension ".S"

    You might find this article and its links of help

    https://social.msdn.microsoft.com/Fo...lstudiogeneral
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  11. #11
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,825

    Re: File Extension ".S"

    I think you need to specify a custom build for the .s files. See
    https://msdn.microsoft.com/en-us/library/hefydhhy.aspx

    You can then specify the required command line for ml64.exe to compile the .s file

    PS Try renaming the .s file(s) to .asm as .asm is the extension for Microsoft assembler files.
    Last edited by 2kaud; August 12th, 2016 at 06:19 AM. Reason: PS
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  12. #12
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,835

    Re: File Extension ".S"

    Actually I think I found it eventually...

    1) Right click on the project file (in Solution Explorer)
    2) Select Build Dependencies->Build Customizations
    3) Tick the option for "masm"

    Microsoft Macro Assembler will now be listed as one of the available build tools when you select Properties->General->Item Type for a given source file.

    Not exactly intuitive - but it seems to be working...
    "A problem well stated is a problem half solved.” - Charles F. Kettering

  13. #13
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,825

    Re: [RESOLVED] File Extension ".S"

    Yes, I agree not very intuitive. It uses ml or ml64 based upon what is specified as active in the configuration manager.

    You can now alter the masm properties for the build similar to changing c++ build properties.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured