How to download and build nacl-clang source code?

119 views
Skip to first unread message

KnoooW

unread,
Aug 24, 2015, 4:13:47 AM8/24/15
to Native-Client-Discuss
hi all,
  My purpose is to do some modification on NEXE compiler. It's said nacl-clang is MUCH easier THAN gcc-compiler.
So I want to download it and do some development. BUT, I only find this help page I (seems old ?)


And FOR SOME REASON, I can download most of nacl source, except the directory 'native_client/toolchain_build/src', 
I guess this may be the clang source code place, while I cannot get it through 'gclient sync'.

So, I wonder If there are some place I can directly download all source code used to do development on nacl-clang compiler ?
the best may be some .tgz or .tar packages ! 

Some guidance on compiling these sources will also be very helpful !


thanks !


 

Derek Schuff

unread,
Aug 24, 2015, 12:44:39 PM8/24/15
to Native-Client-Discuss
The PNaCl/nacl-clang sources are not synced by gclient; Instead when you run toolchain_build/toolchain_build_pnacl.py with the --sync flag, it will download the sources before building them. There are no canonical tgz files right now, so toolchain_build_pnacl.py is the easiest way to get the sources.

toolchain_build_pnacl.py is also the way to compile LLVM and the rest of the toolchain. You can start with the document you linked (and if you have questions or suggestions on how to improve it, let me know!). If it were me I would start with a clean build of everything in the toolchain using toolchain_build_pnacl.py (without the sandboxed translator) and then if you want to hack on LLVM you can edit the sources, then go directly to LLVM's build directory (e.g. cd toolchain_build/out/llvm_x86_64_linux_work) and run 'make' directly there to iterate.

--
You received this message because you are subscribed to the Google Groups "Native-Client-Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to native-client-di...@googlegroups.com.
To post to this group, send email to native-cli...@googlegroups.com.
Visit this group at http://groups.google.com/group/native-client-discuss.
For more options, visit https://groups.google.com/d/optout.

KnoooW

unread,
Aug 25, 2015, 9:22:16 PM8/25/15
to Native-Client-Discuss, dsc...@google.com
hi  Derek,
  thanks for your explanation, I have downloaded the toolchain source and build almost everyone ok.(except when it searches for the .git in native_client directory, I deleted .git sometime),
But, I think I have downloaded what I need !, I only need llvm-clang x86_64 compiler and newlib library and some relative libs.

BUT, after I compiled it, I have two doubts:
(1) As I only need clang-llvm-x86_64-nacl compiler (not pexe, i need nexe), So I tried to compile one hello world .c with the newly build clang compiler.
But I don't know where the compiler is. So I scaned all the directories in out directory, the following ones may be what I want.

binutils_x86_x86_64_linux_install
compiler_rt_bc_x86_64_bc_install
core_sdk_libs_x86_64_install
driver_x86_64_linux_install
libcxx_x86_64_bc_install
libcxx_x86_64_install
libcxx_x86_64_linux_install
libgcc_eh_x86_64_install
libs_support_translator_x86_64_install
libs_support_x86_64_bc_install
libs_support_x86_64_install
llvm_x86_64_linux_install
newlib_x86_64_bc_install
newlib_x86_64_install

I use compiler in llvm_x86_64_linux_install/bin/x86_64-nacl-clang, But when I compile .c with it, I find it needs come basic .o file such as crt1.o, crtbeginT.o and so on.
Although I find all the .o files in above directories with 'find .. -name xxx', and I copied them to my builddir then compile ok .
but this is somewhat informal, I think there should have some scripts or some option for one to auto collect all the basic files for one to compile !!
Can you kindly figure it out ?

(2) What I want to do is to modify the core code generation part. for example, I would like to add one instruction before every load/store instruction.
Can you kindly figure the llvm code part which I should focus on ? 
I have searched llvm/clang for string 'nacl/NACL', BUT, i didn't find any key parts.

NOW, I want to deep into this, try to expanding mem space larger than 4G ! 



Thanks !


