mirror of
https://github.com/gbdev/rgbds.git
synced 2026-10-03 10:45:37 +00:00
Fix FLOATING in linker scripts conflicting with section constraints (#2148)
This commit is contained in:
1 parent
6a08e809b5
commit
03c71ced93
7 files changed
+87
-7
No files matched your search
+34
-7
@@ -267,9 +267,8 @@ void layout_PlaceSection(std::string const &name, bool isOptional) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (activeBankIdx == UINT32_MAX) {
|
// Enforce a bank if one is active, but leave any existing constraint alone.
|
||||||
section->isBankFixed = false;
|
if (activeBankIdx != UINT32_MAX) {
|
||||||
} else {
|
|
||||||
uint32_t bank = activeBankIdx + typeInfo.firstBank;
|
uint32_t bank = activeBankIdx + typeInfo.firstBank;
|
||||||
if (section->isBankFixed && bank != section->bank) {
|
if (section->isBankFixed && bank != section->bank) {
|
||||||
scriptError(
|
scriptError(
|
||||||
@@ -296,11 +295,11 @@ void layout_PlaceSection(std::string const &name, bool isOptional) {
|
|||||||
section->org
|
section->org
|
||||||
);
|
);
|
||||||
} else if (section->isAlignFixed && (org & section->alignMask) != section->alignOfs) {
|
} else if (section->isAlignFixed && (org & section->alignMask) != section->alignOfs) {
|
||||||
uint8_t alignment = std::countr_one(section->alignMask);
|
int alignment = std::countr_one(section->alignMask);
|
||||||
scriptError(
|
scriptError(
|
||||||
"The linker script assigns section \"%s\" to address $%04" PRIx16
|
"The linker script assigns section \"%s\" to address $%04" PRIx16
|
||||||
", but that would be ALIGN[%" PRIu8 ", %" PRIu16
|
", but that would be ALIGN[%d, %" PRIu16
|
||||||
"] instead of the requested ALIGN[%" PRIu8 ", %" PRIu16 "]",
|
"] instead of the requested ALIGN[%d, %" PRIu16 "]",
|
||||||
name.c_str(),
|
name.c_str(),
|
||||||
org,
|
org,
|
||||||
alignment,
|
alignment,
|
||||||
@@ -331,10 +330,38 @@ void layout_PlaceSection(std::string const &name, bool isOptional) {
|
|||||||
org += section->size;
|
org += section->size;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
section->isAddressFixed = false;
|
if (section->isAddressFixed) {
|
||||||
|
if ((section->org & floatingAlignMask) != floatingAlignOffset) {
|
||||||
|
int alignment = std::countr_one(floatingAlignMask);
|
||||||
|
scriptError(
|
||||||
|
"The linker script aligns floating section \"%s\" to ALIGN[%d, %" PRIu16
|
||||||
|
"], but it was already at address $%04" PRIx16 " which has ALIGN[%d, %" PRIu16
|
||||||
|
"]",
|
||||||
|
name.c_str(),
|
||||||
|
alignment,
|
||||||
|
floatingAlignOffset,
|
||||||
|
section->org,
|
||||||
|
alignment,
|
||||||
|
static_cast<uint16_t>(section->org & floatingAlignMask)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else if (uint16_t commonMask = section->alignMask & floatingAlignMask;
|
||||||
|
section->isAlignFixed
|
||||||
|
&& (section->alignOfs & commonMask) != (floatingAlignOffset & commonMask)) {
|
||||||
|
scriptError(
|
||||||
|
"The linker script aligns floating section \"%s\" to ALIGN[%d, %" PRIu16
|
||||||
|
"], but it already has requested ALIGN[%d, %" PRIu16 "]",
|
||||||
|
name.c_str(),
|
||||||
|
std::countr_one(floatingAlignMask),
|
||||||
|
floatingAlignOffset,
|
||||||
|
std::countr_one(section->alignMask),
|
||||||
|
section->alignOfs
|
||||||
|
);
|
||||||
|
} else if (!section->isAlignFixed || floatingAlignMask > section->alignMask) {
|
||||||
section->isAlignFixed = floatingAlignMask != 0;
|
section->isAlignFixed = floatingAlignMask != 0;
|
||||||
section->alignMask = floatingAlignMask;
|
section->alignMask = floatingAlignMask;
|
||||||
section->alignOfs = floatingAlignOffset;
|
section->alignOfs = floatingAlignOffset;
|
||||||
|
}
|
||||||
|
|
||||||
floatingAlignOffset = (floatingAlignOffset + section->size) & floatingAlignMask;
|
floatingAlignOffset = (floatingAlignOffset + section->size) & floatingAlignMask;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
DEF address EQU $100
|
||||||
|
|
||||||
|
SECTION "code", ROM0[address]
|
||||||
|
|
||||||
|
Start::
|
||||||
|
jp Start
|
||||||
|
|
||||||
|
assert STARTOF("code") == address
|
||||||
|
assert Start == address
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
ROM0
|
||||||
|
FLOATING
|
||||||
|
"code"
|
||||||
Whitespace-only changes.
@@ -0,0 +1,11 @@
|
|||||||
|
SECTION "fixed", ROM0[$1234]
|
||||||
|
|
||||||
|
SECTION "aligned", ROMX, ALIGN[8, 42]
|
||||||
|
|
||||||
|
SECTION "less aligned", ROMX, ALIGN[4, 1]
|
||||||
|
|
||||||
|
SECTION "more aligned", ROMX, ALIGN[8, 1]
|
||||||
|
|
||||||
|
SECTION "address compatible", ROMX[$4463]
|
||||||
|
|
||||||
|
SECTION "align compatible", ROMX, ALIGN[8, 99]
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
ROM0
|
||||||
|
FLOATING
|
||||||
|
ALIGN 8, 42
|
||||||
|
"fixed"
|
||||||
|
ROMX 1
|
||||||
|
FLOATING
|
||||||
|
ALIGN 8, 23
|
||||||
|
"aligned"
|
||||||
|
ROMX 2
|
||||||
|
FLOATING
|
||||||
|
ALIGN 8, 2
|
||||||
|
"less aligned"
|
||||||
|
ROMX 3
|
||||||
|
FLOATING
|
||||||
|
ALIGN 4, 2
|
||||||
|
"more aligned"
|
||||||
|
ROMX 4
|
||||||
|
FLOATING
|
||||||
|
ALIGN 8, 99
|
||||||
|
"address compatible"
|
||||||
|
"align compatible"
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
error: The linker script aligns floating section "fixed" to ALIGN[8, 42], but it was already at address $1234 which has ALIGN[8, 52]
|
||||||
|
at linkerscript-floating-conflict.link(4)
|
||||||
|
error: The linker script aligns floating section "aligned" to ALIGN[8, 23], but it already has requested ALIGN[8, 42]
|
||||||
|
at linkerscript-floating-conflict.link(8)
|
||||||
|
error: The linker script aligns floating section "less aligned" to ALIGN[8, 2], but it already has requested ALIGN[4, 1]
|
||||||
|
at linkerscript-floating-conflict.link(12)
|
||||||
|
error: The linker script aligns floating section "more aligned" to ALIGN[4, 2], but it already has requested ALIGN[8, 1]
|
||||||
|
at linkerscript-floating-conflict.link(16)
|
||||||
|
Linking failed with 4 errors
|
||||||
Reference in new issue
Block a user