public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
* [glibc/maskray/lld] elf: Replace a --defsym trick with an object file to be compatible with lld
@ 2021-01-18 21:41 Fangrui Song
  0 siblings, 0 replies; 8+ messages in thread
From: Fangrui Song @ 2021-01-18 21:41 UTC (permalink / raw)
  To: glibc-cvs

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=3678e9498ec9a069a33a225dd2e8464bde98dba5

commit 3678e9498ec9a069a33a225dd2e8464bde98dba5
Author: Fangrui Song <maskray@google.com>
Date:   Sat Apr 11 14:21:35 2020 -0700

    elf: Replace a --defsym trick with an object file to be compatible with lld
    
    The existing code specifies -Wl,--defsym=malloc=0 and other malloc.os
    definitions before libc_pic.a so that libc_pic.a(malloc.os) is not
    fetched. This trick is used to avoid multiple definition errors which
    would happen as a chain result:
    
      dl-allobjs.os has an undefined __libc_scratch_buffer_set_array_size
      __libc_scratch_buffer_set_array_size fetches libc_pic.a(scratch_buffer_set_array_size.os)
      libc_pic.a(scratch_buffer_set_array_size.os) has an undefined free
      free fetches libc_pic.a(malloc.os)
      libc_pic.a(malloc.os) has an undefined __libc_message
      __libc_message fetches libc_pic.a(libc_fatal.os)
    
      libc_fatal.os will cause a multiple definition error (__GI___libc_fatal)
      >>> defined at dl-fxstatat64.c
      >>>            /tmp/p/glibc/Release/elf/dl-allobjs.os:(__GI___libc_fatal)
      >>> defined at libc_fatal.c
      >>>            libc_fatal.os:(.text+0x240) in archive /tmp/p/glibc/Release/libc_pic.a
    
    lld processes --defsym after all input files, so this trick does not
    suppress multiple definition errors with lld. Split the step into two
    and use an object file to make the intention more obvious and make lld
    work.
    
    This is conceptually more appropriate because --defsym defines a SHN_ABS
    symbol while a normal definition is relative to the image base.
    
    See https://sourceware.org/pipermail/libc-alpha/2020-March/111910.html
    for discussions about the --defsym semantics.

Diff:
---
 elf/Makefile | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/elf/Makefile b/elf/Makefile
index 543800f4be..e242fdc6c3 100644
--- a/elf/Makefile
+++ b/elf/Makefile
@@ -524,10 +524,6 @@ rtld-stubbed-symbols = \
   malloc \
   realloc \
 
-# The GCC arguments that implement $(rtld-stubbed-symbols).
-rtld-stubbed-symbols-args = \
-  $(patsubst %,-Wl$(comma)--defsym=%=0, $(rtld-stubbed-symbols))
-
 ifeq ($(have-ssp),yes)
 # rtld is not built with the stack protector, so these references will
 # go away in the rebuilds.
@@ -536,9 +532,10 @@ endif
 
 $(objpfx)librtld.map: $(objpfx)dl-allobjs.os $(common-objpfx)libc_pic.a
 	@-rm -f $@T
-	$(reloc-link) -o $@.o $(rtld-stubbed-symbols-args) \
-		'-Wl,-(' $^ -lgcc '-Wl,-)' -Wl,-Map,$@T
-	rm -f $@.o
+	echo '$(patsubst %,.globl %;,$(rtld-stubbed-symbols)) $(patsubst %,%:,$(rtld-stubbed-symbols))' | \
+		$(CC) -o $@T.o $(ASFLAGS) -c -x assembler -
+	$(reloc-link) -o $@.o $@T.o '-Wl,-(' $^ -lgcc '-Wl,-)' -Wl,-Map,$@T
+	rm -f %@T.o $@.o
 	mv -f $@T $@
 
 # For lld, skip preceding addresses and values before matching the archive and the member.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [glibc/maskray/lld] elf: Replace a --defsym trick with an object file to be compatible with LLD
