Skip to content

Commit 468edb9

Browse files
committed
work around GCC name mangling bug
It seems that older versions of GCC (4.0 and older, at least) generate assembly files with duplicate symbols for function templates which differ only by the attributes of the templated types. Newer versions have no such problem, but we need to support both, hence the workaround in this commit of using a dedicated, non-template "alias" function where we previously used "cast<alias_t>".
1 parent 2e0770b commit 468edb9

File tree

4 files changed

+36
-18
lines changed

4 files changed

+36
-18
lines changed

src/common.h

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,15 @@ typedef uint64_t uintptr_t;
5959
# error "unsupported architecture"
6060
# endif
6161

62-
typedef intptr_t alias_t;
62+
namespace vm {
63+
64+
inline intptr_t&
65+
alias(void* p, unsigned offset)
66+
{
67+
return *reinterpret_cast<intptr_t*>(static_cast<uint8_t*>(p) + offset);
68+
}
69+
70+
} // namespace vm
6371

6472
#else // not _MSC_VER
6573

@@ -88,7 +96,16 @@ typedef intptr_t alias_t;
8896
# error "unsupported architecture"
8997
# endif
9098

91-
typedef intptr_t __attribute__((__may_alias__)) alias_t;
99+
namespace vm {
100+
101+
typedef intptr_t __attribute__((__may_alias__)) intptr_alias_t;
102+
inline intptr_alias_t&
103+
alias(void* p, unsigned offset)
104+
{
105+
return *reinterpret_cast<intptr_alias_t*>(static_cast<uint8_t*>(p) + offset);
106+
}
107+
108+
} // namespace vm
92109

93110
#endif // not _MSC_VER
94111

src/machine.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2145,8 +2145,8 @@ class HeapClient: public Heap::Client {
21452145
memcpy(dst, src, n * BytesPerWord);
21462146

21472147
if (hashTaken(t, src)) {
2148-
cast<alias_t>(dst, 0) &= PointerMask;
2149-
cast<alias_t>(dst, 0) |= ExtendedMark;
2148+
alias(dst, 0) &= PointerMask;
2149+
alias(dst, 0) |= ExtendedMark;
21502150
extendedWord(t, dst, base) = takeHash(t, src);
21512151
}
21522152
}
@@ -2781,7 +2781,7 @@ allocate3(Thread* t, Allocator* allocator, Machine::AllocationType type,
27812781

27822782
memset(o, 0, sizeInBytes);
27832783

2784-
cast<alias_t>(o, 0) = FixedMark;
2784+
alias(o, 0) = FixedMark;
27852785

27862786
t->m->fixedFootprint += total;
27872787

@@ -2796,7 +2796,7 @@ allocate3(Thread* t, Allocator* allocator, Machine::AllocationType type,
27962796

27972797
memset(o, 0, sizeInBytes);
27982798

2799-
cast<alias_t>(o, 0) = FixedMark;
2799+
alias(o, 0) = FixedMark;
28002800

28012801
return o;
28022802
}

src/machine.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1878,8 +1878,9 @@ setObjectClass(Thread*, object o, object value)
18781878
{
18791879
cast<object>(o, 0)
18801880
= reinterpret_cast<object>
1881-
(reinterpret_cast<alias_t>(value)
1882-
| (reinterpret_cast<alias_t>(cast<object>(o, 0)) & (~PointerMask)));
1881+
(reinterpret_cast<intptr_alias_t>(value)
1882+
| (reinterpret_cast<intptr_alias_t>
1883+
(cast<object>(o, 0)) & (~PointerMask)));
18831884
}
18841885

18851886
inline const char*
@@ -2094,19 +2095,19 @@ setType(Thread* t, Machine::Type type, object value)
20942095
inline bool
20952096
objectFixed(Thread*, object o)
20962097
{
2097-
return (cast<alias_t>(o, 0) & (~PointerMask)) == FixedMark;
2098+
return (alias(o, 0) & (~PointerMask)) == FixedMark;
20982099
}
20992100

21002101
inline bool
21012102
objectExtended(Thread*, object o)
21022103
{
2103-
return (cast<alias_t>(o, 0) & (~PointerMask)) == ExtendedMark;
2104+
return (alias(o, 0) & (~PointerMask)) == ExtendedMark;
21042105
}
21052106

21062107
inline bool
21072108
hashTaken(Thread*, object o)
21082109
{
2109-
return (cast<alias_t>(o, 0) & (~PointerMask)) == HashTakenMark;
2110+
return (alias(o, 0) & (~PointerMask)) == HashTakenMark;
21102111
}
21112112

21122113
inline unsigned
@@ -2237,7 +2238,7 @@ markHashTaken(Thread* t, object o)
22372238

22382239
ACQUIRE_RAW(t, t->m->heapLock);
22392240

2240-
cast<alias_t>(o, 0) |= HashTakenMark;
2241+
alias(o, 0) |= HashTakenMark;
22412242
t->m->heap->pad(o);
22422243
}
22432244

src/util.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,32 +66,32 @@ inline object
6666
getTreeNodeValue(Thread*, object n)
6767
{
6868
return reinterpret_cast<object>
69-
(cast<alias_t>(n, TreeNodeValue) & PointerMask);
69+
(alias(n, TreeNodeValue) & PointerMask);
7070
}
7171

7272
inline void
7373
setTreeNodeValue(Thread* t, object n, object value)
7474
{
75-
alias_t red = cast<alias_t>(n, TreeNodeValue) & (~PointerMask);
75+
intptr_t red = alias(n, TreeNodeValue) & (~PointerMask);
7676

7777
set(t, n, TreeNodeValue, value);
7878

79-
cast<alias_t>(n, TreeNodeValue) |= red;
79+
alias(n, TreeNodeValue) |= red;
8080
}
8181

8282
inline bool
8383
treeNodeRed(Thread*, object n)
8484
{
85-
return (cast<alias_t>(n, TreeNodeValue) & (~PointerMask)) == 1;
85+
return (alias(n, TreeNodeValue) & (~PointerMask)) == 1;
8686
}
8787

8888
inline void
8989
setTreeNodeRed(Thread*, object n, bool red)
9090
{
9191
if (red) {
92-
cast<alias_t>(n, TreeNodeValue) |= 1;
92+
alias(n, TreeNodeValue) |= 1;
9393
} else {
94-
cast<alias_t>(n, TreeNodeValue) &= PointerMask;
94+
alias(n, TreeNodeValue) &= PointerMask;
9595
}
9696
}
9797

0 commit comments

Comments
 (0)