This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Relative expressions and ASSERT


Kazu has discovered a really perverse behavior of linker script
processing.  Consider this script:

SECTIONS
{
	.section : {
	  ASSERT ((main & 1) == 0, "In-section 0");
	  ASSERT ((main & 1) == 1, "In-section 1");
	}
	ASSERT ((main & 1) == 0, "Out-section 0")
	ASSERT ((main & 1) == 1, "Out-section 1")
}

It seems like two of those asserts must trigger on any program - but
it's not so.  In fact, neither of the In-section messages is printed
for my test (anything with 'main' will do).

Why?  Well, because both "1" and "0" are interpreted as relative to
".section".  So it becomes ASSERT ((main & (.section+1)) ==
(.section+0)).

There's a special exception that makes this work for + (and sometimes
-).  The code is in fold_binary.

IMO, it would be plausible to extend this exception to at least
bitwise operators.  But the == case has me stumped.  If "foo = 0" is
going to assign a relative value of 0 to foo, then it's odd for foo == 0
to not use a relative value of 0 too.

Thoughts?  Just Don't Do This inside an output section?

-- 
Daniel Jacobowitz
CodeSourcery


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]