@ 2021-02-01 18:01 Fangrui Song
  0 siblings, 0 replies; 8+ messages in thread
From: Fangrui Song @ 2021-02-01 18:01 UTC (permalink / raw)
  To: glibc-cvs

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=02d393f2483aedc4ce74e6edf8a15f063198041d

commit 02d393f2483aedc4ce74e6edf8a15f063198041d
Author: Fangrui Song <maskray@google.com>
Date:   Mon Feb 1 09:29:26 2021 -0800

    elf: Replace a --defsym trick with an object file to be compatible with LLD
    
    The existing code specifies -Wl,--defsym=malloc=0 and other malloc.os
    definitions before libc_pic.a so that libc_pic.a(malloc.os) is not
    fetched. This trick is used to avoid multiple definition errors which
    would happen as a chain result:
    
      dl-allobjs.os has an undefined __libc_scratch_buffer_set_array_size
      __libc_scratch_buffer_set_array_size fetches libc_pic.a(scratch_buffer_set_array_size.os)
      libc_pic.a(scratch_buffer_set_array_size.os) has an undefined free
      free fetches libc_pic.a(malloc.os)
      libc_pic.a(malloc.os) has an undefined __libc_message
      __libc_message fetches libc_pic.a(libc_fatal.os)
    
      libc_fatal.os will cause a multiple definition error (__GI___libc_fatal)
      >>> defined at dl-fxstatat64.c
      >>>            /tmp/p/glibc/Release/elf/dl-allobjs.os:(__GI___libc_fatal)
      >>> defined at libc_fatal.c
      >>>            libc_fatal.os:(.text+0x240) in archive /tmp/p/glibc/Release/libc_pic.a
    
    LLD processes --defsym after all input files, so this trick does not
    suppress multiple definition errors with LLD. Split the step into two
    and use an object file to make the intention more obvious and make LLD
    work.
    
    This is conceptually more appropriate because --defsym defines a SHN_ABS
    symbol while a normal definition is relative to the image base.
    
    See https://sourceware.org/pipermail/libc-alpha/2020-March/111910.html
    for discussions about the --defsym semantics.
    
    Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
    Reviewed-by: H.J. Lu <hjl.tools@gmail.com>

Diff:
---
 elf/Makefile | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/elf/Makefile b/elf/Makefile
index 5d666b1b0c..16c89b6d07 100644
--- a/elf/Makefile
+++ b/elf/Makefile
@@ -526,10 +526,6 @@ rtld-stubbed-symbols = \
   malloc \
   realloc \
 
-# The GCC arguments that implement $(rtld-stubbed-symbols).
-rtld-stubbed-symbols-args = \
-  $(patsubst %,-Wl$(comma)--defsym=%=0, $(rtld-stubbed-symbols))
-
 ifeq ($(have-ssp),yes)
 # rtld is not built with the stack protector, so these references will
 # go away in the rebuilds.
@@ -538,9 +534,12 @@ endif
 
 $(objpfx)librtld.map: $(objpfx)dl-allobjs.os $(common-objpfx)libc_pic.a
 	@-rm -f $@T
-	$(reloc-link) -o $@.o $(rtld-stubbed-symbols-args) \
-		'-Wl,-(' $^ -lgcc '-Wl,-)' -Wl,-Map,$@T
-	rm -f $@.o
+	for symbol in $(rtld-stubbed-symbols); do \
+		echo ".globl $$symbol"; \
+		echo "$$symbol:"; \
+	done | $(CC) -o $@T.o $(ASFLAGS) -c -x assembler -
+	$(reloc-link) -o $@.o $@T.o '-Wl,-(' $^ -lgcc '-Wl,-)' -Wl,-Map,$@T
+	rm -f %@T.o $@.o
 	mv -f $@T $@
 
 # For lld, skip preceding addresses and values before matching the archive and the member.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [glibc/maskray/lld] elf: Replace a --defsym trick with an object file to be compatible with LLD
