Mail Archives: djgpp/2015/05/14/12:34:59
--001a113f284e3eb22105160d4e5d
Content-Type: text/plain; charset=UTF-8
On 5/14/15, Eli Zaretskii (eliz AT gnu DOT org) <djgpp AT delorie DOT com> wrote:
>> Date: Wed, 13 May 2015 23:27:39 +0300
>> From: "Ozkan Sezer (sezeroz AT gmail DOT com)" <djgpp AT delorie DOT com>
>>
>> > If you (or someone else) can verify that the size of the structure and
>> > the offsets of each member are the same in both C and C++ programs,
>> > then I see no reason to keep the attribute on every member.
>>
>> I did the following as a foo.c and foo.cc:
>>
>> #define COMPILE_TIME_ASSERT(name, x) \
>> typedef int _djchk_ ## name[(x) * 2 - 1]
>>
>> #include "dos.h"
>> COMPILE_TIME_ASSERT(find_t,sizeof(struct _find_t)==286);
>>
>> #include "dir.h"
>> COMPILE_TIME_ASSERT(ffblk,sizeof(struct ffblk)==290);
>> COMPILE_TIME_ASSERT(ffblklfn,sizeof(struct ffblklfn)==318);
>>
>> #include "coff.h"
>> COMPILE_TIME_ASSERT(exln,sizeof(struct external_lineno)==6);
>> COMPILE_TIME_ASSERT(exse,sizeof(struct external_syment)==18);
>> COMPILE_TIME_ASSERT(exau,sizeof(union external_auxent)==18);
>> COMPILE_TIME_ASSERT(exrl,sizeof(struct external_reloc)==10);
>>
>> Compiled using existing and modified headers for djgpp using gcc/g++
>> v3.4.6 and 5.1.0, no errors. I also compiled its coff.h-only parts
>> for linux (i686 gcc-4.3.0 and clang-3.4.2), osx (ppc gcc-4.0.1 and
>> x86_64 gcc-4.2.1), mingw (gcc-3.4.5), mingw-w64 (x86_64 gcc-4.5.4):
>> no errors.
>>
>> Diff for the modified headers is attached (1.patch)
>> Ideas?
>
> LGTM, thanks.
>
OK, fixed the broken pragma in dir.h as of r1.7.
Moved the packed attributes from members to structures as
of dir.h r1.8, dos.h r1.16 and coff.h r1.8.
>> On 5/13/15, Andris Pavenis (andris DOT pavenis AT iki DOT fi) <djgpp AT delorie DOT com>
>> wrote:
>> > I guess it would be a good idea to have small test in build process to
>> > verify that offsets of
>> > members are correct for structures intended for DOS calls. So build
>> > would
>> > fail if something is
>> > wrong with member packing
>> >
>> > Andris
>>
>> We can add compile-time asserts like the above to the headers: ideas?
>
> I think a test in djtst would be better.
>
> Thanks.
>
I would feel safer if the compile time asserts reside in the relevant
headers and checked every time something is compiled against them.
How about the following patch: (also attached as 3a.patch)
coff.h, dos.h, dir.h: conditionalize packed pragma to gcc < 3.
add compile time assertions to make sure of correct structure packing.
Index: include/coff.h
===================================================================
RCS file: /cvs/djgpp/djgpp/include/coff.h,v
retrieving revision 1.8
diff -u -r1.8 coff.h
--- include/coff.h 14 May 2015 16:23:05 -0000 1.8
+++ include/coff.h 14 May 2015 16:32:23 -0000
@@ -150,6 +150,9 @@
* grouping will have l_lnno = 0 and in place of physical address will be the
* symbol table index of the function name.
*/
+#if (__GNUC__ < 3)
+#pragma pack(1)
+#endif
struct external_lineno {
union {
ULONG32 l_symndx; /* function name symbol index, iff l_lnno == 0 */
@@ -157,10 +160,14 @@
} l_addr;
unsigned short l_lnno; /* line number */
} __attribute__((packed));
-
+#if (__GNUC__ < 3)
+#pragma pack()
+#endif
#define LINENO struct external_lineno
#define LINESZ sizeof(LINENO)
+/* make sure that structure packing is correct */
+typedef int _DJCHK_EXTLINENO[(LINESZ==6)*3 - 1];
/********************** SYMBOLS **********************/
@@ -169,6 +176,9 @@
#define E_FILNMLEN 14 /* # characters in a file name */
#define E_DIMNUM 4 /* # array dimensions in auxiliary entry */
+#if (__GNUC__ < 3)
+#pragma pack(1)
+#endif
struct external_syment
{
union {
@@ -184,12 +194,18 @@
unsigned char e_sclass;
unsigned char e_numaux;
} __attribute__((packed));
+#if (__GNUC__ < 3)
+#pragma pack()
+#endif
#define N_BTMASK (0xf)
#define N_TMASK (0x30)
#define N_BTSHFT (4)
#define N_TSHIFT (2)
+#if (__GNUC__ < 3)
+#pragma pack(1)
+#endif
union external_auxent {
struct {
ULONG32 x_tagndx; /* str, un, or enum tag indx */
@@ -233,11 +249,17 @@
} __attribute__((packed)) x_tv; /* info about .tv section (in
auxent of symbol .tv)) */
} __attribute__((packed));
+#if (__GNUC__ < 3)
+#pragma pack()
+#endif
#define SYMENT struct external_syment
#define SYMESZ sizeof(SYMENT)
#define AUXENT union external_auxent
#define AUXESZ sizeof(AUXENT)
+/* make sure that structure packing is correct */
+typedef int _DJCHK_EXTSYMENT[(SYMESZ==18)*3 - 1];
+typedef int _DJCHK_EXTAUXENT[(AUXESZ==18)*3 - 1];
#define _ETEXT "etext"
@@ -325,16 +347,22 @@
/********************** RELOCATION DIRECTIVES **********************/
-
+#if (__GNUC__ < 3)
+#pragma pack(1)
+#endif
struct external_reloc {
ULONG32 r_vaddr;
ULONG32 r_symndx;
unsigned short r_type;
} __attribute__((packed));
-
+#if (__GNUC__ < 3)
+#pragma pack()
+#endif
#define RELOC struct external_reloc
#define RELSZ sizeof(RELOC)
+/* make sure that structure packing is correct */
+typedef int _DJCHK_EXTRELOC[(RELSZ==10)*3 - 1];
#define RELOC_REL32 20 /* 32-bit PC-relative address */
#define RELOC_ADDR32 6 /* 32-bit absolute address */
Index: include/dir.h
===================================================================
RCS file: /cvs/djgpp/djgpp/include/dir.h,v
retrieving revision 1.8
diff -u -r1.8 dir.h
--- include/dir.h 14 May 2015 16:23:05 -0000 1.8
+++ include/dir.h 14 May 2015 16:32:23 -0000
@@ -24,8 +24,9 @@
hold the extra information. Fields marked LFN are only valid if the magic
is set to LFN32 */
-/* This is for g++ 2.7.2 and below */
+#if (__GNUC__ < 3) /* This is for g++ 2.7.2 and below */
#pragma pack(1)
+#endif
struct ffblk {
char lfn_magic[6]; /* LFN */
@@ -54,7 +55,12 @@
char fd_name[14];
} __attribute__((packed));
+#if (__GNUC__ < 3)
#pragma pack()
+#endif
+/* make sure that structure packing is correct */
+typedef int _DJCHK_FFBLK0[(sizeof(struct ffblk) ==290)*3 - 1];
+typedef int _DJCHK_FFBLK1[(sizeof(struct ffblklfn)==318)*3 - 1];
#define FA_RDONLY 1
#define FA_HIDDEN 2
Index: include/dos.h
===================================================================
RCS file: /cvs/djgpp/djgpp/include/dos.h,v
retrieving revision 1.16
diff -u -r1.16 dos.h
--- include/dos.h 14 May 2015 16:23:05 -0000 1.16
+++ include/dos.h 14 May 2015 16:32:23 -0000
@@ -214,6 +214,9 @@
};
#define dostime_t _dostime_t
+#if (__GNUC__ < 3)
+#pragma pack(1)
+#endif
struct _find_t {
char reserved[21];
unsigned char attrib;
@@ -222,7 +225,12 @@
unsigned long size;
char name[256];
} __attribute__((packed));
+#if (__GNUC__ < 3)
+#pragma pack()
+#endif
#define find_t _find_t
+/* make sure that structure packing is correct */
+typedef int _DJCHK_FIND_T[(sizeof(struct _find_t)==286)*3 - 1];
struct _diskfree_t {
unsigned short total_clusters;
--
O.S.
--001a113f284e3eb22105160d4e5d
Content-Type: application/octet-stream; name="3a.patch"
Content-Disposition: attachment; filename="3a.patch"
Content-Transfer-Encoding: base64
X-Attachment-Id: file0
Y29mZi5oLCBkb3MuaCwgZGlyLmg6IGNvbmRpdGlvbmFsaXplIHBhY2tlZCBwcmFnbWEgdG8gZ2Nj
IDwgMy4KYWRkIGNvbXBpbGUgdGltZSBhc3NlcnRpb25zIHRvIG1ha2Ugc3VyZSBvZiBjb3JyZWN0
IHN0cnVjdHVyZSBwYWNraW5nLgoKSW5kZXg6IGluY2x1ZGUvY29mZi5oCj09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT0KUkNT
IGZpbGU6IC9jdnMvZGpncHAvZGpncHAvaW5jbHVkZS9jb2ZmLmgsdgpyZXRyaWV2aW5nIHJldmlz
aW9uIDEuOApkaWZmIC11IC1yMS44IGNvZmYuaAotLS0gaW5jbHVkZS9jb2ZmLmgJMTQgTWF5IDIw
MTUgMTY6MjM6MDUgLTAwMDAJMS44CisrKyBpbmNsdWRlL2NvZmYuaAkxNCBNYXkgMjAxNSAxNjoz
MjoyMyAtMDAwMApAQCAtMTUwL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