Difference between Machine code and Object Code [duplicate] - execution

This question already has answers here:
Assembly code vs Machine code vs Object code?
(10 answers)
Closed 9 years ago.
I'm in the middle of my a levels and im doing some revision for my Computing exam.
I was wondering if someone could tell me what the difference is between machine code and object code.
keep it it simple please.

Object code is the output of the compiler. It contains instructions and tokens like your source code, but in a compact and optimized (often executable) format. It can also contain other things like debugger symbols. Usually, object code is then processed by the linker, which connects the object code from each compilation unit together to form an executable (or library, such as a dll). The executable or library contains machine code, which can be executed directly by the processor and is specific to the machine architecture and operation set.

Related

Dynamically loading CUDA [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed yesterday.
Improve this question
I'm trying to add CUDA functionality to an existing code. The desired result is that if the user has cuda runtime installed on their machine, the code will use their cuda runtime (using dlopen) to check if a CUDA enabled GPU is available and then run the CUDA code on it if that's true. Otherwise, run the original non-GPU accelerated code. However, there are some gaps in my understanding of libraries and CUDA that make this tricky for me.
The code compiles just fine if I specify the location of the required CUDA libraries (cudart and cublas) and dynamically link them. However, I tried not linking these libraries and instead wrapping 'everything' I need using dlopen and dlsym to get handles to the functions I need. However, compilation fails when it gets to actual device code (definitions for angle bracket code) because it's looking for things like __cudaRegisterFunction during compile time. I've replaced the angle bracket calls with a wrapped version of cudaLaunchKernel but still get this issue, possibly because the definitions of the machine code themselves require some special calls.
Some fundamental things I'm unsure about are when the symbols in a shared lib have to be resolved. For example, let's say the user does not have cudart.so, is it possible for me to just not run any cudart/cuda code and avoid any runtime issues involving finding references to functions contained in this library? Or do all cudart.so functions need to be found in the .so file regardless of whether or not they're used? If the answer to this question is that only functions that are used need to be resolved, would this not obviate the need for wrapping functions via dlopen/dlsym? Another question somewhat related to this is: can you compile cuda code without linking to cudart? I may be confusing two separate issues in that it might be necessary to link to cudart.so when compiling CUDA code but that does not mean you are actually using cudart.so during runtime.
It's entirely possible I'm going about this the entirely wrong way so hopefully the general statement of what I'm trying to do can get me to some working answer.

Need help unittesting rust library that has calls to execve

Background:
I'm currently writing unittests for a library that is capable of starting other binaries, guaranteeing the binary will die after a timeout on linux.
The unittest is currently done by calling a binary that would normally sleep for 10 seconds and then create a file containing some data. The binary should be killed before those 10 seconds meaning the file should not exist had the timeout functioned. The path to that binary is currently hardcoded which is not what I want.
What I need help with:
Problem is I want to have access to such a binary when the crate is compiled, and then pass its path to the library being tested (thus being able to call said binary using execve syscall without hardcoding its location allowing other users of my crate to compile it). This means I need to somehow have a binary generated or grabbed during compilation and somehow have access to its path inside my unittest. Is there any decent approach to doing this?
The code for the binary can be written in whatever language as long as it works. But preferably rust or C/C++. Worst case it can be precompiled but I'd like to have it compiled on the fly so it works on ARM or other architectures aswell
What have I tried:
The current method is to simply hardcode the binary path and compile it manually using G++. This is not optimal however since if anyone downloads my crate from crates.io they won't have that binary and thus cannot pass its unittests.
I have been messing around with cc in build.rs, generating C++ code and then compiling it, but CC appears to be for compiling libraries which is not what I want since it attempts to link the binaries with the library (I believe thats what it's doing), and I have been googling for a few hours without finding any approach to solve this problem.

I wrote a nice program in linux and I don't want people to steal my work [duplicate]

This question already has answers here:
How to obfuscate a shell script?
(4 answers)
Closed 6 years ago.
I wrote a nice program in linux and I don't want people to steal my work, is there a way for me to hide the contents of my sh file from other people seeing it when I publish it? And it still has to be functional when I publish it to the public. I won't be posting any of the code because of this.
You could consider adding an open source license to your program to protect it:
https://dzone.com/articles/selecting-an-open-source-license-for-your-project
One possibility is to compile the shell script to C and ship a binary executable. Compilers for the shell language exist, such as CCsh from Comeau Computing, which is a proprietary product, like yours.

Why can't we extract source code from executable file?

I need some information on executable files, thanks in advance, this is a new topic in our grade.
I've seen a lot of questions asking how to extract, but my question is why can't we get the original source code? Yeah using decompilers we can extract but those codes are not the exact code used to develop the program.
I mean, if a computer is running a software it obviously has to have some code to refer from, then why can't we get that code? Also, do exe files have the same code which is developed by the programmer? Is it that OSs are developed in such a way that they don't leak source code from an executable file?
The .exe file is made up of binary numbers which consist of 1's and 0's. And these files contain some additional code that support code from many source.
Operating systems use binary languages to operate, this is what we call machine code. (Getting the code back from the exe is like getting the apple back from the apple juice) ;)
Also check Compiled vs. Interpreted Languages
The process to transform the source code into the exe file is extremely complex. For example, when it is being compile, the language of the source code (eg. c++ etc) is transformed into machine code. It is like when you eat something, those things turns into feces after being process by your stomach. Therefore it's quite impossible to revert exe file to source code.

Producing executables within Linux (in relation to implementing a compiler)

For my university, final-year dissertation, I am going to implement a compiler for a skeletal form of the C programming language, then go about extending it until it resembles something a little more like Java with array bounds checking, type-checking and so forth.
I am relatively competent at much of the theory that relates to compiler construction, and have experience programming in MIPS assembly language, so I do understand a little of what it is to write extremely low-level code.
My main concern is that I am likely to be able to get all the way to the point where I need to produce the actual machine-code output, but then not understand enough about how machine code is executed from the perspective of the operating system running it.
So, my actual question is basically, "does anyone know the best place to read up about writing assembly to run on an intel x86-64 processor under linux?"
The main gap in my knowledge is how the machine code is actually run in practise. Is it run directly on the processor, making "syscall"s (or the x86 equivalent) when it needs services provided by the kernel, or is the assembly language somehow an encapsulated description that tells the kernel how to execute the instructions (in a manner similar to an interpreted language such as Java)?
Any help you can provide would be greatly appreciated.
This document explains how you can implement a foreign function interface to interact with other code: http://www.x86-64.org/documentation/abi.pdf
Firstly, for the machine code start here: http://www.intel.com/products/processor/manuals/
Next, I assume your question about how the machine code is run is really about how the OS loads the exe into memory and calls main()? These links may help
Linkers and loaders:
http://www.linuxjournal.com/article/6463
ELF file format:
http://en.wikipedia.org/wiki/Executable_and_Linkable_Format and
http://www.linuxjournal.com/article/1060
Your machine code will go into the .text section of the executable
Finally, best of luck. Your project is similar to my final year project, except I targeted the JVM and compiled a subset of Visual Basic!

Resources