Hacking in C 2020 the C Programming Language Thom Wiggers
Total Page:16
File Type:pdf, Size:1020Kb
Hacking in C 2020 The C programming language Thom Wiggers 1 Table of Contents Introduction Undefined behaviour Abstracting away from bytes in memory Integer representations 2 Table of Contents Introduction Undefined behaviour Abstracting away from bytes in memory Integer representations 3 – Another predecessor is B. • Not one of the first programming languages: ALGOL for example is older. • Closely tied to the development of the Unix operating system • Unix and Linux are mostly written in C • Compilers are widely available for many, many, many platforms • Still in development: latest release of standard is C18. Popular versions are C99 and C11. • Many compilers implement extensions, leading to versions such as gnu18, gnu11. • Default version in GCC gnu11 The C programming language • Invented by Dennis Ritchie in 1972–1973 4 – Another predecessor is B. • Closely tied to the development of the Unix operating system • Unix and Linux are mostly written in C • Compilers are widely available for many, many, many platforms • Still in development: latest release of standard is C18. Popular versions are C99 and C11. • Many compilers implement extensions, leading to versions such as gnu18, gnu11. • Default version in GCC gnu11 The C programming language • Invented by Dennis Ritchie in 1972–1973 • Not one of the first programming languages: ALGOL for example is older. 4 • Closely tied to the development of the Unix operating system • Unix and Linux are mostly written in C • Compilers are widely available for many, many, many platforms • Still in development: latest release of standard is C18. Popular versions are C99 and C11. • Many compilers implement extensions, leading to versions such as gnu18, gnu11. • Default version in GCC gnu11 The C programming language • Invented by Dennis Ritchie in 1972–1973 • Not one of the first programming languages: ALGOL for example is older. – Another predecessor is B. 4 • Unix and Linux are mostly written in C • Compilers are widely available for many, many, many platforms • Still in development: latest release of standard is C18. Popular versions are C99 and C11. • Many compilers implement extensions, leading to versions such as gnu18, gnu11. • Default version in GCC gnu11 The C programming language • Invented by Dennis Ritchie in 1972–1973 • Not one of the first programming languages: ALGOL for example is older. – Another predecessor is B. • Closely tied to the development of the Unix operating system 4 • Compilers are widely available for many, many, many platforms • Still in development: latest release of standard is C18. Popular versions are C99 and C11. • Many compilers implement extensions, leading to versions such as gnu18, gnu11. • Default version in GCC gnu11 The C programming language • Invented by Dennis Ritchie in 1972–1973 • Not one of the first programming languages: ALGOL for example is older. – Another predecessor is B. • Closely tied to the development of the Unix operating system • Unix and Linux are mostly written in C 4 • Still in development: latest release of standard is C18. Popular versions are C99 and C11. • Many compilers implement extensions, leading to versions such as gnu18, gnu11. • Default version in GCC gnu11 The C programming language • Invented by Dennis Ritchie in 1972–1973 • Not one of the first programming languages: ALGOL for example is older. – Another predecessor is B. • Closely tied to the development of the Unix operating system • Unix and Linux are mostly written in C • Compilers are widely available for many, many, many platforms 4 • Many compilers implement extensions, leading to versions such as gnu18, gnu11. • Default version in GCC gnu11 The C programming language • Invented by Dennis Ritchie in 1972–1973 • Not one of the first programming languages: ALGOL for example is older. – Another predecessor is B. • Closely tied to the development of the Unix operating system • Unix and Linux are mostly written in C • Compilers are widely available for many, many, many platforms • Still in development: latest release of standard is C18. Popular versions are C99 and C11. 4 • Default version in GCC gnu11 The C programming language • Invented by Dennis Ritchie in 1972–1973 • Not one of the first programming languages: ALGOL for example is older. – Another predecessor is B. • Closely tied to the development of the Unix operating system • Unix and Linux are mostly written in C • Compilers are widely available for many, many, many platforms • Still in development: latest release of standard is C18. Popular versions are C99 and C11. • Many compilers implement extensions, leading to versions such as gnu18, gnu11. 4 The C programming language • Invented by Dennis Ritchie in 1972–1973 • Not one of the first programming languages: ALGOL for example is older. – Another predecessor is B. • Closely tied to the development of the Unix operating system • Unix and Linux are mostly written in C • Compilers are widely available for many, many, many platforms • Still in development: latest release of standard is C18. Popular versions are C99 and C11. • Many compilers implement extensions, leading to versions such as gnu18, gnu11. • Default version in GCC gnu11 4 – Almost no abstraction – Full control – No types, no bounds checking: everything is just bytes to the CPU – Direct access to CPU and memory – Choice of instructions, register allocation left to programmer – Need to do everything from scratch for different CPUs – If a microarchitecture is released with new features, may need to re-implement parts of the code • Unix is an operating system: main job is managing hardware • C was used to replace the assembly code and implement new sofware for Unix • Writing code in assembly: Programming for hardware • Initially C was co-developed with Unix 5 – Almost no abstraction – Full control – No types, no bounds checking: everything is just bytes to the CPU – Direct access to CPU and memory – Choice of instructions, register allocation left to programmer – Need to do everything from scratch for different CPUs – If a microarchitecture is released with new features, may need to re-implement parts of the code • C was used to replace the assembly code and implement new sofware for Unix • Writing code in assembly: Programming for hardware • Initially C was co-developed with Unix • Unix is an operating system: main job is managing hardware 5 – Almost no abstraction – Full control – No types, no bounds checking: everything is just bytes to the CPU – Direct access to CPU and memory – Choice of instructions, register allocation left to programmer – Need to do everything from scratch for different CPUs – If a microarchitecture is released with new features, may need to re-implement parts of the code • Writing code in assembly: Programming for hardware • Initially C was co-developed with Unix • Unix is an operating system: main job is managing hardware • C was used to replace the assembly code and implement new sofware for Unix 5 – Almost no abstraction – Full control – No types, no bounds checking: everything is just bytes to the CPU – Direct access to CPU and memory – Choice of instructions, register allocation left to programmer – Need to do everything from scratch for different CPUs – If a microarchitecture is released with new features, may need to re-implement parts of the code Programming for hardware • Initially C was co-developed with Unix • Unix is an operating system: main job is managing hardware • C was used to replace the assembly code and implement new sofware for Unix • Writing code in assembly: 5 – Full control – No types, no bounds checking: everything is just bytes to the CPU – Direct access to CPU and memory – Choice of instructions, register allocation left to programmer – Need to do everything from scratch for different CPUs – If a microarchitecture is released with new features, may need to re-implement parts of the code Programming for hardware • Initially C was co-developed with Unix • Unix is an operating system: main job is managing hardware • C was used to replace the assembly code and implement new sofware for Unix • Writing code in assembly: – Almost no abstraction 5 – No types, no bounds checking: everything is just bytes to the CPU – Direct access to CPU and memory – Choice of instructions, register allocation left to programmer – Need to do everything from scratch for different CPUs – If a microarchitecture is released with new features, may need to re-implement parts of the code Programming for hardware • Initially C was co-developed with Unix • Unix is an operating system: main job is managing hardware • C was used to replace the assembly code and implement new sofware for Unix • Writing code in assembly: – Almost no abstraction – Full control 5 – Direct access to CPU and memory – Choice of instructions, register allocation left to programmer – Need to do everything from scratch for different CPUs – If a microarchitecture is released with new features, may need to re-implement parts of the code Programming for hardware • Initially C was co-developed with Unix • Unix is an operating system: main job is managing hardware • C was used to replace the assembly code and implement new sofware for Unix • Writing code in assembly: – Almost no abstraction – Full control – No types, no bounds checking: everything is just bytes to the CPU 5 – Choice of instructions, register allocation left to programmer – Need to do everything from scratch for different CPUs – If a microarchitecture is released with new features, may need to re-implement parts of the code Programming for hardware • Initially