Skip to content

Commit 29ba55c

Browse files
committed
MC/Mach-O: Allow emission of relocations for variables in some more cases.
llvm-svn: 130520
1 parent b9c2b6c commit 29ba55c

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

llvm/lib/MC/MachObjectWriter.cpp

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ class MachObjectWriter : public MCObjectWriter {
550550
// Add the local offset, if needed.
551551
if (Base != &SD)
552552
Value += Layout.getSymbolOffset(&SD) - Layout.getSymbolOffset(Base);
553-
} else if (Symbol->isInSection()) {
553+
} else if (Symbol->isInSection() && !Symbol->isVariable()) {
554554
// The index is the section ordinal (1-based).
555555
Index = SD.getFragment()->getParent()->getOrdinal() + 1;
556556
IsExtern = 0;
@@ -1028,17 +1028,17 @@ class MachObjectWriter : public MCObjectWriter {
10281028
// FIXME!
10291029
report_fatal_error("FIXME: relocations to absolute targets "
10301030
"not yet implemented");
1031-
} else if (SD->getSymbol().isVariable()) {
1032-
int64_t Res;
1033-
if (SD->getSymbol().getVariableValue()->EvaluateAsAbsolute(
1034-
Res, Layout, SectionAddress)) {
1035-
FixedValue = Res;
1036-
return;
1031+
} else {
1032+
// Resolve constant variables.
1033+
if (SD->getSymbol().isVariable()) {
1034+
int64_t Res;
1035+
if (SD->getSymbol().getVariableValue()->EvaluateAsAbsolute(
1036+
Res, Layout, SectionAddress)) {
1037+
FixedValue = Res;
1038+
return;
1039+
}
10371040
}
10381041

1039-
report_fatal_error("unsupported relocation of variable '" +
1040-
SD->getSymbol().getName() + "'");
1041-
} else {
10421042
// Check whether we need an external or internal relocation.
10431043
if (doesSymbolRequireExternRelocation(SD)) {
10441044
IsExtern = 1;
@@ -1129,17 +1129,17 @@ class MachObjectWriter : public MCObjectWriter {
11291129
// FIXME: Currently, these are never generated (see code below). I cannot
11301130
// find a case where they are actually emitted.
11311131
Type = macho::RIT_Vanilla;
1132-
} else if (SD->getSymbol().isVariable()) {
1133-
int64_t Res;
1134-
if (SD->getSymbol().getVariableValue()->EvaluateAsAbsolute(
1135-
Res, Layout, SectionAddress)) {
1136-
FixedValue = Res;
1137-
return;
1132+
} else {
1133+
// Resolve constant variables.
1134+
if (SD->getSymbol().isVariable()) {
1135+
int64_t Res;
1136+
if (SD->getSymbol().getVariableValue()->EvaluateAsAbsolute(
1137+
Res, Layout, SectionAddress)) {
1138+
FixedValue = Res;
1139+
return;
1140+
}
11381141
}
11391142

1140-
report_fatal_error("unsupported relocation of variable '" +
1141-
SD->getSymbol().getName() + "'");
1142-
} else {
11431143
// Check whether we need an external or internal relocation.
11441144
if (doesSymbolRequireExternRelocation(SD)) {
11451145
IsExtern = 1;

0 commit comments

Comments
 (0)