BUG: Fix Issue #2422, including a test.

It turns out that _end is an undocumented global symbol, maybe in the C++
standard library which has a value of 0.

Declaring it as static is enough to avoid the problem.
Use `const` instead, so that the compiler can optimize the constant variable.