Clobbering#Assembly

{{Short description|The act of overwriting a resource}}

{{how-to|date=December 2012}}

In computing, clobbering is the act of overwriting a resource such as a file, processor register or a region of memory, such that its content is lost. Generally, the term is used in the context of unintentional loss of information, but it can be used for intentional overwriting as well.{{ cite web | url = https://www.wisegeek.com/in-computing-what-is-clobbering.htm | title = In Computing, what is Clobbering? | access-date = 13 June 2019 | date = 20 June 2016 | website = wiseGEEK | quote = The term “clobbering” is used in several different ways in computing, with the meaning usually clear from the context. In one sense, it refers to overwriting existing files or memory entries. It can also be used to discuss overwhelming computers such as servers with requests, causing a downgrade in performance. This second usage of the word reflects the common usage of “clobber” as a word to describe taking a beating. | archive-url = https://web.archive.org/web/20190613155133/https://www.wisegeek.com/in-computing-what-is-clobbering.htm | archive-date = 13 June 2019 | df = dmy-all }} The Jargon File defines clobbering as

{{blockquote|To overwrite, usually unintentionally: "I walked off the end of the array and clobbered the stack." Compare mung, scribble, trash, and smash the stack.[http://www.catb.org/~esr/jargon/html/C/clobber.html "Clobber" in the Jargon File]}}

Examples

= File redirection =

In many shells, the > file redirection operator clobbers if the output path refers to an existing file. This can be prevented in bash and ksh via the command set -o noclobber and in csh and tcsh via set noclobber. Subsequently, attempting to clobber via redirection fails with an error message.[https://books.google.com/books?id=tDDb5zRoONwC&dq=clobber+file+noclobber&pg=PA892 "Unix Power Tools", by Shelley Powers, Jerry Peek, Tim O'Reilly, Mike Loukides, p. 892] For example:

$ echo "Hello, world" >file.txt

$ cat file.txt

Hello, world

$ echo "This will overwrite the first greeting." >file.txt

$ cat file.txt

This will overwrite the first greeting.

$ set -o noclobber

$ echo "Can we overwrite it again?" >file.txt

-bash: file.txt: cannot overwrite existing file

$ echo "But we can use the >| operator to ignore the noclobber." >|file.txt

$ cat file.txt # Successfully overwrote the contents of file.txt using the >| operator

But we can use the >| operator to ignore the noclobber.

$ set +o noclobber # Changes setting back

= File mv and cp =

The default behavior of the mv and cp commands is to clobber an existing destination file. This behavior may be overridden vi the -i option which results in prompting the user to confirm clobbering a file. Alternatively, the -n option selects to skip operations that would clobber.

= Makefiles =

A commonly used make

target, named clobber, performs a complete cleanup of files and directories produced via previous invocations of the command for a particular makefile.[https://books.google.com/books?id=r9BQAAAAMAAJ&q=clobber+make+target UNIX System V, Release 4, Motorola Unix, Motorola, inc, inc Motorola, p. 28] It is a more thorough cleanup operation than clean and is commonly used to uninstall software. Some make-related commands invoke {{code|make clobber}} during their execution. They check the CLOBBER environment variable. If it is set to OFF then clobbering is not done.[https://books.google.com/books?id=e7dQAAAAMAAJ&q=clobber+make+target "Unix Unleashed", by Robin Burk, David B. Horvath]

= Assembly =

In assembler programming (including GCC inline assembly{{cite web |title=Extended Asm (Using the GNU Compiler Collection (GCC)) |url=https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html |website=GCC, The GNU Compiler Collection |access-date=22 March 2021}}) a clobbered register denotes a register whose value may be overwritten in the course of executing an instruction.

References