diff mbox series

[kvm-unit-tests,7/9] s390x: use C pre-processor for linker script generation

Message ID 20230116175757.71059-8-mhartmay@linux.ibm.com (mailing list archive)
State New, archived
Headers show
Series Some cleanup patches | expand

Commit Message

Marc Hartmayer Jan. 16, 2023, 5:57 p.m. UTC
Use the C pre-processor for the linker script generation. For example,
this enables us the use of constants in the "linker scripts" `*.lds.S`.

Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
---
 .gitignore                                  | 1 +
 s390x/Makefile                              | 6 ++++--
 s390x/{flat.lds => flat.lds.S}              | 0
 s390x/snippets/asm/{flat.lds => flat.lds.S} | 0
 s390x/snippets/c/{flat.lds => flat.lds.S}   | 0
 5 files changed, 5 insertions(+), 2 deletions(-)
 rename s390x/{flat.lds => flat.lds.S} (100%)
 rename s390x/snippets/asm/{flat.lds => flat.lds.S} (100%)
 rename s390x/snippets/c/{flat.lds => flat.lds.S} (100%)

Comments

Claudio Imbrenda Jan. 16, 2023, 6:22 p.m. UTC | #1
On Mon, 16 Jan 2023 18:57:55 +0100
Marc Hartmayer <mhartmay@linux.ibm.com> wrote:

> Use the C pre-processor for the linker script generation. For example,
> this enables us the use of constants in the "linker scripts" `*.lds.S`.

please explain that the original .lds scripts are being renamed to
.lds.S, and that the .lds are now generated.

> 
> Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
> ---
>  .gitignore                                  | 1 +
>  s390x/Makefile                              | 6 ++++--
>  s390x/{flat.lds => flat.lds.S}              | 0
>  s390x/snippets/asm/{flat.lds => flat.lds.S} | 0
>  s390x/snippets/c/{flat.lds => flat.lds.S}   | 0
>  5 files changed, 5 insertions(+), 2 deletions(-)
>  rename s390x/{flat.lds => flat.lds.S} (100%)
>  rename s390x/snippets/asm/{flat.lds => flat.lds.S} (100%)
>  rename s390x/snippets/c/{flat.lds => flat.lds.S} (100%)
> 
> diff --git a/.gitignore b/.gitignore
> index 601822d67325..29f352c5ceb6 100644
> --- a/.gitignore
> +++ b/.gitignore
> @@ -31,3 +31,4 @@ cscope.*
>  /s390x/comm.key
>  /s390x/snippets/*/*.hdr
>  /s390x/snippets/*/*.*obj
> +/s390x/**/*.lds

why ** ?

