This is an archive of the discontinued LLVM Phabricator instance.

Retrieve command line arguments and environment correctly on FreeBSD
ClosedPublic

Authored by dim on Mar 2 2016, 3:21 PM.

Details

Summary

Recently I saw the test TestCases/Posix/print_cmdline.cc failing on
FreeBSD, with "expected string not found in input". This is because
asan could not retrieve the command line arguments properly.

In lib/sanitizer_common/sanitizer_linux.cc, this is taken care of by
the GetArgsAndEnv() function, but it uses __libc_stack_end to get at
the required data. This variable does not exist on BSDs; the regular
way to retrieve the arguments and environment information is via the
kern.ps_strings sysctl.

I added this functionality in sanitizer_linux.cc, as a separate #ifdef
block in GetArgsAndEnv(). Also, ReadNullSepFileToArray() becomes
unused due to this change. (It won't work on FreeBSD anyway, since
/proc is not mounted by default.)

Diff Detail

Event Timeline

dim updated this revision to Diff 49680.Mar 2 2016, 3:21 PM
dim retitled this revision from to Retrieve command line arguments and environment correctly on FreeBSD.
dim updated this object.
dim added reviewers: kcc, emaste, davide.
dim added a subscriber: llvm-commits.
dim added a reviewer: joerg.Mar 2 2016, 3:22 PM
davide edited edge metadata.Mar 2 2016, 3:45 PM

LGTM. Probably the Asan owner should sign-off this anyway.

lib/sanitizer_common/sanitizer_linux.cc
451

Can you please add a comment explaining what this function is doing for first-readers who don't know sysctl&friends ?

davide accepted this revision.Mar 2 2016, 3:45 PM
davide edited edge metadata.
This revision is now accepted and ready to land.Mar 2 2016, 3:45 PM
dim updated this revision to Diff 49850.Mar 4 2016, 1:37 PM
dim edited edge metadata.

Add an explanatory comment. Also, ping. :-)

dim closed this revision.Mar 10 2016, 12:26 PM