This is an archive of the discontinued LLVM Phabricator instance.

[ELF] - Make ASSERT() return Dot instead of evaluated value.
ClosedPublic

Authored by grimar on Feb 20 2017, 8:37 AM.

Details

Summary

Currently we fail with "unable to move location counter backward" in scripts that
assign ASSERT to Dot.

Previously ASSERT we implemented earlier returned expression value.
Ex:

. = ASSERT(0x100);

would set Dot to 0x100

Documentation does not say anything about this behavior:
"ASSERT(exp, message) Ensure that exp is non-zero. If it is zero, then exit the linker with an error code, and print message."

As far I know form of assert when it is assigned to Dot was used for compatibility with very old GNU ld whick required it.
Some scripts in the wild, including linux kernel scripts use ASSERTs at the end for checks, like:

<many script code here>
/*
 * Build-time check on the image size:
 */
. = ASSERT((_end - _text <= (512 * 1024 * 1024)), "kernel image bigger than KERNEL_IMAGE_SIZE");

Since we error out moving backward now, I thing it is reasonable just to change behavior to return Dot. That way ASSERT will be unable
to move it backward. Anyways since that form was implemented just for compatibility, we probably should not really care what does
it return.

That fixes issue I am observing now when trying to use reproduce for vmlinux,

Diff Detail

Event Timeline

grimar created this revision.Feb 20 2017, 8:37 AM
ruiu accepted this revision.Feb 20 2017, 6:08 PM

LGTM

test/ELF/linkerscript/locationcountererr2.s
7

Please make a test as simple as possible. You can replace 0x10 > 0x1 with 1.

This revision is now accepted and ready to land.Feb 20 2017, 6:08 PM
tpimh added a subscriber: tpimh.Feb 20 2017, 11:29 PM
This revision was automatically updated to reflect the committed changes.