5241 – dmd: ABI breakage/regression (TypeInfo.toString() returns partially corrupted string)

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 5241 - dmd: ABI breakage/regression (TypeInfo.toString() returns partially corrupted string)
Summary: dmd: ABI breakage/regression (TypeInfo.toString() returns partially corrupted...
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D1 (retired)
Hardware: Other All
: P2 regression
Assignee: No Owner
URL:
Keywords: patch, wrong-code
Depends on:
Blocks:
Reported: 2010年11月19日 08:19 UTC by nfxjfg
Modified: 2011年02月11日 03:01 UTC (History)
2 users (show)

See Also:


Attachments
Add an attachment (proposed patch, testcase, etc.)

Note You need to log in before you can comment on or make changes to this issue.
Description nfxjfg 2010年11月19日 08:19:30 UTC
At some point, both dmd and Phobos1 added a new member to TypeInfo_Struct: m_flags.
The way dmd handles this causes an ABI breakage: dmd will use the _calculated_ size of the struct to calculate the offset of the name string. After that, dmd _unconditionally_ writes the new m_flags field, and writes it at the same offset where the name string is supposed to start.
As a result, TypeInfo names for structs are broken. The first 4 items of typeid(somestruct).toString() will contain garbage. I'm not really sure why after these 4 bytes, the expected string starts. Either I got it wrong, or the backend data segment writer does strange things?
The problem doesn't appear if the object.d[i] contains the proper m_align. E.g. compare:
http://www.dsource.org/projects/phobos/browser/branches/phobos-1.x/phobos/object.d#L141
http://www.dsource.org/projects/tango/browser/trunk/object.di#L163 (WARNING: BSD LICENSED CODE)
Comment 1 nfxjfg 2010年11月19日 08:20:24 UTC
(In reply to comment #0)
> At some point, both dmd and Phobos1 added a new member to TypeInfo_Struct:
> m_flags.
Damn, that should be m_align.
Comment 2 nfxjfg 2010年11月19日 08:45:57 UTC
Lazy patch:
diff --git a/idgen.c b/idgen.c
index 023d8a9..c0cfc0b 100644
--- a/idgen.c
+++ b/idgen.c
@@ -232,6 +232,8 @@ Msgtable msgtable[] =
 // varargs implementation
 { "va_argsave_t", "__va_argsave_t" },
 { "va_argsave", "__va_argsave" },
+
+ { "m_align" },
 };
 
 
diff --git a/typinf.c b/typinf.c
index 906795a..ab9d87b 100644
--- a/typinf.c
+++ b/typinf.c
@@ -593,8 +593,11 @@ void TypeInfoStructDeclaration::toDt(dt_t **pdt)
 // uint m_flags;
 dtdword(pdt, tc->hasPointers());
 
- // uint m_align;
- dtdword(pdt, tc->alignsize());
+ if (Type::typeinfostruct->search(NULL, Id::m_align, 0))
+ {
+ // uint m_align;
+ dtdword(pdt, tc->alignsize());
+ }
 
 #if DMDV2
 // xgetMembers


AltStyle によって変換されたページ (->オリジナル) /