Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

i486 toolchain (and maybe others) fail with -fPIE -fstack-protector-all #45

Closed
rofl0r opened this issue Nov 3, 2014 · 12 comments
Closed

Comments

@rofl0r
Copy link
Collaborator

rofl0r commented Nov 3, 2014

test.c

int main() {return 0;}
i486-linux-musl-gcc test.c -fPIE -fstack-protector-all
/tmp/ccEkagdJ.o: In function `main':
test.c:(.text+0x28): undefined reference to `__stack_chk_fail_local'
/home/rofl/musl-cross-4.8.3/i486-linux-musl/lib/gcc/i486-linux-musl/4.8.3/../../../../i486-linux-musl/bin/ld: a.out: hidden symbol `__stack_chk_fail_local' isn't defined
/home/rofl/musl-cross-4.8.3/i486-linux-musl/lib/gcc/i486-linux-musl/4.8.3/../../../../i486-linux-musl/bin/ld: final link failed: Bad value
collect2: error: ld returned 1 exit status

interestingly, the gcc build is aware of the need of libssp_nonshared.a and creates it from ssp-local.c, and it even installs it into lib/.
however, it fails to add it to its linker invocation when it's needed.

i486-linux-musl-gcc test.c -fPIE -fstack-protector-all -lssp_nonshared

works.
alpine linux uses the following patch for the same issue:
http://git.alpinelinux.org/cgit/aports/tree/main/gcc/gcc-4.8-musl-libssp.patch

@rofl0r
Copy link
Collaborator Author

rofl0r commented Nov 11, 2014

@bradfa
Copy link
Contributor

bradfa commented Jan 30, 2015

I've tested x86_64, mips, arm (hardfloat, v7a), and i486 with current git master (09bb1b9). Only i486 seems to have this compile-time issue. I have not tested that the resulting binaries actually run.

For example, on the mips output, readelf shows:

 Global entries:
   Address     Access  Initial Sym.Val. Type    Ndx Name
  004109b0 -32720(gp) 00000000 00000000 FUNC    UND __register_frame_info
  004109b4 -32716(gp) 00000000 00000000 NOTYPE  UND _Jv_RegisterClasses
  004109b8 -32712(gp) 00400900 00400900 FUNC    UND __libc_start_main
  004109bc -32708(gp) 00000000 00000000 NOTYPE  UND _ITM_deregisterTMCloneTable
  004109c0 -32704(gp) 00000000 00000000 NOTYPE  UND _ITM_registerTMCloneTable
  004109c4 -32700(gp) 00000000 00000000 FUNC    UND __deregister_frame_info
  004109c8 -32696(gp) 004008f0 004008f0 FUNC    UND __stack_chk_fail
  004109cc -32692(gp) 00000000 00000000 OBJECT  UND __stack_chk_guard

I assume this is the desired result

@GregorR
Copy link
Owner

GregorR commented Feb 11, 2015

OK, the patch SEEMS harmless. ssp_nonshared shouldn't hurt if no-stack-protector is used, since it doesn't actually pull in anything fingers crossed. As such I've integrated the Alpine patch directly. Revision c57e607a5a5d of musl-cross.

@GregorR GregorR closed this as completed Feb 11, 2015
@GregorR
Copy link
Owner

GregorR commented Feb 11, 2015

No, cancel that. I wasn't doing a full bootstrapping build to test (I already had the target directory filled). This patch breaks bootstrapping. This... is frustrating :). In the interest of getting something released, I'm just going to revoke the patch for 1.1.6. Reinvestigation required later.

@GregorR GregorR reopened this Feb 11, 2015
rofl0r added a commit to sabotage-linux/sabotage that referenced this issue May 6, 2015
this causes the cross-build to fail on i386 due to
GregorR/musl-cross#45

additionally it's against sabotage's philosophy that the user
makes the decision which CFLAGS are added and which not, and not
the software author.

the user can still add -fstack-protector-all to his CFLAGS in
his /etc/butch-optflags.sh if he wants to.
@soul9
Copy link

soul9 commented Jun 17, 2015

@soul9
Copy link

soul9 commented Jun 18, 2015

While it does not break bootstrapping it introduces a bug where static linking fails with stack-protector. I am investigating.

soul9 added a commit to soul9/musl-cross that referenced this issue Jun 20, 2015
soul9 added a commit to soul9/musl-cross that referenced this issue Jun 20, 2015
@soul9
Copy link

soul9 commented Jun 20, 2015

With this and sabotage's musl patched I can bootstrap the cross-toolchain and build every package in sabotage stage1 with stack-protector-all, except gcc4.7.4 where I need to disable stack-protector entirely.
credits to dalias and nsz on freenode#musl
Edit: I've just tested it with libressl and it still errors out with hidden symbol `__stack_chk_fail_local' isn't defined

@soul9
Copy link

soul9 commented Jun 22, 2015

the libressl issue can be fixed by adding -lssp_nonshared to LDFLAGS. investigating further.

soul9 added a commit to soul9/musl-cross that referenced this issue Jun 24, 2015
@GregorR
Copy link
Owner

GregorR commented Jul 25, 2015

Any conclusions?

@GregorR
Copy link
Owner

GregorR commented Jul 25, 2015

Oh, probably in that other ticket :)

soul9 added a commit to soul9/musl-gcc-patches that referenced this issue Jul 26, 2015
  this alloms musl-cross compiler to be built with ssp support.
  together with a patch in musl upstream (not in any stable release yet)
    http://git.musl-libc.org/cgit/musl/commit/?id=55d061f031085f24d138664c897791aebe9a2fab
    this fixes GregorR/musl-cross#51 and
    GregorR/musl-cross#45
@soul9
Copy link

soul9 commented Jul 26, 2015

and now at a third location too

GregorR pushed a commit to GregorR/musl-gcc-patches that referenced this issue Jul 26, 2015
  this alloms musl-cross compiler to be built with ssp support.
  together with a patch in musl upstream (not in any stable release yet)
    http://git.musl-libc.org/cgit/musl/commit/?id=55d061f031085f24d138664c897791aebe9a2fab
    this fixes GregorR/musl-cross#51 and
    GregorR/musl-cross#45
@GregorR
Copy link
Owner

GregorR commented Jul 26, 2015

I like to spread the issue around :)

@GregorR GregorR closed this as completed Jul 26, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants