HNHacker News
TopNewBestAskShowJobs

xorblurb

416 karma · joined October 22, 2013

submissionscomments
xorblurb··on Depressing and faintly terrifying days for the C standard [pdf]
That's, given the question, is a really moronic answer.

There are means to apply the modern approach of optimizations beyond O0 on C without importing all kind of UB from the language level. You just have to actually proove the properties you want to rely on, instead of relying on wishful "UB => authorized by the standard => programmer fault if anything goes bad" thinking.

And promoting local variable to registers CERTAINLY NOT depends on language level UB. It would be permitted by the as-if general rule even if anything prevented it to happen in the first place, which is not the case. You don't have to have an address if nobody wants it and random pointers haver never been required to allow access to all objects, especially those who might never have an address at all. Plus nobody ever expected that anyway. People expect 2s complement. Or at least something that can not result in nasal daemons, and given C history, something that matches what the processor does. So 2s complements is at least not utterly stupid. So conflating the two is dishonest to the highest point -- except maybe if the only intended audience of the C language is now experts who e.g. write compilers. What a bright future this would be.

Hell, we dropped the hypothetical flat memory model even without strict aliasing for maybe 20 years (and probably 30, to be honest), and this had NEVER caused the kind of issues we are talking about. So don't pretend it did, just to dismiss the real issues. So ok even then it was actually probably informal as hell and in some ways worse for experts, but the amount of exploited UB was also WAY smaller. Quantity matters in this area. And context too. Do you want secure OR fast embedded systems? I would prefer reasonably secure and reasonably fast. Certainly NOT fast to execute and exploit, or more probably fast to crash pathetically.

You know very well that compiling in O0 is not going to happen in prod on tons on projects.

Don't dismiss real concerns with false "solutions", especially when mixed with proofs of your misunderstanding of the situation.

xorblurb··on Depressing and faintly terrifying days for the C standard [pdf]
Those kind of discussions have various effects, some of which I believe to be far from moot.

First, they permit that some people even take notice about this situation. Few developers read the standard and even less write it or follow the discussions to change it (are they even open?) or write a compiler for it. The rationales are not even tracked [1]. It actually would be insanely hard to get a good understanding of those subjects by e.g. just reading the standard, without having those kind of discussions on forums typically used by more devs than just a few dozens of compiler writers...

[1]: but while I'm thinking about it, an impressive independent book as been written by Derek Jones: The New C Standard: An Economic and Cultural Commentary http://www.knosof.co.uk/cbook/cbook.html

xorblurb··on Depressing and faintly terrifying days for the C standard [pdf]
Could have been (should, in some -most?- cases) implementation defined.
xorblurb··on Depressing and faintly terrifying days for the C standard [pdf]
Microbenchmark can be very misleading compared to real impact in real programs. Still, the gains allowed by UB of signed overflow (when you are lucky enough that this transformation is actually correct in the context of what the original programmer had in mind...) are positive and probably measurable even in real programs, or if hardly measurable, maybe they at least permit a few percent of whole system perf improvement when using SMT processors. But they are more suited to other programming language than C, and actually yes, in C++ (and probably in most languages at this point) it is better both of code readability (most important!) and performance (nice to have, but very secondary compared to code readability) to use for each constructs compared to maintaining an index yourself.

Technically there is no overflow flag to reset, it is just that some CPU instruction sets do not support indexing with a 32 bit register when using 64 bits addressing, so you have to insert an extra sign extend instruction if you want to support 2s-complement signed overflow on 32 bits indexes. So you typically already don't have any cost if your indexes are already size_t/ptrdiff_t, but ptrdiff_t signed overflow is still UB according to the C standard, which is also a shame, because it allows for far less interesting "optimizations" at this point (maybe a + w >= a --> true if w is positive, but that's actually typically dangerous, because that was historically what was used to check for overflow at source level, and now the compiler is suppressing all the checks!)

So all of that really only are trade-offs, and in the modern age (with e.g. a security picture that is kind of worrying, etc.) some people are arguing that this was a terrible idea to use this approach so carelessly, in their opinion. Most experts now think that no non-trivial codebase exist with no potential UB in it, so it is not just rants all around, some even are working on the mathematical model of the llvm optimizer to make it actually sound (for now even internally, it seems that it is not -- so unfortunately with this approach of optimisation for now there is no mathematical justification as for why the optimizations performed are actually correct even with the hypothesis of strict conformance to the C standard, so I let you imagine what happens in practice when almost no program is actually conforming...)

