Skip to content

Commit

Permalink
Deal with compiler changes on Windows giving different bitfield padding
Browse files Browse the repository at this point in the history
  • Loading branch information
ibmmqmet committed Aug 22, 2019
1 parent 191a694 commit 619d5b7
Show file tree
Hide file tree
Showing 16 changed files with 173 additions and 12 deletions.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,6 @@ Jul 2019 (v5.1.2)

Aug 2019 (v5.1.3)
* Print QJST SLPTU as number not timestamp

Aug 2019 (v5.1.4)
* Newer compilers have changed bitfield structure padding layouts
Binary file modified bin/aix/convH
Binary file not shown.
Binary file modified bin/aix/mqsmfcsv
Binary file not shown.
Binary file modified bin/linux/convH
Binary file not shown.
Binary file modified bin/linux/mqsmfcsv
Binary file not shown.
Binary file modified bin/win/convH.exe
Binary file not shown.
Binary file modified bin/win/mqsmfcsv.exe
Binary file not shown.
4 changes: 2 additions & 2 deletions src/M
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ plat=`uname`

if [ "$plat" = "AIX" ]
then
flags="-q32 -qmaxmem=-1 $CCEXTRAFLAGS"
flags="-q32 -qmaxmem=-1 $CCEXTRAFLAGS -D PLATFORM_AIX"
cc="xlc"
targdir="../bin/aix"
optim="-O3"
else
flags="-m32 $CCEXTRAFLAGS"
flags="-m32 $CCEXTRAFLAGS -D PLATFORM_LINUX"
cc="gcc"
targdir="../bin/linux"
optim="-O3"
Expand Down
10 changes: 8 additions & 2 deletions src/Makefile.gcc.win
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

CC=i686-w64-mingw32-gcc
CFLAGS= -I. -m32 -O2
CFLAGS= -I. -m32 -fpack-struct=1 -DPLATFORM_WINDOWS
PLATFLAGS=
VERS=913
SRC = mqsmf.c \
Expand All @@ -9,6 +9,7 @@ SRC = mqsmf.c \
smfConv.c \
smfJson.c \
smfPrint.c \
checkSize.c \
printDEBUG.c \
printQ5ST.c \
printQCST.c \
Expand Down Expand Up @@ -38,6 +39,11 @@ SRC = mqsmf.c \
HDR = mqsmfstruc.h \
mqsmf.h

checkSize: mqsmfcsv.exe
./mqsmfcsv.exe -v > sizes.tmp
diff -b sizes.tmp sizes.master


mqsmfcsv.exe: $(SRC) $(HDR) Makefile.gcc.win dummy
-rm -f $@
$(CC) $(PLATFLAGS) -o $@ $(SRC) $(CFLAGS) -DCSQDSMF_VERSION=$(VERS)
Expand All @@ -48,7 +54,7 @@ mqsmfstruc.h: csqdsmfc-$(VERS).h convH.exe dummy
./convH.exe < csqdsmfc-$(VERS).h > $@

convH.exe: convH.c
$(CC) -o $@ convH.c
$(CC) $(CFLAGS) -o $@ convH.c
cp $@ ../bin/win


Expand Down
5 changes: 5 additions & 0 deletions src/Makefile.unix
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ SRC = \
smfDate.c \
smfConv.c \
smfJson.c \
checkSize.c \
printDEBUG.c \
printQ5ST.c \
printQCST.c \
Expand Down Expand Up @@ -38,6 +39,10 @@ SRC = \
HDR = mqsmfstruc.h \
mqsmf.h

checkSize: mqsmfcsv
./mqsmfcsv -v > sizes.tmp
diff -b sizes.tmp sizes.master

mqsmfcsv: $(SRC) $(HDR) Makefile.unix dummy
$(CC) $(PLATFLAGS) -o $@ $(SRC) $(CFLAGS) -DCSQDSMF_VERSION=$(VERS)

Expand Down
9 changes: 7 additions & 2 deletions src/Makefile.win
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
CFLAGS=-nologo /D_CRT_SECURE_NO_WARNINGS /Zp1 /J /O2
CFLAGS=-nologo /D_CRT_SECURE_NO_WARNINGS /Zp1 /J /O2 /DPLATFORM_WINDOWS
VERS=913
SRC = mqsmf.c \
smfDDL.c \
smfDate.c \
smfConv.c \
smfJson.c \
smfPrint.c \
checkSize.c \
printDEBUG.c \
printQ5ST.c \
printQCST.c \
Expand Down Expand Up @@ -35,6 +36,10 @@ SRC = mqsmf.c \
HDR = mqsmfstruc.h \
mqsmf.h

