If we have such expression in linker script: __TESTVAL1__ = 1; __TESTVAL2__ = 2; __TESTVAL__ = DEFINED ( __TESTVAL1__ ) ? (__TESTVAL1__) : (__TESTVAL2__); in final Map file output it always shows "else" branch: 0x00000001 __TESTVAL1__ = 0x1 0x00000002 __TESTVAL2__ = 0x2 0x00000002 __TESTVAL__ = DEFINED (__TESTVAL1__)?__TESTVAL1__:__TESTVAL2__ While disassembling final ELF shows: 00000001 g *ABS* 00000000 __TESTVAL__ 00000001 g *ABS* 00000000 __TESTVAL1__ 00000002 g *ABS* 00000000 __TESTVAL2__
The problem is that the defined state isn't tracked during printing of the map, due to not passing the entire assignment expression to exp_fold_tree.
The master branch has been updated by Alan Modra <amodra@sourceware.org>: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=6a84624340dd19ccd927d91d79e0ece135c6d846 commit 6a84624340dd19ccd927d91d79e0ece135c6d846 Author: Alan Modra <amodra@gmail.com> Date: Mon Jan 28 09:59:29 2019 +1030 PR24008, Wrong value of ternary expression in map file PR 24008 * ldexp.h (lang_phase_type): Add lang_fixed_phase_enum. * ldexp.c (fold_name): Move expld.assign_name check later to avoid an extra lookup. (exp_fold_tree_1): When lang_fixed_phase_enum, don't change symbol values, and don't clear expld.assign_name. * ldlang.c (lang_map): Set expld.phase to lang_fixed_phase_enum. (print_assignment): Resolve entire assignment expression. Don't access symbol u.def unless symbol is defined.
Fixed
The binutils-2_32-branch branch has been updated by Nick Clifton <nickc@sourceware.org>: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=12542b2a6da22f5ab2fd4043e8bded1444ed42ad commit 12542b2a6da22f5ab2fd4043e8bded1444ed42ad Author: Nick Clifton <nickc@redhat.com> Date: Tue Jan 29 11:20:02 2019 +0000 Fix error in expression evalutation in linker output maps. PR 24008 * ldexp.h (lang_phase_type): Add lang_fixed_phase_enum. * ldexp.c (fold_name): Move expld.assign_name check later to avoid an extra lookup. (exp_fold_tree_1): When lang_fixed_phase_enum, don't change symbol values, and don't clear expld.assign_name. * ldlang.c (lang_map): Set expld.phase to lang_fixed_phase_enum. (print_assignment): Resolve entire assignment expression. Don't access symbol u.def unless symbol is defined.
The master branch has been updated by H.J. Lu <hjl@sourceware.org>: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=ad0f979c9df2cc3fba1f120c5e7f39e35591ed07 commit ad0f979c9df2cc3fba1f120c5e7f39e35591ed07 Author: H.J. Lu <hjl.tools@gmail.com> Date: Tue Jan 29 06:07:42 2019 -0800 Add a testcase for PR ld/24008 PR ld/24008 * testsuite/ld-scripts/defined.exp: Run pr24008. * testsuite/ld-scripts/pr24008.d: New file. * testsuite/ld-scripts/pr24008.map: Likewise. * testsuite/ld-scripts/pr24008.s: Likewise. * testsuite/ld-scripts/pr24008.t: Likewise.
Verified using binutils-2_32-branch
The master branch has been updated by Alan Modra <amodra@sourceware.org>: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=4249a53cce8651061092d666e5df06492cb91cf1 commit 4249a53cce8651061092d666e5df06492cb91cf1 Author: Alan Modra <amodra@gmail.com> Date: Wed Feb 6 17:26:23 2019 +1030 Fix some ldscripts/pr24008 fails These targets were all failing due to extra symbols. pdp11-dec-aout +FAIL: ld-scripts/pr24008 powerpc-aix5.1 +FAIL: ld-scripts/pr24008 powerpc-aix5.2 +FAIL: ld-scripts/pr24008 rs6000-aix4.3.3 +FAIL: ld-scripts/pr24008 rs6000-aix5.1 +FAIL: ld-scripts/pr24008 rs6000-aix5.2 +FAIL: ld-scripts/pr24008 Some fails remain, those I saw were segfaults or assertion fails that indicate target bugs. PR ld/24008 * testsuite/ld-scripts/pr24008.d: Pass with extra target defined symbols.