@ 2021-02-01 17:23 Fangrui Song
  0 siblings, 0 replies; 8+ messages in thread
From: Fangrui Song @ 2021-02-01 17:23 UTC (permalink / raw)
  To: glibc-cvs

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=f6cdc9ce47364120f5ab77d60a5fc38ee3ba72e2

commit f6cdc9ce47364120f5ab77d60a5fc38ee3ba72e2
Author: Fangrui Song <maskray@google.com>
Date:   Mon Feb 1 09:21:21 2021 -0800

    elf: Replace a --defsym trick with an object file to be compatible with LLD
    
    The existing code specifies -Wl,--defsym=malloc=0 and other malloc.os
    definitions before libc_pic.a so that libc_pic.a(malloc.os) is not
    fetched. This trick is used to avoid multiple definition errors which
    would happen as a chain result:
    
      dl-allobjs.os has an undefined __libc_scratch_buffer_set_array_size
      __libc_scratch_buffer_set_array_size fetches libc_pic.a(scratch_buffer_set_array_size.os)
      libc_pic.a(scratch_buffer_set_array_size.os) has an undefined free
      free fetches libc_pic.a(malloc.os)
      libc_pic.a(malloc.os) has an undefined __libc_message
      __libc_message fetches libc_pic.a(libc_fatal.os)
    
      libc_fatal.os will cause a multiple definition error (__GI___libc_fatal)
      >>> defined at dl-fxstatat64.c
      >>>            /tmp/p/glibc/Release/elf/dl-allobjs.os:(__GI___libc_fatal)
      >>> defined at libc_fatal.c
      >>>            libc_fatal.os:(.text+0x240) in archive /tmp/p/glibc/Release/libc_pic.a
    
    LLD processes --defsym after all input files, so this trick does not
    suppress multiple definition errors with LLD. Split the step into two
    and use an object file to make the intention more obvious and make LLD
    work.
    
    This is conceptually more appropriate because --defsym defines a SHN_ABS
    symbol while a normal definition is relative to the image base.
    
    See https://sourceware.org/pipermail/libc-alpha/2020-March/111910.html
    for discussions about the --defsym semantics.

Diff:
---
 elf/Makefile | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/elf/Makefile b/elf/Makefile
index 5d666b1b0c..16c89b6d07 100644
--- a/elf/Makefile
+++ b/elf/Makefile
@@ -526,10 +526,6 @@ rtld-stubbed-symbols = \
   malloc \
   realloc \
 
-# The GCC arguments that implement $(rtld-stubbed-symbols).
-rtld-stubbed-symbols-args = \
-  $(patsubst %,-Wl$(comma)--defsym=%=0, $(rtld-stubbed-symbols))
-
 ifeq ($(have-ssp),yes)
 # rtld is not built with the stack protector, so these references will
 # go away in the rebuilds.
@@ -538,9 +534,12 @@ endif
 
 $(objpfx)librtld.map: $(objpfx)dl-allobjs.os $(common-objpfx)libc_pic.a
 	@-rm -f $@T
-	$(reloc-link) -o $@.o $(rtld-stubbed-symbols-args) \
-		'-Wl,-(' $^ -lgcc '-Wl,-)' -Wl,-Map,$@T
-	rm -f $@.o
+	for symbol in $(rtld-stubbed-symbols); do \
+		echo ".globl $$symbol"; \
+		echo "$$symbol:"; \
+	done | $(CC) -o $@T.o $(ASFLAGS) -c -x assembler -
+	$(reloc-link) -o $@.o $@T.o '-Wl,-(' $^ -lgcc '-Wl,-)' -Wl,-Map,$@T
+	rm -f %@T.o $@.o
 	mv -f $@T $@
 
 # For lld, skip preceding addresses and values before matching the archive and the member.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [glibc/maskray/lld] elf: Replace a --defsym trick with an object file to be compatible with LLD
@ 2021-01-29 18:30 Fangrui Song
  0 siblings, 0 replies; 8+ messages in thread