> diff --git a/s390x/Makefile b/s390x/Makefile
> index 31f6db11213d..45493160cdf8 100644
> --- a/s390x/Makefile
> +++ b/s390x/Makefile
> @@ -76,7 +76,7 @@ CFLAGS += -fno-delete-null-pointer-checks
>  LDFLAGS += -nostdlib -Wl,--build-id=none
>  
>  # We want to keep intermediate files
> -.PRECIOUS: %.o
> +.PRECIOUS: %.o %.lds
>  
>  asm-offsets = lib/$(ARCH)/asm-offsets.h
>  include $(SRCDIR)/scripts/asm-offsets.mak
> @@ -159,6 +159,8 @@ $(SNIPPET_DIR)/c/%.gbin: $(SNIPPET_DIR)/c/%.o $(snippet_lib) $(FLATLIBS) $(SRCDI
>  %.hdr.obj: %.hdr
>  	$(OBJCOPY) -I binary -O elf64-s390 -B "s390:64-bit" $< $@
>  
> +%.lds: %.lds.S
> +	$(CPP) $(autodepend-flags) $(CPPFLAGS) -P -C -o $@ $<
>  
>  .SECONDEXPANSION:
>  %.elf: $(FLATLIBS) $(asmlib) $(SRCDIR)/s390x/flat.lds $$(snippets-obj) $$(snippet-hdr-obj) %.o
> @@ -211,7 +213,7 @@ $(snippet_asmlib): $$(patsubst %.o,%.S,$$@) $(asm-offsets)
>  
>  
>  arch_clean: asm_offsets_clean
> -	$(RM) $(TEST_DIR)/*.{o,elf,bin} $(SNIPPET_DIR)/*/*.{o,elf,*bin,*obj,hdr} $(SNIPPET_DIR)/asm/.*.d $(TEST_DIR)/.*.d lib/s390x/.*.d $(comm-key)
> +	$(RM) $(TEST_DIR)/*.{o,elf,bin,lds} $(SNIPPET_DIR)/*/*.{o,elf,*bin,*obj,hdr,lds} $(SNIPPET_DIR)/asm/.*.d $(TEST_DIR)/.*.d lib/s390x/.*.d $(comm-key)
>  
>  generated-files = $(asm-offsets)
>  $(tests:.elf=.o) $(asmlib) $(cflatobjs): $(generated-files)
> diff --git a/s390x/flat.lds b/s390x/flat.lds.S
> similarity index 100%
> rename from s390x/flat.lds
> rename to s390x/flat.lds.S
> diff --git a/s390x/snippets/asm/flat.lds b/s390x/snippets/asm/flat.lds.S
> similarity index 100%
> rename from s390x/snippets/asm/flat.lds
> rename to s390x/snippets/asm/flat.lds.S
> diff --git a/s390x/snippets/c/flat.lds b/s390x/snippets/c/flat.lds.S
> similarity index 100%
> rename from s390x/snippets/c/flat.lds
> rename to s390x/snippets/c/flat.lds.S
Marc Hartmayer Jan. 17, 2023, 9:43 a.m. UTC | #2
Claudio Imbrenda <imbrenda@linux.ibm.com> writes:

> On Mon, 16 Jan 2023 18:57:55 +0100
> Marc Hartmayer <mhartmay@linux.ibm.com> wrote:
>
>> Use the C pre-processor for the linker script generation. For example,
>> this enables us the use of constants in the "linker scripts" `*.lds.S`.
>
> please explain that the original .lds scripts are being renamed to
> .lds.S, and that the .lds are now generated.

Okay.

>
>> 
>> Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
>> ---
>>  .gitignore                                  | 1 +
>>  s390x/Makefile                              | 6 ++++--
>>  s390x/{flat.lds => flat.lds.S}              | 0
>>  s390x/snippets/asm/{flat.lds => flat.lds.S} | 0
>>  s390x/snippets/c/{flat.lds => flat.lds.S}   | 0
>>  5 files changed, 5 insertions(+), 2 deletions(-)
>>  rename s390x/{flat.lds => flat.lds.S} (100%)
>>  rename s390x/snippets/asm/{flat.lds => flat.lds.S} (100%)
>>  rename s390x/snippets/c/{flat.lds => flat.lds.S} (100%)
>> 
>> diff --git a/.gitignore b/.gitignore
>> index 601822d67325..29f352c5ceb6 100644
>> --- a/.gitignore
>> +++ b/.gitignore
>> @@ -31,3 +31,4 @@ cscope.*
>>  /s390x/comm.key
>>  /s390x/snippets/*/*.hdr
>>  /s390x/snippets/*/*.*obj
>> +/s390x/**/*.lds
>
> why ** ?

Because all of our linker scripts are generated now:

s390x/snippets/(c|asm)/*.lds

and

s390x/*.lds

[…snip]
Claudio Imbrenda Jan. 17, 2023, 10:24 a.m. UTC | #3
On Tue, 17 Jan 2023 10:43:01 +0100
Marc Hartmayer <mhartmay@linux.ibm.com> wrote:

> Claudio Imbrenda <imbrenda@linux.ibm.com> writes:
> 
> > On Mon, 16 Jan 2023 18:57:55 +0100
> > Marc Hartmayer <mhartmay@linux.ibm.com> wrote:
> >  
> >> Use the C pre-processor for the linker script generation. For example,
> >> this enables us the use of constants in the "linker scripts" `*.lds.S`.  
> >
> > please explain that the original .lds scripts are being renamed to
> > .lds.S, and that the .lds are now generated.  
> 
> Okay.
> 
> >  
> >> 
> >> Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
> >> ---
> >>  .gitignore                                  | 1 +
> >>  s390x/Makefile                              | 6 ++++--
> >>  s390x/{flat.lds => flat.lds.S}              | 0
> >>  s390x/snippets/asm/{flat.lds => flat.lds.S} | 0
> >>  s390x/snippets/c/{flat.lds => flat.lds.S}   | 0
> >>  5 files changed, 5 insertions(+), 2 deletions(-)
> >>  rename s390x/{flat.lds => flat.lds.S} (100%)
> >>  rename s390x/snippets/asm/{flat.lds => flat.lds.S} (100%)
> >>  rename s390x/snippets/c/{flat.lds => flat.lds.S} (100%)
> >> 
> >> diff --git a/.gitignore b/.gitignore
> >> index 601822d67325..29f352c5ceb6 100644
> >> --- a/.gitignore
> >> +++ b/.gitignore
> >> @@ -31,3 +31,4 @@ cscope.*
> >>  /s390x/comm.key
> >>  /s390x/snippets/*/*.hdr
> >>  /s390x/snippets/*/*.*obj
> >> +/s390x/**/*.lds  
> >
> > why ** ?  
> 
> Because all of our linker scripts are generated now:
> 
> s390x/snippets/(c|asm)/*.lds
> 
> and
> 
> s390x/*.lds
> 
> […snip]
> 

I still don't understand why ** instead of just * ?
Marc Hartmayer Jan. 17, 2023, 11:19 a.m. UTC | #4
Claudio Imbrenda <imbrenda@linux.ibm.com> writes:

> On Tue, 17 Jan 2023 10:43:01 +0100
> Marc Hartmayer <mhartmay@linux.ibm.com> wrote:
>
>> Claudio Imbrenda <imbrenda@linux.ibm.com> writes:
>> 
>> > On Mon, 16 Jan 2023 18:57:55 +0100
>> > Marc Hartmayer <mhartmay@linux.ibm.com> wrote:
>> >  
>> >> Use the C pre-processor for the linker script generation. For example,
>> >> this enables us the use of constants in the "linker scripts" `*.lds.S`.  
>> >
>> > please explain that the original .lds scripts are being renamed to
>> > .lds.S, and that the .lds are now generated.  
>> 
>> Okay.
>> 
>> >  
>> >> 
>> >> Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
>> >> ---
>> >>  .gitignore                                  | 1 +
>> >>  s390x/Makefile                              | 6 ++++--
>> >>  s390x/{flat.lds => flat.lds.S}              | 0
>> >>  s390x/snippets/asm/{flat.lds => flat.lds.S} | 0
>> >>  s390x/snippets/c/{flat.lds => flat.lds.S}   | 0
>> >>  5 files changed, 5 insertions(+), 2 deletions(-)
>> >>  rename s390x/{flat.lds => flat.lds.S} (100%)
>> >>  rename s390x/snippets/asm/{flat.lds => flat.lds.S} (100%)
>> >>  rename s390x/snippets/c/{flat.lds => flat.lds.S} (100%)
>> >> 
>> >> diff --git a/.gitignore b/.gitignore
>> >> index 601822d67325..29f352c5ceb6 100644
>> >> --- a/.gitignore
>> >> +++ b/.gitignore
>> >> @@ -31,3 +31,4 @@ cscope.*
>> >>  /s390x/comm.key
>> >>  /s390x/snippets/*/*.hdr
>> >>  /s390x/snippets/*/*.*obj
>> >> +/s390x/**/*.lds  
>> >
>> > why ** ?  
>> 
>> Because all of our linker scripts are generated now:
>> 
>> s390x/snippets/(c|asm)/*.lds
>> 
>> and
>> 
>> s390x/*.lds
>> 
>> […snip]
>> 
>
> I still don't understand why ** instead of just * ?

“A slash followed by two consecutive asterisks then a slash matches zero
or more directories. For example, "a/**/b" matches "a/b", "a/x/b",
"a/x/y/b" and so on.” [1]

[1] https://git-scm.com/docs/gitignore
Claudio Imbrenda Jan. 17, 2023, 11:21 a.m. UTC | #5
On Tue, 17 Jan 2023 10:43:01 +0100
Marc Hartmayer <mhartmay@linux.ibm.com> wrote:

> Claudio Imbrenda <imbrenda@linux.ibm.com> writes:
> 
> > On Mon, 16 Jan 2023 18:57:55 +0100
> > Marc Hartmayer <mhartmay@linux.ibm.com> wrote:
> >  
> >> Use the C pre-processor for the linker script generation. For example,
> >> this enables us the use of constants in the "linker scripts" `*.lds.S`.  
> >
> > please explain that the original .lds scripts are being renamed to
> > .lds.S, and that the .lds are now generated.  
> 
> Okay.
> 
> >  
> >> 
> >> Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
> >> ---
> >>  .gitignore                                  | 1 +
> >>  s390x/Makefile                              | 6 ++++--
> >>  s390x/{flat.lds => flat.lds.S}              | 0
> >>  s390x/snippets/asm/{flat.lds => flat.lds.S} | 0
> >>  s390x/snippets/c/{flat.lds => flat.lds.S}   | 0
> >>  5 files changed, 5 insertions(+), 2 deletions(-)
> >>  rename s390x/{flat.lds => flat.lds.S} (100%)
> >>  rename s390x/snippets/asm/{flat.lds => flat.lds.S} (100%)
> >>  rename s390x/snippets/c/{flat.lds => flat.lds.S} (100%)
> >> 
> >> diff --git a/.gitignore b/.gitignore
> >> index 601822d67325..29f352c5ceb6 100644
> >> --- a/.gitignore
> >> +++ b/.gitignore
> >> @@ -31,3 +31,4 @@ cscope.*
> >>  /s390x/comm.key
> >>  /s390x/snippets/*/*.hdr
> >>  /s390x/snippets/*/*.*obj
> >> +/s390x/**/*.lds  
> >
> > why ** ?  
> 
> Because all of our linker scripts are generated now:
> 
> s390x/snippets/(c|asm)/*.lds
> 
> and
> 
> s390x/*.lds
> 
> […snip]
> 

ok so I thought ** was a typo and you meant either * or */*, but it
turns out ** is actual a special glob syntax in gitignore

ignore my comments regarding ** :)
diff mbox series

Patch

diff --git a/.gitignore b/.gitignore
index 601822d67325..29f352c5ceb6 100644
--- a/.gitignore
+++ b/.gitignore
@@ -31,3 +31,4 @@  cscope.*
 /s390x/comm.key
 /s390x/snippets/*/*.hdr
 /s390x/snippets/*/*.*obj
+/s390x/**/*.lds
diff --git a/s390x/Makefile b/s390x/Makefile
index 31f6db11213d..45493160cdf8 100644
--- a/s390x/Makefile
+++ b/s390x/Makefile
@@ -76,7 +76,7 @@  CFLAGS += -fno-delete-null-pointer-checks
 LDFLAGS += -nostdlib -Wl,--build-id=none
 
 # We want to keep intermediate files
-.PRECIOUS: %.o
+.PRECIOUS: %.o %.lds
 
 asm-offsets = lib/$(ARCH)/asm-offsets.h
 include $(SRCDIR)/scripts/asm-offsets.mak
@@ -159,6 +159,8 @@  $(SNIPPET_DIR)/c/%.gbin: $(SNIPPET_DIR)/c/%.o $(snippet_lib) $(FLATLIBS) $(SRCDI
 %.hdr.obj: %.hdr
 	$(OBJCOPY) -I binary -O elf64-s390 -B "s390:64-bit" $< $@
 
+%.lds: %.lds.S
+	$(CPP) $(autodepend-flags) $(CPPFLAGS) -P -C -o $@ $<
 
 .SECONDEXPANSION:
 %.elf: $(FLATLIBS) $(asmlib) $(SRCDIR)/s390x/flat.lds $$(snippets-obj) $$(snippet-hdr-obj) %.o
@@ -211,7 +213,7 @@  $(snippet_asmlib): $$(patsubst %.o,%.S,$$@) $(asm-offsets)
 
 
 arch_clean: asm_offsets_clean
-	$(RM) $(TEST_DIR)/*.{o,elf,bin} $(SNIPPET_DIR)/*/*.{o,elf,*bin,*obj,hdr} $(SNIPPET_DIR)/asm/.*.d $(TEST_DIR)/.*.d lib/s390x/.*.d $(comm-key)
+	$(RM) $(TEST_DIR)/*.{o,elf,bin,lds} $(SNIPPET_DIR)/*/*.{o,elf,*bin,*obj,hdr,lds} $(SNIPPET_DIR)/asm/.*.d $(TEST_DIR)/.*.d lib/s390x/.*.d $(comm-key)
 
 generated-files = $(asm-offsets)
 $(tests:.elf=.o) $(asmlib) $(cflatobjs): $(generated-files)
diff --git a/s390x/flat.lds b/s390x/flat.lds.S
similarity index 100%
rename from s390x/flat.lds
rename to s390x/flat.lds.S
diff --git a/s390x/snippets/asm/flat.lds b/s390x/snippets/asm/flat.lds.S
similarity index 100%
rename from s390x/snippets/asm/flat.lds
rename to s390x/snippets/asm/flat.lds.S
diff --git a/s390x/snippets/c/flat.lds b/s390x/snippets/c/flat.lds.S
similarity index 100%
rename from s390x/snippets/c/flat.lds
rename to s390x/snippets/c/flat.lds.S