CensoredUsername/dynasm-rs

Tutorial doesn't compile

Closed this issue · 1 comments

I copied the initial tutorial code from here, (which is the same as the one in the tree) into a "cargo init --bin" tree, added dependencies on dynamic 0.2.3, installed nightly rust, and ran cargo build. I got the following compile errors:

   Compiling test v0.1.0 (/home/me/test)                                                                                                                 
warning: unused `#[macro_use]` import                                                                                                                         
 --> src/main.rs:4:1                                                                                                                                          
  |                                                                                                                                                           
4 | #[macro_use]                                                                                                                                              
  | ^^^^^^^^^^^^                                                                                                                                              
  |                                                                                                                                                           
  = note: #[warn(unused_imports)] on by default                                                                                                               
                                                                                                                                                              
error[E0599]: no method named `global_label` found for type `std::result::Result<dynasmrt::x64::Assembler, std::io::Error>` in the current scope              
  --> src/main.rs:16:5                                                                                                                                        
   |                                                                                                                                                          
16 | /     dynasm!(ops                                                                                                                                        
17 | |         ; ->hello:                                                                                                                                     
18 | |         ; .bytes string.as_bytes()                                                                                                                     
19 | |     );                                                                                                                                                 
   | |______^                                                                                                                                                 
                                                                                                                                                              
error[E0599]: no method named `extend` found for type `std::result::Result<dynasmrt::x64::Assembler, std::io::Error>` in the current scope                    
  --> src/main.rs:16:5                                                                                                                                        
   |                                                                                                                                                          
16 | /     dynasm!(ops                                                                                                                                        
17 | |         ; ->hello:                                                                                                                                     
18 | |         ; .bytes string.as_bytes()                                                                                                                     
19 | |     );                                                                                                                                                 
   | |______^                                                                                                                                                 
                                                                                                                                                              
error[E0599]: no method named `offset` found for type `std::result::Result<dynasmrt::x64::Assembler, std::io::Error>` in the current scope                    
  --> src/main.rs:21:21                                                                                                                                       
   |                                                                                                                                                          
21 |     let hello = ops.offset();                                                                                                                            
   |                     ^^^^^^                                                                                                                               
                                                                                                                                                              
error[E0599]: no method named `extend` found for type `std::result::Result<dynasmrt::x64::Assembler, std::io::Error>` in the current scope                    
  --> src/main.rs:22:5                                                                                                                                        
   |                                                                                                                                                          
22 | /     dynasm!(ops                                                                                                                                        
23 | |         ; lea rcx, [->hello]                                                                                                                           
24 | |         ; xor edx, edx                                                                                                                                 
25 | |         ; mov dl, BYTE string.len() as _                                                                                                               
...  |                                                                                                                                                        
30 | |         ; ret                                                                                                                                          
31 | |     );                                                                                                                                                 
   | |______^                                                                                                                                                 
                                                                                                                                                              
error[E0599]: no method named `global_reloc` found for type `std::result::Result<dynasmrt::x64::Assembler, std::io::Error>` in the current scope              
  --> src/main.rs:22:5                                                                                                                                        
   |                                                                                                                                                          
22 | /     dynasm!(ops                                                                                                                                        
23 | |         ; lea rcx, [->hello]                                                                                                                           
24 | |         ; xor edx, edx                                                                                                                                 
25 | |         ; mov dl, BYTE string.len() as _                                                                                                               
...  |                                                                                                                                                        
30 | |         ; ret                                                                                                                                          
31 | |     );                                                                                                                                                 
   | |______^                                                                                                                                                 
                                                                                                                                                              
error[E0599]: no method named `push_i8` found for type `std::result::Result<dynasmrt::x64::Assembler, std::io::Error>` in the current scope                   
  --> src/main.rs:22:5                                                                                                                                        
   |                                                                                                                                                          
22 | /     dynasm!(ops                                                                                                                                        
23 | |         ; lea rcx, [->hello]                                                                                                                           
24 | |         ; xor edx, edx                                                                                                                                 
25 | |         ; mov dl, BYTE string.len() as _                                                                                                               
...  |                                                                                                                                                        
30 | |         ; ret                                                                                                                                          
31 | |     );                                                                                                                                                 
   | |______^                                                                                                                                                 
                                                                                                                                                              
error[E0599]: no method named `push_i64` found for type `std::result::Result<dynasmrt::x64::Assembler, std::io::Error>` in the current scope                  
  --> src/main.rs:22:5                                                                                                                                        
   |                                                                                                                                                          
22 | /     dynasm!(ops                                                                                                                                        
23 | |         ; lea rcx, [->hello]                                                                                                                           
24 | |         ; xor edx, edx                                                                                                                                 
25 | |         ; mov dl, BYTE string.len() as _                                                                                                               
...  |                                                                                                                                                        
30 | |         ; ret                                                                                                                                          
31 | |     );                                                                                                                                                 
   | |______^                                                                                                                                                 
                                                                                                                                                              
error[E0599]: no method named `finalize` found for type `std::result::Result<dynasmrt::x64::Assembler, std::io::Error>` in the current scope                  
  --> src/main.rs:33:19                                                                                                                                       
   |                                                                                                                                                          
33 |     let buf = ops.finalize().unwrap();                                                                                                                   
   |                   ^^^^^^^^                                                                                                                               
                                                                                                                                                              
error: aborting due to 8 previous errors

Looks like an unwrap is missing in the initial assembler creation. I'll fix it. In the meantime you can use the example in the README, it's exactly the same but with this issue fixed already.