From: Fangrui Song @ 2021-01-29 18:30 UTC (permalink / raw)
  To: glibc-cvs

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=f8c819ca6021b80e3382119651cb8df9c19b928c

commit f8c819ca6021b80e3382119651cb8df9c19b928c
Author: Fangrui Song <maskray@google.com>
Date:   Fri Jan 29 10:25:35 2021 -0800

    elf: Replace a --defsym trick with an object file to be compatible with LLD
    
    The existing code specifies -Wl,--defsym=malloc=0 and other malloc.os
    definitions before libc_pic.a so that libc_pic.a(malloc.os) is not
    fetched. This trick is used to avoid multiple definition errors which
    would happen as a chain result:
    
      dl-allobjs.os has an undefined __libc_scratch_buffer_set_array_size
      __libc_scratch_buffer_set_array_size fetches libc_pic.a(scratch_buffer_set_array_size.os)
      libc_pic.a(scratch_buffer_set_array_size.os) has an undefined free
      free fetches libc_pic.a(malloc.os)
      libc_pic.a(malloc.os) has an undefined __libc_message
      __libc_message fetches libc_pic.a(libc_fatal.os)
    
      libc_fatal.os will cause a multiple definition error (__GI___libc_fatal)
      >>> defined at dl-fxstatat64.c
      >>>            /tmp/p/glibc/Release/elf/dl-allobjs.os:(__GI___libc_fatal)
      >>> defined at libc_fatal.c
      >>>            libc_fatal.os:(.text+0x240) in archive /tmp/p/glibc/Release/libc_pic.a
    
    LLD processes --defsym after all input files, so this trick does not
    suppress multiple definition errors with LLD. Split the step into two
    and use an object file to make the intention more obvious and make LLD
    work.
    
    This is conceptually more appropriate because --defsym defines a SHN_ABS
    symbol while a normal definition is relative to the image base.
    
    See https://sourceware.org/pipermail/libc-alpha/2020-March/111910.html
    for discussions about the --defsym semantics.

Diff:
---
 elf/Makefile | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/elf/Makefile b/elf/Makefile
index 5d666b1b0c..03e4034cc7 100644
--- a/elf/Makefile
+++ b/elf/Makefile
@@ -526,10 +526,6 @@ rtld-stubbed-symbols = \
   malloc \
   realloc \
 
-# The GCC arguments that implement $(rtld-stubbed-symbols).
-rtld-stubbed-symbols-args = \
-  $(patsubst %,-Wl$(comma)--defsym=%=0, $(rtld-stubbed-symbols))
-
 ifeq ($(have-ssp),yes)
 # rtld is not built with the stack protector, so these references will
 # go away in the rebuilds.
@@ -538,9 +534,10 @@ endif
 
 $(objpfx)librtld.map: $(objpfx)dl-allobjs.os $(common-objpfx)libc_pic.a
 	@-rm -f $@T
-	$(reloc-link) -o $@.o $(rtld-stubbed-symbols-args) \
-		'-Wl,-(' $^ -lgcc '-Wl,-)' -Wl,-Map,$@T
-	rm -f $@.o
+	printf '$(patsubst %,.globl %\n,$(rtld-stubbed-symbols)) $(patsubst %,%:\n,$(rtld-stubbed-symbols))' | \
+		$(CC) -o $@T.o $(ASFLAGS) -c -x assembler -
+	$(reloc-link) -o $@.o $@T.o '-Wl,-(' $^ -lgcc '-Wl,-)' -Wl,-Map,$@T
+	rm -f %@T.o $@.o
 	mv -f $@T $@
 
 # For lld, skip preceding addresses and values before matching the archive and the member.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [glibc/maskray/lld] elf: Replace a --defsym trick with an object file to be compatible with lld
@ 2021-01-18 21:38 Fangrui Song
  0 siblings, 0 replies; 8+ messages in thread
From: Fangrui Song @ 2021-01-18 21:38 UTC (permalink / raw)
  To: glibc-cvs

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=2af9cbfd37aa5e3e5e94125c85673ac9beb433a3

commit 2af9cbfd37aa5e3e5e94125c85673ac9beb433a3
Author: Fangrui Song <maskray@google.com>
Date:   Sat Apr 11 14:21:35 2020 -0700

    elf: Replace a --defsym trick with an object file to be compatible with lld
    
    The existing code specifies -Wl,--defsym=malloc=0 and other malloc.os
    definitions before libc_pic.a so that libc_pic.a(malloc.os) is not
    fetched. This trick is used to avoid multiple definition errors which
    would happen as a chain result:
    
      dl-allobjs.os has an undefined __libc_scratch_buffer_set_array_size
      __libc_scratch_buffer_set_array_size fetches libc_pic.a(scratch_buffer_set_array_size.os)
      libc_pic.a(scratch_buffer_set_array_size.os) has an undefined free
      free fetches libc_pic.a(malloc.os)
      libc_pic.a(malloc.os) has an undefined __libc_message
      __libc_message fetches libc_pic.a(libc_fatal.os)
    
      libc_fatal.os will cause a multiple definition error (__GI___libc_fatal)
      >>> defined at dl-fxstatat64.c
      >>>            /tmp/p/glibc/Release/elf/dl-allobjs.os:(__GI___libc_fatal)
      >>> defined at libc_fatal.c
      >>>            libc_fatal.os:(.text+0x240) in archive /tmp/p/glibc/Release/libc_pic.a
    
    lld processes --defsym after all input files, so this trick does not
    suppress multiple definition errors with lld. Split the step into two
    and use an object file to make the intention more obvious and make lld
    work.
    
    This is conceptually more appropriate because --defsym defines a SHN_ABS
    symbol while a normal definition is relative to the image base.
    
    See https://sourceware.org/pipermail/libc-alpha/2020-March/111910.html
    for discussions about the --defsym semantics.

Diff:
---
 elf/Makefile | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/elf/Makefile b/elf/Makefile
index 5e7f938e2d..8dbca48c4a 100644
--- a/elf/Makefile
+++ b/elf/Makefile
@@ -528,10 +528,6 @@ rtld-stubbed-symbols = \
   malloc \
   realloc \
 
-# The GCC arguments that implement $(rtld-stubbed-symbols).
-rtld-stubbed-symbols-args = \
-  $(patsubst %,-Wl$(comma)--defsym=%=0, $(rtld-stubbed-symbols))
-
 ifeq ($(have-ssp),yes)
 # rtld is not built with the stack protector, so these references will
 # go away in the rebuilds.
@@ -540,9 +536,10 @@ endif
 
 $(objpfx)librtld.map: $(objpfx)dl-allobjs.os $(common-objpfx)libc_pic.a
 	@-rm -f $@T
-	$(reloc-link) -o $@.o $(rtld-stubbed-symbols-args) \
-		'-Wl,-(' $^ -lgcc '-Wl,-)' -Wl,-Map,$@T
-	rm -f $@.o
+	echo '$(patsubst %,.globl %;,$(rtld-stubbed-symbols)) $(patsubst %,%:,$(rtld-stubbed-symbols))' | \
+		$(CC) -o $@T.o $(ASFLAGS) -c -x assembler -
+	$(reloc-link) -o $@.o $@T.o '-Wl,-(' $^ -lgcc '-Wl,-)' -Wl,-Map,$@T
+	rm -f %@T.o $@.o
 	mv -f $@T $@
 
 # For lld, skip preceding addresses and values before matching the archive and the member.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [glibc/maskray/lld] elf: Replace a --defsym trick with an object file to be compatible with lld
@ 2020-12-28 21:08 Fangrui Song
  0 siblings, 0 replies; 8+ messages in thread
From: Fangrui Song @ 2020-12-28 21:08 UTC (permalink / raw)
  To: glibc-cvs

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=a9467e5d34026ad7b242513f5398a89e874fd6e7

commit a9467e5d34026ad7b242513f5398a89e874fd6e7
Author: Fangrui Song <maskray@google.com>
Date:   Sat Apr 11 14:21:35 2020 -0700

    elf: Replace a --defsym trick with an object file to be compatible with lld
    
    The existing code specifies -Wl,--defsym=malloc=0 and other malloc.os
    definitions before libc_pic.a so that libc_pic.a(malloc.os) is not
    fetched. This trick is used to avoid multiple definition errors which
    would happen as a chain result:
    
      dl-allobjs.os has an undefined __libc_scratch_buffer_set_array_size
      __libc_scratch_buffer_set_array_size fetches libc_pic.a(scratch_buffer_set_array_size.os)
      libc_pic.a(scratch_buffer_set_array_size.os) has an undefined free
      free fetches libc_pic.a(malloc.os)
      libc_pic.a(malloc.os) has an undefined __libc_message
      __libc_message fetches libc_pic.a(libc_fatal.os)
    
      libc_fatal.os will cause a multiple definition error (__GI___libc_fatal)
      >>> defined at dl-fxstatat64.c
      >>>            /tmp/p/glibc/Release/elf/dl-allobjs.os:(__GI___libc_fatal)
      >>> defined at libc_fatal.c
      >>>            libc_fatal.os:(.text+0x240) in archive /tmp/p/glibc/Release/libc_pic.a
    
    lld processes --defsym after all input files, so this trick does not
    suppress multiple definition errors with lld. Split the step into two
    and use an object file to make the intention more obvious and make lld
    work.
    
    This is conceptually more appropriate because --defsym defines a SHN_ABS
    symbol while a normal definition is relative to the image base.
    
    See https://sourceware.org/pipermail/libc-alpha/2020-March/111910.html
    for discussions about the --defsym semantics.

Diff:
---
 elf/Makefile | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/elf/Makefile b/elf/Makefile
index 0b4d78c874..299bf24b49 100644
--- a/elf/Makefile
+++ b/elf/Makefile
@@ -524,10 +524,6 @@ rtld-stubbed-symbols = \
   malloc \
   realloc \
 
-# The GCC arguments that implement $(rtld-stubbed-symbols).
-rtld-stubbed-symbols-args = \
-  $(patsubst %,-Wl$(comma)--defsym=%=0, $(rtld-stubbed-symbols))
-
 ifeq ($(have-ssp),yes)
 # rtld is not built with the stack protector, so these references will
 # go away in the rebuilds.
@@ -536,9 +532,10 @@ endif
 
 $(objpfx)librtld.map: $(objpfx)dl-allobjs.os $(common-objpfx)libc_pic.a
 	@-rm -f $@T
-	$(reloc-link) -o $@.o $(rtld-stubbed-symbols-args) \
-		'-Wl,-(' $^ -lgcc '-Wl,-)' -Wl,-Map,$@T
-	rm -f $@.o
+	echo '$(patsubst %,.globl %;,$(rtld-stubbed-symbols)) $(patsubst %,%:,$(rtld-stubbed-symbols))' | \
+		$(CC) -o $@T.o $(ASFLAGS) -c -x assembler -
+	$(reloc-link) -o $@.o $@T.o '-Wl,-(' $^ -lgcc '-Wl,-)' -Wl,-Map,$@T
+	rm -f %@T.o $@.o
 	mv -f $@T $@
 
 # For lld, skip preceding addresses and values before matching the archive and the member.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [glibc/maskray/lld] elf: Replace a --defsym trick with an object file to be compatible with lld
@ 2020-12-28 21:06 Fangrui Song
  0 siblings, 0 replies; 8+ messages in thread
From: Fangrui Song @ 2020-12-28 21:06 UTC (permalink / raw)
  To: glibc-cvs

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=79aff916261c20cce3def9277c933e3956c5bd36

commit 79aff916261c20cce3def9277c933e3956c5bd36
Author: Fangrui Song <maskray@google.com>
Date:   Sat Apr 11 14:21:35 2020 -0700

    elf: Replace a --defsym trick with an object file to be compatible with lld
    
    The existing code specifies -Wl,--defsym=malloc=0 and other malloc.os
    definitions before libc_pic.a so that libc_pic.a(malloc.os) is not
    fetched. This trick is used to avoid multiple definition errors which
    would happen as a chain result:
    
      dl-allobjs.os has an undefined __libc_scratch_buffer_set_array_size
      __libc_scratch_buffer_set_array_size fetches libc_pic.a(scratch_buffer_set_array_size.os)
      libc_pic.a(scratch_buffer_set_array_size.os) has an undefined free
      free fetches libc_pic.a(malloc.os)
      libc_pic.a(malloc.os) has an undefined __libc_message
      __libc_message fetches libc_pic.a(libc_fatal.os)
    
      libc_fatal.os will cause a multiple definition error (__GI___libc_fatal)
      >>> defined at dl-fxstatat64.c
      >>>            /tmp/p/glibc/Release/elf/dl-allobjs.os:(__GI___libc_fatal)
      >>> defined at libc_fatal.c
      >>>            libc_fatal.os:(.text+0x240) in archive /tmp/p/glibc/Release/libc_pic.a
    
    lld processes --defsym after all input files, so this trick does not
    suppress multiple definition errors with lld. Split the step into two
    and use an object file to make the intention more obvious and make lld
    work.
    
    This is conceptually more appropriate because --defsym defines a SHN_ABS
    symbol while a normal definition is relative to the image base.
    
    See https://sourceware.org/pipermail/libc-alpha/2020-March/111910.html
    for discussions about the --defsym semantics.

Diff:
---
 elf/Makefile | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/elf/Makefile b/elf/Makefile
index 0b4d78c874..299bf24b49 100644
--- a/elf/Makefile
+++ b/elf/Makefile
@@ -524,10 +524,6 @@ rtld-stubbed-symbols = \
   malloc \
   realloc \
 
-# The GCC arguments that implement $(rtld-stubbed-symbols).
-rtld-stubbed-symbols-args = \
-  $(patsubst %,-Wl$(comma)--defsym=%=0, $(rtld-stubbed-symbols))
-
 ifeq ($(have-ssp),yes)
 # rtld is not built with the stack protector, so these references will
 # go away in the rebuilds.
@@ -536,9 +532,10 @@ endif
 
 $(objpfx)librtld.map: $(objpfx)dl-allobjs.os $(common-objpfx)libc_pic.a
 	@-rm -f $@T
-	$(reloc-link) -o $@.o $(rtld-stubbed-symbols-args) \
-		'-Wl,-(' $^ -lgcc '-Wl,-)' -Wl,-Map,$@T
-	rm -f $@.o
+	echo '$(patsubst %,.globl %;,$(rtld-stubbed-symbols)) $(patsubst %,%:,$(rtld-stubbed-symbols))' | \
+		$(CC) -o $@T.o $(ASFLAGS) -c -x assembler -
+	$(reloc-link) -o $@.o $@T.o '-Wl,-(' $^ -lgcc '-Wl,-)' -Wl,-Map,$@T
+	rm -f %@T.o $@.o
 	mv -f $@T $@
 
 # For lld, skip preceding addresses and values before matching the archive and the member.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [glibc/maskray/lld] elf: Replace a --defsym trick with an object file to be compatible with lld
@ 2020-12-28 19:07 Fangrui Song
  0 siblings, 0 replies; 8+ messages in thread
From: Fangrui Song @ 2020-12-28 19:07 UTC (permalink / raw)
  To: glibc-cvs

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=9aafcb7196be6eccddec2923a8bc3bfbc16eefea

