NO

Author Topic: error trying to produce assembly source listing  (Read 1667 times)

Jimg

  • Guest
error trying to produce assembly source listing
« on: February 02, 2019, 06:43:35 PM »
First, I am basically a total beginner at C.

I'm playing with an old Microsoft terminal program call MTTTY.

I sucessfully compiled it.   I wanted to see the assembly language produced, so I added the -Tx86-asm switch to CCFLAGS.
(As an aside question, CCFLAGS seems to be protected, I couldn't change it under project options/compiler, I had to manually edit the ppj file.)

No when I compile, I get the error:
POLINK: fatal error: Invalid machine type in object 'F:\PellesC\Progs\mttymod\output\Error2.obj'.
*** Error code: 1 ***

I can't see anything in the code to cause this, but then I'm not very good a C.

Here is the code for Error2.C
Code: [Select]
/*-----------------------------------------------------------------------------
    This is a part of the Microsoft Source Code Samples.
    Copyright (C) 1995 Microsoft Corporation.
    All rights reserved.
    This source code is only intended as a supplement to
    Microsoft Development Tools and/or WinHelp documentation.

    MODULE: Error.c

    PURPOSE: Implement error handling functions
             called to report errors.
-----------------------------------------------------------------------------*/

#include <windows.h>
#include "mttty.h"    /* included in all the other modules, so I don't think the error is here */

DWORD ErrorExtender(DWORD, char **);

DWORD ErrorExtender(DWORD dwError, char ** szBuffer)
{
    DWORD dwRes = 0;

    dwRes = FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER | 80 ,
                          NULL, dwError,
                          MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US),
                          (LPTSTR) szBuffer, 0, NULL);

    if (dwRes == 0) {
        *szBuffer = LocalAlloc(LPTR, 1);
        return 1;
    }

    return dwRes;
}

void ErrorReporter(char * szMessage)
{
    char * szFormat = "Error %d: %s.\n\r%s\r\n";    // format for wsprintf
    char * szExtended;      // error string translated from error code
    char * szFinal;         // final string to report
    DWORD dwExtSize;
    DWORD dwErr;

    dwErr = GetLastError();

    /*
        Get error string from system
    */
    dwExtSize = ErrorExtender(dwErr, &szExtended);
   
    /*
        allocate buffer for error string from system, passed in string
        and extra stuff from the szFormat string
    */
    szFinal = LocalAlloc(LPTR, strlen(szMessage) + dwExtSize + 30);

    if (szFinal == NULL) // if no final buffer, then can't format error
        MessageBox(ghwndMain, "Cannot properly report error.", "Fatal Error", MB_OK);
    else {
        wsprintf(szFinal, szFormat, dwErr, szMessage, szExtended);

        OutputDebugString(szFinal);

        if (DISPLAYERRORS(TTYInfo))
            MessageBox(ghwndMain, szFinal, NULL, MB_OK);

        LocalFree(szFinal);                  // free final buffer
    }

    /*
        free extended string buffer
    */
    LocalFree(szExtended);

    return;
}

void ErrorHandler(char * szMessage)
{
    ErrorReporter(szMessage);
    ExitProcess(0);
}

void ErrorInComm(char * szMessage)
{
    ErrorReporter(szMessage);
    BreakDownCommPort();
    ExitProcess(0);
}

Since it worked before I asked for the assembly source listing, I'm a little mystified here.  Any help will be appreciated.

p.s.-
Since this is the FIRST module in the project, it may be that this error would show for every module.

pps.

I stripped the code down to this but still get the same error, so I don't think it is code related-
Code: [Select]
#include <windows.h>
DWORD ErrorExtender(DWORD dwError, char ** szBuffer)
{
    ExitProcess(0);
}

void ErrorReporter(char * szMessage)
{
    ExitProcess(0);
}

void ErrorHandler(char * szMessage)
{
    ExitProcess(0);
}

void ErrorInComm(char * szMessage)
{
    ExitProcess(0);
}

ppps-
and in case it helps, here is the project file-
Code: [Select]
#
# PROJECT FILE generated by "Pelles C for Windows, version 8.00".
# WARNING! DO NOT EDIT THIS FILE.
#

POC_PROJECT_VERSION = 7.00#
POC_PROJECT_TYPE = 0#
POC_PROJECT_OUTPUTDIR = output#
POC_PROJECT_RESULTDIR = .#
POC_PROJECT_ARGUMENTS = #
POC_PROJECT_WORKPATH = .#
POC_PROJECT_EXECUTOR = #
POC_PROJECT_ZIPEXTRA = #
CC = pocc.exe#
AS = poasm.exe#
RC = porc.exe#
LINK = polink.exe#
SIGN = posign.exe#
CCFLAGS = -std:C11 -Tx86-coff -Tx86-asm -MT -Ob1 -fp:precise -W1 -Gd -Ze#
ASFLAGS = -AIA32 -Gz#
RCFLAGS = #
LINKFLAGS = -subsystem:windows -machine:x86 kernel32.lib user32.lib gdi32.lib comctl32.lib comdlg32.lib advapi32.lib delayimp.lib winmm.lib#
SIGNFLAGS = -location:CU -store:MY -timeurl:http://timestamp.verisign.com/scripts/timstamp.dll -errkill#
INCLUDE = $(PellesCDir)\Include\Win;$(PellesCDir)\Include#
LIB = $(PellesCDir)\Lib\Win;$(PellesCDir)\Lib#

#
# Build originalmtty.exe.
#
originalmtty.exe: \
output\INIT.obj \
output\MTTTY.obj \
output\MTTTY.res \
output\READER.obj \
output\READSTAT.obj \
output\SETTINGS.obj \
output\STATUS.obj \
output\TRANSFER.obj \
output\WRITER.obj \
output\ERROR.obj
$(LINK) $(LINKFLAGS) -out:"$@" $**

#
# Build MTTTY.obj.
#
output\MTTTY.obj: \
MTTTY.C \
mttty.h \
resource.h \
ttyinfo.h
$(CC) $(CCFLAGS) "$!" -Fo"$@"

#
# Build MTTTY.res.
#
output\MTTTY.res: \
MTTTY.RC \
MTTTY.ICO \
MTTTY2.ICO \
MTTTY3.ICO \
MTTTY4.ICO \
resource.h
$(RC) $(RCFLAGS) "$!" -Fo"$@"

#
# Build INIT.obj.
#
output\INIT.obj: \
INIT.C \
mttty.h \
resource.h \
ttyinfo.h
$(CC) $(CCFLAGS) "$!" -Fo"$@"

#
# Build READER.obj.
#
output\READER.obj: \
READER.C \
mttty.h \
resource.h \
ttyinfo.h
$(CC) $(CCFLAGS) "$!" -Fo"$@"

#
# Build READSTAT.obj.
#
output\READSTAT.obj: \
READSTAT.C \
mttty.h \
resource.h \
ttyinfo.h
$(CC) $(CCFLAGS) "$!" -Fo"$@"

#
# Build SETTINGS.obj.
#
output\SETTINGS.obj: \
SETTINGS.C \
mttty.h \
resource.h \
ttyinfo.h
$(CC) $(CCFLAGS) "$!" -Fo"$@"

#
# Build STATUS.obj.
#
output\STATUS.obj: \
STATUS.C \
mttty.h \
resource.h \
ttyinfo.h
$(CC) $(CCFLAGS) "$!" -Fo"$@"

#
# Build TRANSFER.obj.
#
output\TRANSFER.obj: \
TRANSFER.C \
mttty.h \
resource.h \
ttyinfo.h
$(CC) $(CCFLAGS) "$!" -Fo"$@"

#
# Build WRITER.obj.
#
output\WRITER.obj: \
WRITER.C \
mttty.h \
resource.h \
ttyinfo.h
$(CC) $(CCFLAGS) "$!" -Fo"$@"

#
# Build ERROR.obj.
#
output\ERROR.obj: \
ERROR.C \
mttty.h \
resource.h \
ttyinfo.h
$(CC) $(CCFLAGS) "$!" -Fo"$@"

.EXCLUDEDFILES:

.SILENT:
« Last Edit: February 02, 2019, 07:05:52 PM by Jimg »

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2096
Re: error trying to produce assembly source listing
« Reply #1 on: February 02, 2019, 09:48:48 PM »
Quote
#
# PROJECT FILE generated by "Pelles C for Windows, version 8.00".
# WARNING! DO NOT EDIT THIS FILE.
#
Means that you shouldn't modify it unless you know what you're doing.  ::)
Using the switch -Tx86-asm the compiler will produce an assembly listing instead of an object file (got it? just the assembly listing, not both listing and object!), and name it as your file with an obj extension. In your case the compiler produced the file "Error2.obj".
This file was used by the linker to produce the executable. And as soon it opens the file instead of an object format found a text file, from where come the linker error message.
The switch -Tx86-asm is a diagnostic support function of the compiler, supposed to be used on a command line to produce a list file, not in the IDE.
It is better to be hated for what you are than to be loved for what you are not. - Andre Gide

Jimg

  • Guest
Re: error trying to produce assembly source listing
« Reply #2 on: February 02, 2019, 10:14:35 PM »
Well, that's a surprise.    Thanks, I'll see if I can use the files.