Link libgcc.a before shared libraries (especially libc.so).

[cherry-picked from internal master]

Change-Id: I53d19754d0d40e9ca2f3d043001cc77e39e5d795
port a bunch of synergye's magic flags from cfX
picked from Mustaavalkosta