<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/stamping-build-info-in-constant-memory-v51vnrdfe" -->

---
title: Stamping build info in constant memory | daily.dev
description: A build engineer describes a memory-efficiency trick for stamping build metadata (build-id, timestamp, author) into ELF binaries after linking. Standard tools...
canonical: https://daily.dev/posts/stamping-build-info-in-constant-memory-v51vnrdfe
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Stamping build info in constant memory | daily.dev
og:description: A build engineer describes a memory-efficiency trick for stamping build metadata (build-id, timestamp, author) into ELF binaries after linking. Standard tools...
og:url: https://daily.dev/posts/stamping-build-info-in-constant-memory-v51vnrdfe
og:image: https://api.daily.dev/og/posts/V51vNRDfe.png
og:image:alt: Stamping build info in constant memory
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Stamping build info in constant memory

**[Farid Zakaria’s Blog](https://daily.dev/sources/fzakaria)** · 9 min read · 0 upvotes · 0 comments

## Summary

A build engineer describes a memory-efficiency trick for stamping build metadata (build-id, timestamp, author) into ELF binaries after linking. Standard tools like llvm-objcopy and GNU objcopy read the entire binary into memory to add a small section, causing peak RSS to scale linearly (roughly 2x file size) with binary size. The fix: have the linker emit a placeholder section with a single byte during the normal build, so the section header table entry and name already exist. A small custom tool (elfstamp.c, ~200 lines) then appends the payload to the end of the file and patches just sixteen bytes in the section header, avoiding reading or rewriting the whole binary. This yields constant memory use and much faster wall time. A PR is also in progress against LLVM to stream ELF output in objcopy, halving its peak memory use.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://fzakaria.com/2026/08/25/stamping-build-info-in-constant-memory>

## Questions this post answers

### why does llvm-objcopy use so much memory when adding a section to a large ELF binary

llvm-objcopy reads the entire binary into memory before writing it back out with the new section added, so peak memory use scales linearly with file size, roughly twice the file size regardless of how small the added section is. GNU objcopy exhibits the same behavior. A PR against LLVM to stream the ELF output instead of materializing it would roughly halve that peak, but the memory use would still scale with file size.

_Track build-tooling internals like ELF stamping and objcopy performance on daily.dev as they evolve._

### how can I add build metadata to an ELF binary without reading the whole file into memory

Emit a placeholder section at link time containing a single byte using inline assembly like `__asm__(".section .buildinfo,\"\",@progbits\n.byte 0\n.previous");` so the section header entry and name already exist. Then a post-link stamping step only needs to append the real payload to the end of the file and rewrite sixteen bytes (sh_offset and sh_size) in that section's header entry, giving constant memory use independent of binary size.

_Developers optimizing build pipelines can follow techniques like this on daily.dev to cut memory pressure._

### why do llvm-objcopy and GNU objcopy require a section to contain at least one byte instead of being empty

llvm-objcopy and GNU objcopy disagree on whether a truly empty section is valid ELF, so giving the placeholder section a single byte of content is a cheap workaround that keeps both tools happy when later locating or manipulating that section.

_Engineers debugging ELF and linker edge cases can find practical fixes like this via daily.dev._

## Similar posts on daily.dev

- [Shrinking while linking](https://daily.dev/posts/shrinking-while-linking-awvvmpylk) · Planet Haskell · 1 upvotes · 0 comments
- [Huge binaries: I thunk therefore I am](https://daily.dev/posts/huge-binaries-i-thunk-therefore-i-am-cemlkri4d) · Farid Zakaria’s Blog · 0 upvotes · 0 comments
- [Huge binaries: papercuts and limits](https://daily.dev/posts/huge-binaries-papercuts-and-limits-zza8ns6n8) · Farid Zakaria’s Blog · 0 upvotes · 0 comments
- [ELF’s ways to combine potentially non-unique objects](https://daily.dev/posts/elf-s-ways-to-combine-potentially-non-unique-objects-rlaswp7dz) · Arthur O'Dwyer · 5 upvotes · 0 comments

---

Tags: [#general-programming](https://daily.dev/tags/general-programming), [#c](https://daily.dev/tags/c), [#build-systems](https://daily.dev/tags/build-systems)

[View this post on daily.dev](https://daily.dev/posts/stamping-build-info-in-constant-memory-v51vnrdfe)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Stamping build info in constant memory","url":"https://daily.dev/posts/stamping-build-info-in-constant-memory-v51vnrdfe","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/stamping-build-info-in-constant-memory-v51vnrdfe"},"datePublished":"2026-08-26T05:01:52.553Z","dateModified":"2026-08-26T05:03:17.235Z","description":"A build engineer describes a memory-efficiency trick for stamping build metadata (build-id, timestamp, author) into ELF binaries after linking. Standard tools...","image":"https://media.daily.dev/image/upload/s--CxzD6vbw--/f_auto/v1722860399/public/Placeholder%2005","thumbnailUrl":"https://media.daily.dev/image/upload/s--CxzD6vbw--/f_auto/v1722860399/public/Placeholder%2005","isAccessibleForFree":true,"articleSection":"Farid Zakaria’s Blog","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Farid Zakaria’s Blog","logo":"https://media.daily.dev/image/upload/s--YqqvRt90--/f_auto/v1723789280/logos/fzakaria","url":"https://daily.dev/sources/fzakaria"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/stamping-build-info-in-constant-memory-v51vnrdfe","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"general-programming,c,build-systems","timeRequired":"PT9M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Farid Zakaria’s Blog","item":"https://daily.dev/sources/fzakaria"},{"@type":"ListItem","position":3,"name":"Stamping build info in constant memory"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/stamping-build-info-in-constant-memory-v51vnrdfe#faq","mainEntity":[{"@type":"Question","name":"why does llvm-objcopy use so much memory when adding a section to a large ELF binary","acceptedAnswer":{"@type":"Answer","text":"llvm-objcopy reads the entire binary into memory before writing it back out with the new section added, so peak memory use scales linearly with file size, roughly twice the file size regardless of how small the added section is. GNU objcopy exhibits the same behavior. A PR against LLVM to stream the ELF output instead of materializing it would roughly halve that peak, but the memory use would still scale with file size. Track build-tooling internals like ELF stamping and objcopy performance on daily.dev as they evolve."}},{"@type":"Question","name":"how can I add build metadata to an ELF binary without reading the whole file into memory","acceptedAnswer":{"@type":"Answer","text":"Emit a placeholder section at link time containing a single byte using inline assembly like `__asm__(\".section .buildinfo,\\\"\\\",@progbits\\n.byte 0\\n.previous\");` so the section header entry and name already exist. Then a post-link stamping step only needs to append the real payload to the end of the file and rewrite sixteen bytes (sh_offset and sh_size) in that section's header entry, giving constant memory use independent of binary size. Developers optimizing build pipelines can follow techniques like this on daily.dev to cut memory pressure."}},{"@type":"Question","name":"why do llvm-objcopy and GNU objcopy require a section to contain at least one byte instead of being empty","acceptedAnswer":{"@type":"Answer","text":"llvm-objcopy and GNU objcopy disagree on whether a truly empty section is valid ELF, so giving the placeholder section a single byte of content is a cheap workaround that keeps both tools happy when later locating or manipulating that section. Engineers debugging ELF and linker edge cases can find practical fixes like this via daily.dev."}}]}
```

