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

aws-c-common: emit unwind information for RISC-V #155719

Merged
merged 1 commit into from
Jan 26, 2022

Conversation

ius
Copy link
Contributor

@ius ius commented Jan 19, 2022

Motivation for this change

The test suite for aws-c-common fails on RISC-V due to libgcc backtrace() returning 0, which in turn triggers a segfault due to underflow (see awslabs/aws-c-common#873).

This is fairly easy to reproduce:

#include <execinfo.h>
#include <stdio.h>

int main(int argc, char **argv[])
{
	void *buf[128];
	int n;

	n = backtrace(buf, 128);
	printf("backtrace() = %d\n", n);

	return 0;
}

Compile:

# riscv64-unknown-linux-gnu-gcc test.c && ./a.out 
backtrace() = 0

Passing -fasynchronous-unwind-tables helps. Note gcc_s needs to be explicitly linked to avoid runtime dlopen() failure:

# riscv64-unknown-linux-gnu-gcc -fasynchronous-unwind-tables test.c -lgcc_s && ./a.out 
backtrace() = 3
Notes

This appears to be gcc default for AArch64: [AArch64] Turn on -fasynchronous-unwind-tables and -funwind-tables by default.
and on x86_64 it works out of the box as well, so an alternate approach would be to patch the toolchain instead. If this doesn't turn out to be a widespread issue, just patching up this package works for me.

Resolution

Pass -fasynchronous-unwind-tables in CFLAGS for RISC-V.

This fixes functionality which depends on backtrace() and enables
running the test suite without error.

Things done
  • Built on platform(s)
    • x86_64-linux
    • riscv64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandbox = true set in nix.conf? (See Nix manual)
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 22.05 Release Notes (or backporting 21.11 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
    • (Release notes changes) Ran nixos/doc/manual/md-to-db.sh to update generated release notes
  • Fits CONTRIBUTING.md.

Pass -fasynchronous-unwind-tables in CFLAGS for RISC-V.

This fixes functionality which depends on backtrace() and enables
running the test suite without error.
@ius ius requested review from zhaofengli and oxalica January 19, 2022 21:08
@ofborg ofborg bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux labels Jan 19, 2022
@veprbl veprbl merged commit 8ccbba4 into NixOS:master Jan 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants