From a55de2ba619a9203e7d93fd3efde127d1ad922a2 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Tue, 4 Oct 2011 21:25:11 -0700 Subject: [PATCH] 5l/6l/8l: add a DT_DEBUG dynamic tag to a dynamic ELF binary This requires making the .dynamic section writable, as the dynamic linker will change the value of the DT_DEBUG tag at runtime. The DT_DEBUG tag is used by gdb to find all loaded shared libraries. R=rsc CC=golang-dev https://golang.org/cl/5189044 --- src/cmd/5l/asm.c | 3 ++- src/cmd/6l/asm.c | 4 +++- src/cmd/8l/asm.c | 4 +++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/cmd/5l/asm.c b/src/cmd/5l/asm.c index 5b7f6f111d1..46fb6b63236 100644 --- a/src/cmd/5l/asm.c +++ b/src/cmd/5l/asm.c @@ -232,7 +232,7 @@ doelf(void) /* define dynamic elf table */ s = lookup(".dynamic", 0); s->reachable = 1; - s->type = SELFROSECT; + s->type = SELFSECT; // writable /* * .dynamic table @@ -251,6 +251,7 @@ doelf(void) elfwritedynent(s, DT_PLTREL, DT_REL); elfwritedynentsymsize(s, DT_PLTRELSZ, lookup(".rel.plt", 0)); elfwritedynentsym(s, DT_JMPREL, lookup(".rel.plt", 0)); + elfwritedynent(s, DT_DEBUG, 0); elfwritedynent(s, DT_NULL, 0); } } diff --git a/src/cmd/6l/asm.c b/src/cmd/6l/asm.c index 3a8223e65cc..8d599ef30aa 100644 --- a/src/cmd/6l/asm.c +++ b/src/cmd/6l/asm.c @@ -649,7 +649,7 @@ doelf(void) /* define dynamic elf table */ s = lookup(".dynamic", 0); s->reachable = 1; - s->type = SELFROSECT; + s->type = SELFSECT; // writable /* * .dynamic table @@ -670,6 +670,8 @@ doelf(void) elfwritedynentsymsize(s, DT_PLTRELSZ, lookup(".rela.plt", 0)); elfwritedynentsym(s, DT_JMPREL, lookup(".rela.plt", 0)); + elfwritedynent(s, DT_DEBUG, 0); + // Do not write DT_NULL. elfdynhash will finish it. } } diff --git a/src/cmd/8l/asm.c b/src/cmd/8l/asm.c index 6c7f9648379..03106386c01 100644 --- a/src/cmd/8l/asm.c +++ b/src/cmd/8l/asm.c @@ -607,7 +607,7 @@ doelf(void) /* define dynamic elf table */ s = lookup(".dynamic", 0); s->reachable = 1; - s->type = SELFROSECT; + s->type = SELFSECT; // writable /* * .dynamic table @@ -627,6 +627,8 @@ doelf(void) elfwritedynentsymsize(s, DT_PLTRELSZ, lookup(".rel.plt", 0)); elfwritedynentsym(s, DT_JMPREL, lookup(".rel.plt", 0)); + elfwritedynent(s, DT_DEBUG, 0); + // Do not write DT_NULL. elfdynhash will finish it. } }