Internal error: out of range error when building custom bootloader

I'm attempting to build a custom bootloader for an Arduino Mega2560 with Arduino IDE 1.8.0 under windows 7.

In platform.txt I've appended ",--section-start=.text=0x3E000" to compiler.c.elf.flags, which should put the bootloader in the last 8k of the 256k flash.

When I verify the application I get the following warnings:

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/main.cpp:47: warning: internal error: out of range error

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/main.cpp:47: warning: internal error: out of range error

This behavior is reproduceable with an empty sketch, the only modification being the additional linker option.

void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:

}

The linker command is below:

"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-gcc" -w -Os -g -flto -fuse-linker-plugin -Wl,--gc-sections,--section-start=.text=0x3E000,--relax -mmcu=atmega2560  -o "C:\Users\username\AppData\Local\Temp\arduino_build_249361/sketch_jan05a.ino.elf" "C:\Users\username\AppData\Local\Temp\arduino_build_249361\sketch\sketch_jan05a.ino.cpp.o" "C:\Users\username\AppData\Local\Temp\arduino_build_249361/core\core.a" "-LC:\Users\username\AppData\Local\Temp\arduino_build_249361" -lm

The line that the linker is complaining about from main.cpp is:

if (serialEventRun) serialEventRun();

serialEventRun is declared as a weak symbol.

Without the "--section-start=.text=0x3E000", the sketch compiled without warnings. Also, relocating the .text section anywhere upto 0x20000 allows the sketch to be compiled without warnings.

Any ideas on how to avoid the warnings? Is there something wrong with the way I am trying to compile a bootloader?

I still don't understand the reason for the linker error, however, I was able to work around it by commenting out the following line in main.cpp

if (serialEventRun) serialEventRun();