News for hackers. Stuff that matters.
Re:Compiler Explorer by drej on Friday December 14, 2018 @05:57AM (#18679929)
Matt Godbolt is a great speaker as well. I loved this talk that included a bit about the architecture behind his Compiler Explorer. The rest of his talk is super cool as well. E.g. closed form solutions from O(n) code? Compilers are awesome. https://m.youtube.com/watch?v=bSkpMdDe4g4
Re:Compiler Explorer by mouldysammich on Friday December 14, 2018 @12:35PM (#18682671)
There is this thing that works similarly but for emacs: https://gitlab.com/jgkamat/rmsbolt It seems pretty gosh darn spicy
Re:Compiler Explorer by johnisgood on Saturday December 15, 2018 @11:02AM (#18688878)
Wow, this is amazing. Thank you!
Re:Compiler Explorer by nyrulez on Friday December 14, 2018 @10:32AM (#18681481)
This is amazing for all computer science degree courses. I wish I had this when I was learning this stuff. Sadly, I think the truth is that most profs or students won't know this platform exists.
Re:Compiler Explorer by pjmlp on Friday December 14, 2018 @01:43PM (#18683347)
Compilers have had the ability do dump Assembly since the early days, and many IDEs do support an interleaved Assembly view, so the missing teaching opportunity has been there for quite a long time.
Re:Compiler Explorer by ufo on Friday December 14, 2018 @01:47PM (#18683387)
Even then, I think the great UI in the compiler explorer still puts it apart from the others.
Re:Compiler Explorer by pjmlp on Friday December 14, 2018 @02:56PM (#18684059)
Sure, compiler explorer is a great idea, just saying that unfortunately plenty of people aren't aware of such workflows, even when the tooling has been available for so long.
Re:Compiler Explorer by kazinator on Friday December 14, 2018 @02:46PM (#18683953)
Re:Compiler Explorer by tomalpha on Friday December 14, 2018 @04:54AM (#18679691)
Nice to see this continues to get exposure. It remains awesome and every time I return to it Matt's added some new nifty feature. More please Matt!
Re:Compiler Explorer by xvilka on Friday December 14, 2018 @05:02AM (#18679732)
See also a command line tool[1] for this, written in Rust.

[1] https://github.com/ethanhs/cce

Re:Compiler Explorer by danieldk on Friday December 14, 2018 @09:35AM (#18681042)
Note that for Rust programs, there is also cargo-asm:

https://github.com/gnzlbg/cargo-asm

(I frequently use Godbolt though, it's so nice for comparing across languages.)

Re:Compiler Explorer by wyldfire on Friday December 14, 2018 @09:38AM (#18681065)
Neat. But once you're using command line tools why not just use the constituent tools used by Compiler Explorer? `objdump`, etc?
Re:Compiler Explorer by WhitneyLand on Friday December 14, 2018 @01:46PM (#18683379)
Really nice work by Matt. Haven’t seen a project before that makes some of that stuff quite so quick and simple.

Tangentially, anyone have a transpiler recommendation?

Started to look at Babel but it seems most inclined to targeting Javascript. Looking to go bidirectional between Python and a proprietary DSL.

Would have to reverse engineer the DSL grammmar I assume but it doesn’t seem very complex, so hearing of any good tooling would be interesting.

Re:Compiler Explorer by purple_ducks on Friday December 14, 2018 @11:58AM (#18682307)
Legit 10/10 for their displayed privacy policy.
Re:Compiler Explorer by kazinator on Friday December 14, 2018 @02:31PM (#18683814)
Or, in one line of shell:

  echo 'int square(int num) { return num*num; }' | gcc -S -x c - -o -
How about this: open an editor on "test.c". Then in another terminal window, run this script:

  #!/bin/sh

  rm -f test_copy.c

  while true ; do
    if [ test.c -nt test_copy.c ] ; then
      cp test.c test_copy.c
      clear
      gcc -S test_copy.c -o -
    fi
    sleep 0.3
  done
Every time you save test.c, the compiler output updates in the other shell window (within a fraction of a second).
Re:Compiler Explorer by steveklabnik on Friday December 14, 2018 @03:17PM (#18684292)
Godbolt has many more features than this. It can show you mappings from your code to the outputted asm, it can show help text on what instructions mean, you can compare multiple compilers against the same source file easily...
Re:Compiler Explorer by jokh on Friday December 14, 2018 @11:30AM (#18682011)
This would be really useful if it can be run offline. Much easier to use than writing code, compiling it with -S to produce assembly, then trawling through the assembly to look for the code you're interested in.
Re:Compiler Explorer by mshockwave on Friday December 14, 2018 @11:52AM (#18682238)
It's open source, so you can just clone the source code and run the server locally on your computer. I've been running it like this for a long time :-)
Re:Compiler Explorer by ufo on Friday December 14, 2018 @01:48PM (#18683402)
How hard was it to set up for you? Is it a small standalone thing or a beast with complex dependencies? Did you configure it to run everything locally or is it still requesting a web service to compile the programs?
Re:Compiler Explorer by je42 on Friday December 14, 2018 @06:22PM (#18685842)
i got it up and running within 30min or so.
Re:Compiler Explorer by jokh on Friday December 14, 2018 @12:20PM (#18682532)
Oh, I had no idea it was open source. Thanks!
Re:Compiler Explorer by kazinator on Friday December 14, 2018 @05:05PM (#18685281)
> Much easier to use than writing code compiling it with -S to produce assembly

In any real-world, production use cases, I will vastly prefer to "objdump -d" or "objdump -S" the executable image (which is formed from dozens, hundreds or thousands of source files, with specific compiler flags and so on). I'm not going to be feeding these source inputs into some dialog box on a website.

What you might benefit from would be a browser which can parse the output of "objdump --line-number -S <yourexecutable>" and present it in a nicer way.

E.g. all the implicated source files could be identified and loaded into multiple views/tabs, with two-way navigation between those and the disassembly tab.

Re:Compiler Explorer by kazinator on Friday December 14, 2018 @05:15PM (#18685365)
Idea: massage the "objdump --line-number -S <executable>" output into a vim quickfix list (errors.err file).

Then run vim -q.

The idea would be that all those file:line entries become navigable quickfix items: we can navigate through the quickfix items (thereby browsing the source code), and the assembly is in the quickfix window as context.

Re:Compiler Explorer by unhammer on Friday December 14, 2018 @02:58PM (#18684078)
Try https://gitlab.com/jgkamat/rmsbolt – highlights the assembly of the code-at-point: https://i.imgur.com/fAQQMJe.gif
Re:Compiler Explorer by Const-me on Friday December 14, 2018 @11:56AM (#18682272)
If you're interested in the code, put a breakpoint and launch with a debugger. In Visual C++ that literally two keypresses, F9 and F5. As a nice side effect, you can step over the assembly instructions observing how they change registers and memory.
Re:Compiler Explorer by rasjani on Friday December 14, 2018 @11:34AM (#18682062)
I haven’t really tried it but from all the exposure godbolt gets in cppcast, I think there is a way to run it locally.
Re:Compiler Explorer by sigjuice on Friday December 14, 2018 @05:05PM (#18685279)
Is there a way to set this up to have two windows? One window to type code into and the other to run my program? I have been fiddling with the UI for a while, but can't quite figure it out.
Re:Compiler Explorer by sigjuice on Friday December 14, 2018 @07:07PM (#18686060)
My bad. For some reason I thought I could actually run programs, but looks like that isn’t the case.
Re:Compiler Explorer by pjmlp on Friday December 14, 2018 @09:45AM (#18681107)
It a very nice project.

I really like how it grew to encompass any language with AOT/JIT compilers, as long as anyone is willing to support the language related tooling.

Re:Compiler Explorer by 15116 on Friday December 14, 2018 @06:56AM (#18680213)
#incluide "/etc/passwd" ?
Re:Compiler Explorer by foxrob92 on Friday December 14, 2018 @07:32AM (#18680342)
Doesn't look like it works any more.

In any case, Matt Godbolt has spoken a bit about the architecture of Compiler Explorer. Seems like he's given some thought to security.

https://www.youtube.com/watch?v=bSkpMdDe4g4

https://www.youtube.com/watch?v=nAbCKa0FzjQ

Re:Compiler Explorer by wyldfire on Friday December 14, 2018 @09:30AM (#18681009)
IIRC the main sandboxing comes from a wrapper around libc that restricts pathnames used in open() and friends. It seems reasonably well designed for its intent but probably not super difficult to escape. Certainly if the C library adds another entry point, it won't be obvious that there's a new way around.

What the Compiler Explorer has going for it in this regard is that there's very little treasure to be found once you escape. No user accounts, no passwords, no security questions, no financial transactions, etc.

Compiler Explorer doesn't execute the programs it builds, so the risk is limited to what you can convince the compiler/assembler to do on your behalf.

Re:Compiler Explorer by twic on Friday December 14, 2018 @02:10PM (#18683615)
> limited to what you can convince the compiler/assembler to do on your behalf

C++ is a not a language where i would have a lot of confidence in that limitation!

Re:Compiler Explorer by echeese on Friday December 14, 2018 @05:14PM (#18685358)
Works for me, you just gotta pass -E in the args. Also need to spell include right.
Re:Compiler Explorer by phoe-krk on Friday December 14, 2018 @06:58AM (#18680222)
Nothing out of the ordinary there. And the compiling user is not permitted to read /etc/shadow.
Re:Compiler Explorer by mattgodbolt on Friday December 14, 2018 @10:37AM (#18681522)
Exactly :) Also even if it could, it would be the `/etc/shadow` of the docker container things run in :)
Re:Compiler Explorer by kazinator on Friday December 14, 2018 @05:08PM (#18685307)
In the age of shadowed passwords, that doesn't amount to a hill of beans. You already know there is an account called root and probably other common things like daemon and www-data.
Re:Compiler Explorer by wener on Friday December 14, 2018 @08:19AM (#18680582)
Godbolt is very impressive for learning assembly, I also post this 5 days ago https://news.ycombinator.com/item?id=18635399
Re:Compiler Explorer by robertsd247 on Friday December 14, 2018 @09:14AM (#18680901)
No perl?!?!?!?
Re:Compiler Explorer by detaro on Friday December 14, 2018 @09:18AM (#18680933)
In a tool to study assembly output of compilers?
Re:Compiler Explorer by hoytech on Friday December 14, 2018 @11:24AM (#18681954)

    $ perl -MO=Concise -e 'my $v = 1234; $v *= 9876'
    a  <@> leave[1 ref] vKP/REFC ->(end)
    1     <0> enter ->2
    2     <;> nextstate(main 1 -e:1) v:{ ->3
    5     <2> sassign vKS/2 ->6
    3        <$> const[IV 1234] s ->4
    4        <0> padsv[$v:1,2] sRM*/LVINTRO ->5
    6     <;> nextstate(main 2 -e:1) v:{ ->7
    9     <2> multiply[t2] vKS/2 ->a
    7        <0> padsv[$v:1,2] sRM ->8
    8        <$> const[IV 9876] s ->9
    -e syntax OK
Re:Compiler Explorer by 0xcde4c3db on Friday December 14, 2018 @09:36AM (#18681046)
This tool is really built for AOT native code generation. Does Perl have a compiler like that? The ones I've heard of are all some flavor of compiling to bytecode followed by an interpreter or JIT.
Re:Compiler Explorer by hoytech on Friday December 14, 2018 @11:26AM (#18681966)
For perl5 there have been several attempts at AOT native code compilers. For example: http://rperl.org
Re:Compiler Explorer by singularity2001 on Friday December 14, 2018 @10:23AM (#18681399)
that's such a wonderful tool, for which I have 0 usage