checkSize: mqsmfcsv.exe
mqsmfcsv.exe -v > sizes.tmp
diff -b sizes.master sizes.tmp

mqsmfcsv.exe: $(SRC) $(HDR) Makefile.win
rm -f $@
$(CC) $(SRC) -I. /Fe$@ $(CFLAGS) -DCSQDSMF_VERSION=$(VERS)
Expand All @@ -45,7 +50,7 @@ mqsmfstruc.h: csqdsmfc-$(VERS).h convH.exe dummy
convH < csqdsmfc-$(VERS).h > $@

convH.exe: convH.c
$(CC) /Fe$@ convH.c
$(CC) $(CFLAGS) /Fe$@ convH.c
copy $@ ..\bin\win


Expand Down
45 changes: 45 additions & 0 deletions src/checkSize.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include "stdio.h"
#include "stddef.h"
#include "../src/mqsmfstruc.h"

void checkStructureSizes(FILE *fp) {

fprintf(fp,"%s : %d\n","q5st",sizeof(q5st));
fprintf(fp,"%s : %d\n","qcct",sizeof(qcct));
fprintf(fp,"%s : %d\n","qct_dsp",sizeof(qct_dsp));
fprintf(fp,"%s : %d\n","qct_adp",sizeof(qct_adp));
fprintf(fp,"%s : %d\n","qct_ssl",sizeof(qct_ssl));
fprintf(fp,"%s : %d\n","qct_dns",sizeof(qct_dns));
fprintf(fp,"%s : %d\n","qcst",sizeof(qcst));
fprintf(fp,"%s : %d\n","qest",sizeof(qest));
fprintf(fp,"%s : %d\n","qesd",sizeof(qesd));
fprintf(fp,"%s : %d\n","qist",sizeof(qist));
fprintf(fp,"%s : %d\n","qis1",sizeof(qis1));
fprintf(fp,"%s : %d\n","qjst",sizeof(qjst));
fprintf(fp,"%s : %d\n","qlst",sizeof(qlst));
fprintf(fp,"%s : %d\n","qmac",sizeof(qmac));
fprintf(fp,"%s : %d\n","qmst",sizeof(qmst));
fprintf(fp,"%s : %d\n","qpst",sizeof(qpst));
fprintf(fp,"%s : %d\n","qsgm",sizeof(qsgm));
fprintf(fp,"%s : %d\n","qsph",sizeof(qsph));
fprintf(fp,"%s : %d\n","qsrs",sizeof(qsrs));
fprintf(fp,"%s : %d\n","qsst",sizeof(qsst));
fprintf(fp,"%s : %d\n","qtst",sizeof(qtst));
fprintf(fp,"%s : %d\n","qwac",sizeof(qwac));
fprintf(fp,"%s : %d\n","qwhc",sizeof(qwhc));
fprintf(fp,"%s : %d\n","qwhs",sizeof(qwhs));
fprintf(fp,"%s : %d\n","wtas",sizeof(wtas));
fprintf(fp,"%s : %d\n","wtid",sizeof(wtid));
fprintf(fp,"%s : %d\n","qwst",sizeof(qwst));
fprintf(fp,"%s : %d\n","qws0",sizeof(qws0));
fprintf(fp,"%s : %d\n","qws1",sizeof(qws1));
fprintf(fp,"%s : %d\n","qws5",sizeof(qws5));
fprintf(fp,"%s : %d\n","qws8",sizeof(qws8));
fprintf(fp,"%s : %d\n","qws9",sizeof(qws9));
fprintf(fp,"%s : %d\n","qwsx",sizeof(qwsx));
fprintf(fp,"%s : %d\n","qwas",sizeof(qwas));
fprintf(fp,"%s : %d\n","qwa0",sizeof(qwa0));
fprintf(fp,"%s : %d\n","wq ",sizeof(wq));
fprintf(fp,"wq->maxqdpth: %d\n",offsetof(wq,maxqdpth));
fprintf(fp,"wq->z__001 : %d\n",offsetof(wq,z__001 ));
}
63 changes: 59 additions & 4 deletions src/convH.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,37 @@
#include <stdio.h>
#include <string.h>

#if defined(PLATFORM_WINDOWS)
#define BITFIELDREPRINTNEEDED (1)
#else
#define BITFIELDREPRINTNEEDED (0)
#endif

int inBitfieldReplace = 0;
void bitfieldReprint(int c);

/*
* This is a very simple filter to take the product-provided
* header file from z/OS and strip a few things that are
* problematic on other platform compilers.
*
* It means we don't need to keep a variant copy
* of the header in sync when new versions come out.
* of the header in sync [Awhen new versions come out.
*
* In particular, get rid of the z/OS format for
* the pragmas, and also the trigraph at the top
* of the file.
*
* If the contents of the header file change, this
* filter may need to be updated to match.
*
* Newer compiler versions on some platforms have also
* affected how bitfields are laid out. This program now
* rewrites bitfield structures that have been found to be a problem.
* The changes have to be explicitly for each issue, but the build process
* does now check if the structure sizes are unexpectedly different.
* The AIX compiler seems to give the same sizes as z/OS so that's the master
* we will drive the comparison from.
*/
int main(int argc, char **argv)
{
Expand Down Expand Up @@ -57,13 +74,51 @@ int main(int argc, char **argv)
continue;
else
{
printf("%s",line);
if (line[strlen(line)-1] != '\n')
printf("\n");
if (BITFIELDREPRINTNEEDED) {
if (strstr(line,"fNoAcctg")) {
bitfieldReprint(1);
}
if (strstr(line,"qwhssmfc")) {
bitfieldReprint(2);
}
}

if (inBitfieldReplace) {
/* Have we reached the end of the bitfield structure */
if (strstr(line,"}"))
inBitfieldReplace = 0;
}

if (!inBitfieldReplace) {
printf("%s",line);
if (line[strlen(line)-1] != '\n')
printf("\n");
}

}
}
} while (c);

fflush(stdout);
return 0;
}

void bitfieldReprint(int c) {
inBitfieldReplace = 1;
switch (c) {
case 1:
printf(" unsigned char fNoAcctg : 1;\n");
printf(" unsigned char fTopic : 1;\n");
printf(" unsigned char fAcctqC : 1;\n");
printf(" unsigned char spare : 5;\n");
printf(" unsigned char spare2 : 8;\n");
break;
case 2:
printf(" unsigned char qwhssmfc : 1;\n");
printf(" unsigned char qwhspad1 : 7;\n");
break;
default:
break;
}
}

7 changes: 5 additions & 2 deletions src/mqsmf.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,14 +239,14 @@ int main( int argc, char *argv[] )
exit(1);
}


infoStream=stdout;

/*fprintf(infoStream,"Sizeof qwhs = %d\n",sizeof(qwhs));*/

/******************************************************************/
/* Parse command-line parameters */
/******************************************************************/
while((c = mqgetopt(argc, argv, "ab:cd:e:f:h:i:m:o:p:rst:")) != EOF)
while((c = mqgetopt(argc, argv, "ab:cd:e:f:h:i:m:o:p:rst:v")) != EOF)
{
switch(c)
{
Expand Down Expand Up @@ -327,6 +327,9 @@ int main( int argc, char *argv[] )
case 't':
ticker = atoi(mqoptarg);
break;
case 'v':
checkStructureSizes(infoStream);
exit(0);
default:
error = TRUE;
break;
Expand Down
1 change: 1 addition & 0 deletions src/mqsmf.h
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ extern void smfPrintStop(FILE *,BOOL, BOOL *,columnHeader_t **);
extern void smfAddHead(BOOL first,BOOL,char *h,int type,int len);
extern void smfAddData(int datatype,char *fmt,...);
extern void smfAddString(int, char *);
extern void checkStructureSizes(FILE *);

#define SMFPRINTGLOB \
static BOOL first = TRUE;\
Expand Down
38 changes: 38 additions & 0 deletions src/sizes.master
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
q5st : 672
qcct : 48
qct_dsp : 36
qct_adp : 32
qct_ssl : 48
qct_dns : 48
qcst : 324
qest : 4104
qesd : 328
qist : 80
qis1 : 104
qjst : 592
qlst : 32
qmac : 48
qmst : 104
qpst : 104
qsgm : 48
qsph : 88
qsrs : 232
qsst : 72
qtst : 96
qwac : 176
qwhc : 92
qwhs : 52
wtas : 2344
wtid : 208
qwst : 28
qws0 : 96
qws1 : 72
qws5 : 16
qws8 : 16
qws9 : 16
qwsx : 48
qwas : 28
qwa0 : 56
wq : 2788
wq->maxqdpth: 588
wq->z__001 : 594

0 comments on commit 619d5b7

Please sign in to comment.