Gentoo Archives: gentoo-user

From: Jorge Almeida <jjalmeida@×××××.com>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] memset_s
Date: Wed, 15 Nov 2017 07:22:29
Message-Id: CAKpSnp+E6BK86V6GCN6DfZ3dWecFQOpiQum+UBuS4f3oz9v8FA@mail.gmail.com
In Reply to: Re: [gentoo-user] memset_s by R0b0t1
1 On Tue, Nov 14, 2017 at 8:42 PM, R0b0t1 <r030t1@×××××.com> wrote:
2 > On Tue, Nov 14, 2017 at 11:36 AM, Jorge Almeida <jjalmeida@×××××.com> wrote:
3 >> On Fri, Nov 10, 2017 at 12:09 PM, Jorge Almeida <jjalmeida@×××××.com> wrote:
4 >>
5 >>> http://www.daemonology.net/blog/2014-09-04-how-to-zero-a-buffer.html
6 >>>
7 >>>
8 >>>>> Of course, what would really solve the optimize-into-oblivion problem
9 >>>>> is a pragma that when invoked on a particular block of code (maybe
10 >>>>> only a function definition) would tell the compiler to do what the
11 >>>>> programmer says rather than viewing a function as a kind of black box.
12 >>>>>
13 >>>>
14 >>
15 >> It seems a solution exists with gcc:
16 >>
17 >> https://stackoverflow.com/questions/2219829/how-to-prevent-gcc-optimizing-some-statements-in-c
18 >>
19 >> The last reply:
20 >>
21 >> void __attribute__((optimize("O0"))) foo(unsigned char data) {
22 >> // unmodifiable compiler code
23 >> }
24 >>
25 >> Any comments, anyone? Yes, it's gcc, but IMO this should be in the
26 >> language itself. Am I right to assume this is a poorly known feature
27 >> of gcc?
28 >> It allows, for example, to replace sensitive data by random bytes,
29 >> existing system callls like memset() or getrandom() can be used as
30 >> they are, no reimplementation needed.
31 >>
32 >
33 > Very interesting. I imagine the opinion of the standards committee
34 > would be that the variability in code generation precludes a standard
35 > interface to optimization controls. This might seem unusual, but
36 > languages with a very controlling standard (like Java or C#) are a new
37 > concept.
38
39 Well, we'll have to stick to gcc (or other compilers with the same
40 feature). OTOH, boldness doesn't seem to be the comittee's most
41 salient feature.
42
43 >
44 > What I am wondering about is if C code which uses
45 > __attribute__((optimize(...))) is against Gentoo package standards and
46 > would have to be removed from the Portage tree.
47 >
48
49
50 You can set your optimization preferences in make.conf, and still an
51 ebuild will override them if deemed unsafe. What would be the
52 difference?
53
54 Cheers
55
56 Jorge