在 2015年8月25日星期二 UTC+8上午12:44:39,Derek Schuff写道:
The PNaCl/nacl-clang sources are not synced by gclient; Instead when you run toolchain_build/toolchain_build_pnacl.py with the --sync flag, it will download the sources before building them. There are no canonical tgz files right now, so toolchain_build_pnacl.py is the easiest way to get the sources.

toolchain_build_pnacl.py is also the way to compile LLVM and the rest of the toolchain. You can start with the document you linked (and if you have questions or suggestions on how to improve it, let me know!). If it were me I would start with a clean build of everything in the toolchain using toolchain_build_pnacl.py (without the sandboxed translator) and then if you want to hack on LLVM you can edit the sources, then go directly to LLVM's build directory (e.g. cd toolchain_build/out/llvm_x86_64_linux_work) and run 'make' directly there to iterate.

On Mon, Aug 24, 2015 at 1:13 AM KnoooW <3n4...@gmail.com> wrote:
hi all,
  My purpose is to do some modification on NEXE compiler. It's said nacl-clang is MUCH easier THAN gcc-compiler.
So I want to download it and do some development. BUT, I only find this help page I (seems old ?)


And FOR SOME REASON, I can download most of nacl source, except the directory 'native_client/toolchain_build/src', 
I guess this may be the clang source code place, while I cannot get it through 'gclient sync'.

So, I wonder If there are some place I can directly download all source code used to do development on nacl-clang compiler ?
the best may be some .tgz or .tar packages ! 

Some guidance on compiling these sources will also be very helpful !


thanks !


 

--
You received this message because you are subscribed to the Google Groups "Native-Client-Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to native-client-discuss+unsub...@googlegroups.com.

Derek Schuff

unread,
Aug 26, 2015, 12:14:42 PM8/26/15
to KnoooW, Native-Client-Discuss
Basically everything that ends up in the toolchain_build/out/{component}_install directories is a component of the toolchain (either a host executable component such as binutils or llvm, or a target library such as newlib_le32 for PNaCl or newlib_x86_64 for clang). The builds of the components are isolated, but in order to use the toolchain you basically just need to copy the contents of all of those components together into the same directory. For the official packaging we use a script called package_version.py (if you read the sources of our buildbot script in buildbot/buildbot_pnacl_toolchain.py you'll see how it works), but the easiest way to get set up locally is to use the --install flag of toolchain_build_pnacl.py which will copy the contents of each built package to the directory you specify after it builds it. So for example if you want to test the toolchain using SCons, you could do something like
./toolchain_build/toolchain_build_pnacl.py --verbose --clobber --install=toolchain/linux_x86/pnacl_newlib_raw

the toolchain/linux_x86/pnacl_newlib_raw directory is where the SCons testing scripts expect to find the nacl toolchain.

 
(2) What I want to do is to modify the core code generation part. for example, I would like to add one instruction before every load/store instruction.
Can you kindly figure the llvm code part which I should focus on ? 
I have searched llvm/clang for string 'nacl/NACL', BUT, i didn't find any key parts.

NOW, I want to deep into this, try to expanding mem space larger than 4G ! 



There are 2 relevant places where instruction sequences are modified for NaCl: the first is lib/Target/X86/X86NaClRewritePass.cpp (and its ARM equivalent) which operates on the MachineInstr IR and turns sandboxable instructions into special pseudo-instruction opcodes, most of which are defined in lib/Target/X86/X86InstrNaCl.td. Then, lib/Target/X86/MCTargetDesc/X86MCNaCl.cpp (which operates on the MC assembly-layer IR) turns those pseudo-instructions into the bundle-locked sequences required for NaCl SFI.

KnoooW

unread,
Aug 26, 2015, 9:24:11 PM8/26/15
to Native-Client-Discuss, 3n4...@gmail.com, dsc...@google.com
Thanks for your kindly reply, Derek!
they are what I want , 
last time I searched the llvm_work dir, so I didn't find NACL realative files :)


在 2015年8月27日星期四 UTC+8上午12:14:42,Derek Schuff写道:
Reply all
Reply to author
Forward
0 new messages