commit 9aafcb7196be6eccddec2923a8bc3bfbc16eefea
Author: Fangrui Song <maskray@google.com>
Date:   Sat Apr 11 14:21:35 2020 -0700

    elf: Replace a --defsym trick with an object file to be compatible with lld
    
    The existing code specifies -Wl,--defsym=malloc=0 and other malloc.os
    definitions before libc_pic.a so that libc_pic.a(malloc.os) is not
    fetched. This trick is used to avoid multiple definition errors which
    would happen as a chain result:
    
      dl-allobjs.os has an undefined __libc_scratch_buffer_set_array_size
      __libc_scratch_buffer_set_array_size fetches libc_pic.a(scratch_buffer_set_array_size.os)
      libc_pic.a(scratch_buffer_set_array_size.os) has an undefined free
      free fetches libc_pic.a(malloc.os)
      libc_pic.a(malloc.os) has an undefined __libc_message
      __libc_message fetches libc_pic.a(libc_fatal.os)
    
      libc_fatal.os will cause a multiple definition error (__GI___libc_fatal)
      >>> defined at dl-fxstatat64.c
      >>>            /tmp/p/glibc/Release/elf/dl-allobjs.os:(__GI___libc_fatal)
      >>> defined at libc_fatal.c
      >>>            libc_fatal.os:(.text+0x240) in archive /tmp/p/glibc/Release/libc_pic.a
    
    lld processes --defsym after all input files, so this trick does not
    suppress multiple definition errors with lld. Split the step into two
    and use an object file to make the intention more obvious and make lld
    work.
    
    This is conceptually more appropriate because --defsym defines a SHN_ABS
    symbol while a normal definition is relative to the image base.
    
    See https://sourceware.org/pipermail/libc-alpha/2020-March/111910.html
    for discussions about the --defsym semantics.

Diff:
---
 elf/Makefile | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/elf/Makefile b/elf/Makefile
index 0b4d78c874..299bf24b49 100644
--- a/elf/Makefile
+++ b/elf/Makefile
@@ -524,10 +524,6 @@ rtld-stubbed-symbols = \
   malloc \
   realloc \
 
-# The GCC arguments that implement $(rtld-stubbed-symbols).
-rtld-stubbed-symbols-args = \
-  $(patsubst %,-Wl$(comma)--defsym=%=0, $(rtld-stubbed-symbols))
-
 ifeq ($(have-ssp),yes)
 # rtld is not built with the stack protector, so these references will
 # go away in the rebuilds.
@@ -536,9 +532,10 @@ endif
 
 $(objpfx)librtld.map: $(objpfx)dl-allobjs.os $(common-objpfx)libc_pic.a
 	@-rm -f $@T
-	$(reloc-link) -o $@.o $(rtld-stubbed-symbols-args) \
-		'-Wl,-(' $^ -lgcc '-Wl,-)' -Wl,-Map,$@T
-	rm -f $@.o
+	echo '$(patsubst %,.globl %;,$(rtld-stubbed-symbols)) $(patsubst %,%:,$(rtld-stubbed-symbols))' | \
+		$(CC) -o $@T.o $(ASFLAGS) -c -x assembler -
+	$(reloc-link) -o $@.o $@T.o '-Wl,-(' $^ -lgcc '-Wl,-)' -Wl,-Map,$@T
+	rm -f %@T.o $@.o
 	mv -f $@T $@
 
 # For lld, skip preceding addresses and values before matching the archive and the member.


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-02-01 18:01 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-18 21:41 [glibc/maskray/lld] elf: Replace a --defsym trick with an object file to be compatible with lld Fangrui Song
  -- strict thread matches above, loose matches on Subject: below --
2021-02-01 18:01 [glibc/maskray/lld] elf: Replace a --defsym trick with an object file to be compatible with LLD Fangrui Song
2021-02-01 17:23 Fangrui Song
2021-01-29 18:30 Fangrui Song
2021-01-18 21:38 [glibc/maskray/lld] elf: Replace a --defsym trick with an object file to be compatible with lld Fangrui Song
2020-12-28 21:08 Fangrui Song
2020-12-28 21:06 Fangrui Song
2020-12-28 19:07 Fangrui Song

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).