This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2012年01月26日 13:34 by skrah, last changed 2022年04月11日 14:57 by admin. This issue is now closed.
| Messages (13) | |||
|---|---|---|---|
| msg152007 - (view) | Author: Stefan Krah (skrah) * (Python committer) | Date: 2012年01月26日 13:34 | |
In non-debug mode the read_null test fails with clang-3.0: ====================================================================== FAIL: test_disable (test.test_faulthandler.FaultHandlerTests) ---------------------------------------------------------------------- Traceback (most recent call last): File "/usr/home/stefan/hg/cpython/Lib/test/test_faulthandler.py", line 235, in test_disable self.assertNotEqual(exitcode, 0) AssertionError: 0 == 0 clang "optimizes" the undefined behavior into a simple assignment: $ ~/usr/bin/clang --version clang version 3.0 (tags/RELEASE_30/final) Target: x86_64-unknown-freebsd9.0 Thread model: posix $ $ cat read_null.c #include <stdio.h> int main(void) { int *x = NULL, y; y = *x; printf("%d\n", y); return 0; } $ $ ~/usr/bin/clang -Wall -O0 -g -o read_null read_null.c $ ./read_null Segmentation fault: 11 (core dumped) $ ~/usr/bin/clang -Wall -O3 -g -o read_null read_null.c $ ./read_null 0 |
|||
| msg152008 - (view) | Author: STINNER Victor (vstinner) * (Python committer) | Date: 2012年01月26日 14:02 | |
Can you try x = (int *)1; instead of x = NULL; ? |
|||
| msg152011 - (view) | Author: Stefan Krah (skrah) * (Python committer) | Date: 2012年01月26日 14:32 | |
STINNER Victor <report@bugs.python.org> wrote: > Can you try x = (int *)1; instead of x = NULL; ? This works. - I must say that I find this new behavior of clang slightly dangerous... |
|||
| msg152025 - (view) | Author: STINNER Victor (vstinner) * (Python committer) | Date: 2012年01月26日 17:10 | |
There was a similar bug which was declared as a vulnerability in the Linux kernel: http://isc.sans.edu/diary.html?storyid=6820 GCC has an option to disable this optimization: -fno-delete-null-pointer-checks. |
|||
| msg152101 - (view) | Author: STINNER Victor (vstinner) * (Python committer) | Date: 2012年01月27日 16:19 | |
Oh, you can also try something else: add the volatile keyword. |
|||
| msg152130 - (view) | Author: Stefan Krah (skrah) * (Python committer) | Date: 2012年01月27日 22:15 | |
Yes, volatile works, too. That's probably the best solution. |
|||
| msg152132 - (view) | Author: Stefan Krah (skrah) * (Python committer) | Date: 2012年01月27日 22:17 | |
Well, to be completely unambiguous. This works: diff -r d2cf8a34ddf9 Modules/faulthandler.c --- a/Modules/faulthandler.c Thu Jan 26 00:15:07 2012 -0800 +++ b/Modules/faulthandler.c Fri Jan 27 23:16:27 2012 +0100 @@ -943,7 +943,7 @@ static PyObject * faulthandler_read_null(PyObject *self, PyObject *args) { - int *x = NULL, y; + volatile int *x = NULL, y; int release_gil = 0; if (!PyArg_ParseTuple(args, "|i:_read_null", &release_gil)) |
|||
| msg152148 - (view) | Author: Jesús Cea Avión (jcea) * (Python committer) | Date: 2012年01月28日 03:48 | |
That makes "x" and "y" volatile. |
|||
| msg152154 - (view) | Author: Stefan Krah (skrah) * (Python committer) | Date: 2012年01月28日 10:35 | |
Jes??s Cea Avi??n <report@bugs.python.org> wrote: > That makes "x" and "y" volatile. Well yes, but is that a problem? |
|||
| msg152165 - (view) | Author: Jesús Cea Avión (jcea) * (Python committer) | Date: 2012年01月28日 15:37 | |
Nothing. I just read the sourcecode :-). I would add an "y=0" in the declaration too, just for aestetics. |
|||
| msg152278 - (view) | Author: Roundup Robot (python-dev) (Python triager) | Date: 2012年01月29日 23:07 | |
New changeset f71249d785d6 by Victor Stinner in branch 'default': Issue #13874: read_null() of faulthandler uses volatile to avoid optimisation http://hg.python.org/cpython/rev/f71249d785d6 |
|||
| msg152279 - (view) | Author: STINNER Victor (vstinner) * (Python committer) | Date: 2012年01月29日 23:07 | |
Does my commit fix the issue? |
|||
| msg152291 - (view) | Author: Stefan Krah (skrah) * (Python committer) | Date: 2012年01月29日 23:55 | |
STINNER Victor <report@bugs.python.org> wrote: > Does my commit fix the issue? Yes, perfectly. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:57:26 | admin | set | github: 58082 |
| 2012年01月30日 01:44:15 | vstinner | set | status: open -> closed resolution: fixed |
| 2012年01月29日 23:55:01 | skrah | set | messages: + msg152291 |
| 2012年01月29日 23:07:55 | vstinner | set | messages: + msg152279 |
| 2012年01月29日 23:07:36 | python-dev | set | nosy:
+ python-dev messages: + msg152278 |
| 2012年01月28日 15:37:51 | jcea | set | messages: + msg152165 |
| 2012年01月28日 10:35:03 | skrah | set | messages: + msg152154 |
| 2012年01月28日 03:48:11 | jcea | set | messages: + msg152148 |
| 2012年01月27日 22:17:32 | skrah | set | messages: + msg152132 |
| 2012年01月27日 22:15:57 | skrah | set | messages: + msg152130 |
| 2012年01月27日 16:19:48 | vstinner | set | messages: + msg152101 |
| 2012年01月27日 15:05:46 | jcea | set | nosy:
+ jcea |
| 2012年01月26日 17:10:49 | vstinner | set | messages: + msg152025 |
| 2012年01月26日 14:32:20 | skrah | set | messages: + msg152011 |
| 2012年01月26日 14:02:53 | vstinner | set | messages: + msg152008 |
| 2012年01月26日 13:34:46 | skrah | create | |