xorblurb··on Depressing and faintly terrifying days for the C standard [pdf]
(Technically it is not really an overflow check the problem in that case, but typically more the need of extending an index from 32 to 64 bits because the instruction set in 64 bits do not support indexing with 32 bits index)

If you want perf in a critical tight loop that has been identified by some profiling, you can easily optimize it yourself (and yes, typically bumping the counter type to size_t / ptrdiff_t is enough to optimize, but the advantage you have is that you can actually check that this transformation is sound according of the intent of the programmer of the original code, whether in the context of the C programming language, the compiler doesn't even try to check that itself, it merely blindly makes the hypothesis that there is absolutely no UB ever, and to hell if there actually was)

But anyway we have since invented sane languages in which we BOTH have safety, and the capability to apply that kind of transformations that have a small but positive perf impact. In some cases it is actually way easier to optimize using those approaches from safe languages than from mostly unchecked ones culturally full of type punning and other kind of insanity (like C is), and this is not even a recent discovery: there is a reason for why number crunching stuck to Fortran. So C should be kind of considered as a legacy programming language, at this point. A very important one for historical reasons, but one should think twice before writing new critical infrastructure with it...

xorblurb··on Depressing and faintly terrifying days for the C standard [pdf]
Large pieces of sw have been able to switch some plateform specific code to other compilers (chrome for windows comes to mind).

This is probably way smaller than the whole Windows, but I would not be surprised if some MS dev are already internally compiling some of their components with clang for their own dev/testing (even if just for extra warnings, etc.)

And a major part of the work of the MSVC team today seems to be about standard compliance.

But yes, I do not really expect that they switch, and actually they probably don't even have the beginning of a serious reason to do so. This is not even a case of NIH. Their compiler derives from an ancient codebase and has been continuously maintained for several decades. They "invented" it. The only modern serious competition (that cares enough about Windows compat and some of their specific techs) has been started way after... They probably also have all kind of patents and whatnot about some security mitigations that are implemented by collaboration between the generated code and (the most modern versions of) low level parts of the Windows platform.

xorblurb··on Depressing and faintly terrifying days for the C standard [pdf]
Sane compilers should do that. The standard should eventually specify that. But before it does, you can not write portable code that expect that (but hopefully once enough compilers are sane but before the standard is updated, you can write code that targets only the compilers, and don't give a fuck about the other broken garbage that try to trap the world)
xorblurb··on Intel Announces Optane DIMMs
Modern DMA is cache coherent (maybe except if you opt-out of it? I'm not even sure you can). It is still costly though.
xorblurb··on Intel Announces Optane DIMMs
It's also integrated to new instructions to flush things and wait for them to be made persistent.
xorblurb··on Intel Announces Optane DIMMs
I think you can still do non burst transactions and even set masks on byte granularity for writes. Classic processors probably don't do that, though.
xorblurb··on I miss Windows Phone
VS2012 (I guess this was the compiler, maybe it has been upgraded after) had a quite limited support of C++ 11.

Only starting with VS2015 (and then maybe even update 2 IIRC) we had what we can call C++ 11 (for the purpose of not having to port code for it, or such port to be easy, so missing 1 or 2 language and library features can be OK, but missing half of them: less so).

xorblurb··on The Little Book of Semaphores (2016) [pdf]
This seems like an interesting book but a few points are dangerous, especially if it is used for teaching.

1. Concurrent access to a variable out of a critical section is qualified as not being dangerous. This actually can't be decided without knowing about the memory model you are considering, and both in the general case and in practical implementations (C++) this is UB.

2. This sentence is maybe only trying to be funny, but discouraging formal proofs in 2016 can very well end up borderline criminal (depending on the application): "The only alternative is to examine the code carefully and “prove” that it is correct. I put “prove” in quotation marks because I don’t mean, necessarily, that you have to write a formal proof (although there are zealots who encourage such lunacy)."

Especially if this is stated right after a rather simple algorithm.

I can absolutely not recommend a book about a critical topic, which contains that kind of defects.

xorblurb··on Poland's oldest university denies Google's right to patent Polish coding concept
I will never ever buy the "we are forced to do evil things for the greater good" argument.

Especially behind real inventors' back.

You can't just dictate your own distorted ethical vision just because you are too big.

Edit: plus I don't even give a shit if they limit their use of this patent to defend themselves against competitor claims. Clearly even in this limited case this patent still would have (a very good) value, so at least propose the REAL inventor to patent it and sell ultra limited right for that purpose for a few millions. Then this would be kind of ethical.

xorblurb··on Poland's oldest university denies Google's right to patent Polish coding concept
HN turns rabid, rightfully so. Even with so-called good motives, which are not even proven. And to be clear, in no way there can be a good motive here: their pledge is limited to Free and Open Source Software, its not even sure this pledge is binding, and EVEN if they really do limit their use of this patent (would have it been misattributed to Google by error), I don't think they would EVER pay the real inventor the value they gain from obtain from having it in their stockpile, even less if they do want to use it after another giant attack them.
xorblurb··on Why PS4 downloads are so slow
Of course if you can do that, it's really good. However, sometimes you need low latency.
xorblurb··on Why PS4 downloads are so slow
That very page makes me think device drivers don't choose their DIRQL. Any more precise pointer to how they can do that?
xorblurb··on Windows Subsystem for Linux on Windows Server
Traditional NT personalities were about the mechanism details.

Otherwise it is very current in operating systems to have a common kernel running different kind of userspace using different API - so of course there are some similarities, but only because it would be completely impossible not to have some.

xorblurb··on Why PS4 downloads are so slow
Needing to wake up usermode is not necessarily an insurmountable obstacle; under Linux you can use a PREEMPT config. Storming a network card having unwanted consequences can also be mitigated: under Linux you have some network device driver that use an hybrid interrupt/polling approach with the NAPI. Combining both should theoretically allow a system to generate sound smoothly in the described conditions.
xorblurb··on Why PS4 downloads are so slow
Windows does not really have interrupt priorities IIRC. It kind of sort of have some, but the applicative code (device driver included) can't chose at which level they run their ISR, so its quite random whether or not the ISR you prefer should preempt others.

Plus typically general purpose OSes don't map hw interrupt priorities mechanisms to their own priorities (and very soon the hw interrupt controllers do not even know whether an ISR is running or not). I believe neither Linux nor Windows can benefit from hw assistance for interrupt priorities (and they mainly don't care at sw level anyway)

xorblurb··on Windows Subsystem for Linux on Windows Server
Except WSL has little in common with traditional NT personalities. Traditional NT personalities were a false good idea, and have been a failure in the long term, especially to run Unix workloads -- however this jugement is easy with insight -- when it came out traditional NT personalities were quite interesting.
xorblurb··on Devirtualization in LLVM and Clang
I've seen some speculative inlining happening even without LTO (so obviously, in the same TU) with GCC.
xorblurb··on Chromium Windows builds now use Clang by default
For me, personally? I occasionally can write that kind of stuff.
xorblurb··on Lenovo ThinkPad X1 Carbon review
I replaced my Thinkpad by an XPS15 with a small fear that I would regret the Thinkpad, and I absolutely not. Under Windows, the Dell software is far better than the one of Lenovo (far less bloated, and far more discret).

I thought that I would regret the Thinkpad keyboard, but the keyboard of the XPS is actually not bad at all (well, the Thinkpad one better, but the XPS is still largely ok for me).

The only thing that I clearly regret are the lack of dedicated Page-up/Page-down keys. This is even ridiculous given there are empty space next to the arrow keys where they could have been put (same place as on the Thinkpad). Well, I can live with that.

xorblurb··on Chromium Windows builds now use Clang by default
> Unless there's an instruction you need that doesn't have an intrinsic or you're writing something like a spin lock where instruction ordering is critical and a compiler barrier for some reason is not sufficient, there's no reason to ever write assembly.

So there are reasons to write code in assembly language.

xorblurb··on Devirtualization in LLVM and Clang
A virtual call on a modern processor is typically not very costly. Too much inlining, OTOH, can be (if it generates bloated code that trashes your cache)
xorblurb··on On C-optimizing compilers removing code that has undefined behavior
> The contents of padding are unspecified after a write; reading it is not UB.

Ok so like I said: "depending of the [effective] type maybe reading an uninitialized byte will be UB, or maybe not, depending of how that byte was in a field of a type or just alignement... "

If I understand correctly this is so insane (to treat those that are UB in that context as effectively UB) that I still have no word.

I absolutely do not want to use a compiler made by people who consider that that situation is OK or even just tolerable for potential gains, regardless of the speedup you could obtain (even at 1000%, I just don't want it -- the risks are way too high)

EDIT: I reread and I think I misunderstood. This is not as bad as I thought, but this is extremely complex and I guess compiler bugs will happen (or have already?) in this area. [ Also what is the relationship with extensions? (like pre-standard or even standard explicit extra alignments...) ]

xorblurb··on On C-optimizing compilers removing code that has undefined behavior
I might actually end up doing that.

But honestly what a waste of resources. I would prefer to be able to work on topics that are not problems created by a recent shift of view of how compiler should be designed and optimize, shift that is for the worst IMO.

And yep I know the reason in the current design for why it is not always easy. That's why I added the caveat that maybe they should be changed.

But then you can not just says that all the users criticizing and "trivializing" the problem are in the wrong and do not know what they are talking about. First, most of the discussion I've seen either points at technical justification of why those crazy optim should not be done, be it for safety, possibility of real optimizations by the programmers (and to compare, I'm not impress about the capability of compilers to take poor code and to transform it to somehow less poor code, especially when the language in question is C, that always required mastering); or points to discussions of compiler authors who are borderline insane (when you see them discussion about how technically the standards would allow to not consider uint8_t and char as alias, and they ask themselves if they could not "optimize" more thanks to that, you clearly understand they have completely lost it, and that things will end up badly); or points to bugs "exposed" by that class of optims (I would even say introduced, because 1) when your binary have been OK on all your target platforms for a few decades, and a new compiler come and break it for a technicality, it can be argued that regardless of said technicality the problem is mainly with the compiler; and 2) compilers compromise e.g. for technically invalid benchmarks, so they have no credibility when they don't take into account major breakage in major software, they are just acting like spoiled child who just want to do what they want regardless of the consequences).

What is never addressed by C/C++ compiler authors and their fan base is why the "nonportable" part of the standard is not taken into consideration anymore. This was the original spirit of UB. NOT: "this will permit EXTRA optimization in abstract compiler code"; the only "optim" were because of differences between target processors, and leaving things UB could yield a better mapping to the instruction sets (a trivial mapping) and it was considered that the programmer knew about them, and could use them when needed.

Now there is no mapping anymore. We all have to target the common denominator of all the existing target past, present, even dead ones. The result is a very very very poor language. Unsuitable to more and more things.

xorblurb··on On C-optimizing compilers removing code that has undefined behavior
I might actually end up doing that.

But honestly what a waste of resources. I would prefer to be able to work on topics that are not problems created by a recent shift of view of how compiler should be designed and optimize, shift that is for the worst IMO.

And yep I know the reason in the current design for why it is not always easy. That's why I added the caveat that maybe they should be changed.

But then you can not just says that all the users criticizing and "trivializing" the problem are in the wrong and do not know what they are talking about. First, most of the discussion I've seen either points at technical justification of why those crazy optim should not be done, be it for safety, possibility of real optimizations by the programmers (and to compare, I'm not impress about the capability of compilers to take poor code and to transform it to somehow less poor code, especially when the language in question is C, that always required mastering); or points to discussions of compiler authors that are borderline insane (when you see them discussion about how technically the standards would allow to not consider uint8_t and char as alias, a

xorblurb··on On C-optimizing compilers removing code that has undefined behavior
Nope. The age of the sufficiently "advanced" (actually: retarded?) compiler was only theoretical during most of the lifetime of C, and UB were actually defined mostly because of differences between processors, NOT compilers. Compilers were faster thanks to their backend.

The standard even says: "undefined behavior: behavior, upon use of a nonportable or erroneous program construct or of erroneous data, for which this International Standard imposes no requirements"

However, today, you should act as if the nonportable part of this statement don't exist anymore, and act as if ALL UB are absolutely forbidden and result in the worst non-deterministic consequences, in all cases and regardless of your actual target. Meaning that today on e.g. x86, if you use a mainstream compiler, you ARE limited by some of the limitations of e.g. some obscure outdated DSPs.

And this is likely impossible to check in a non-trivial program.

So just use another language. C for serious purposes is dead. (some projects that started in that language continue to be developed in it, but given the security issues it creates, this will become unacceptable in a not too far future; so don't wait it is too late to switch: lead that movement.)

xorblurb··on On C-optimizing compilers removing code that has undefined behavior
> The standard can't mandate a diagnostic for undefined behaviour, because it's not always possible to determine if behaviour is undefined.

Yet that argument is stupid if we are talking about compilers issuing warnings for the UB they "detect", because by definition they have detected them. It might not be possible when it does not work exactly like that in some cases, but at least before removing some code, this is desirable.

It might also not be easy given the current internal design of compilers, but then I argue those design should be changed, because it is just too dangerous.

Page 1 of 8Next →