diff mbox series

[kvm-unit-tests,v2,5/8] s390x: use C pre-processor for linker script generation

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

Commit Message

Marc Hartmayer Jan. 19, 2023, 11:40 a.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

Marc Hartmayer Jan. 19, 2023, 11:52 a.m. UTC | #1
Marc Hartmayer <mhartmay@linux.ibm.com> writes:

> 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`.
>

Sorry, I forgot to change the commit message (Claudio’s comment):

“s390x: use preprocessor for linker script generation

The old `.lds` linker scripts are renamed to `.lds.S` and the actual
.lds` scripts are generated by the assembler preprocessor. This change
allows us to use constants defined by macros in the `.lds.S` files.”
Nina Schoetterl-Glausch Jan. 31, 2023, 5:56 p.m. UTC | #2
On Thu, 2023-01-19 at 12:40 +0100, Marc Hartmayer 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`.
> 
> 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
> diff --git a/s390x/Makefile b/s390x/Makefile
> index 8719f0c837cf..44ccca8102d6 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) $(SNIPP
>  %.hdr.obj: %.hdr
>  	$(OBJCOPY) -I binary -O elf64-s390 -B "s390:64-bit" $< $@
>  
> +%.lds: %.lds.S
> +	$(CPP) $(autodepend-flags) $(CPPFLAGS) -P -C -o $@ $<

Where is CPP defined?
Do you need the $(autodepend-flags)? It generates a rule with target flat.lds.o.
I don't think that would be used anywhere.
In the next patch you add $(asm-offsets) as a prerequisite, if the generated rule would
be effective, you wouldn't need that, would you?
>  
>  .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 Feb. 1, 2023, 10 a.m. UTC | #3
Nina Schoetterl-Glausch <nsg@linux.ibm.com> writes:

> On Thu, 2023-01-19 at 12:40 +0100, Marc Hartmayer 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`.
>> 
>> 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
>> diff --git a/s390x/Makefile b/s390x/Makefile
>> index 8719f0c837cf..44ccca8102d6 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) $(SNIPP
>>  %.hdr.obj: %.hdr
>>  	$(OBJCOPY) -I binary -O elf64-s390 -B "s390:64-bit" $< $@
>>  
>> +%.lds: %.lds.S
>> +	$(CPP) $(autodepend-flags) $(CPPFLAGS) -P -C -o $@ $<
>
> Where is CPP defined?
> Do you need the $(autodepend-flags)? It generates a rule with target flat.lds.o.
                                                                       ^^^^^^^^^^

Where does it generate a new Makefile rule? It generates the dependency
file used for the dependency tracking with the name: .flat.lds.S.d (or
similar)

> I don't think that would be used anywhere.

It’s used for the dependency tracking. See line

$KUT/Makefile:122

-include */.*.d */*/.*.d

> In the next patch you add $(asm-offsets) as a prerequisite, if the generated rule would
> be effective, you wouldn't need that, would you?

I thought, $(asm-offsets) is used to make sure that the file
<asm/asm-offsets.h> is generated.

[…snip]
Nina Schoetterl-Glausch Feb. 1, 2023, 12:19 p.m. UTC | #4
On Wed, 2023-02-01 at 11:00 +0100, Marc Hartmayer wrote:
> Nina Schoetterl-Glausch <nsg@linux.ibm.com> writes:
> 
> > On Thu, 2023-01-19 at 12:40 +0100, Marc Hartmayer 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`.
> > > 
> > > 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
> > > diff --git a/s390x/Makefile b/s390x/Makefile
> > > index 8719f0c837cf..44ccca8102d6 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) $(SNIPP
> > >  %.hdr.obj: %.hdr
> > >  	$(OBJCOPY) -I binary -O elf64-s390 -B "s390:64-bit" $< $@
> > >  
> > > +%.lds: %.lds.S
> > > +	$(CPP) $(autodepend-flags) $(CPPFLAGS) -P -C -o $@ $<
> > 
> > Where is CPP defined?
> > Do you need the $(autodepend-flags)? It generates a rule with target flat.lds.o.
>                                                                        ^^^^^^^^^^
> 
> Where does it generate a new Makefile rule? It generates the dependency
> file used for the dependency tracking with the name: .flat.lds.S.d (or
> similar)

Yes and that file contains the rule.
cat s390x/.flat.d
flat.lds.o: /foo/bar/s390x/flat.lds.S \
 /foo/bar/lib/asm/asm-offsets.h \
 /foo/bar/lib/generated/asm-offsets.h

> 
> > I don't think that would be used anywhere.
> 
> It’s used for the dependency tracking. See line
> 
> $KUT/Makefile:122
> 
> -include */.*.d */*/.*.d

Indeed, but the target flat.lds.o isn't used anywhere, is it?
So if flat.lds.S included some other header and that changed,
flat.lds wouldn't be rebuild.
So you would either need to generate a rule with flat.lds as target
or make it depend on flat.lds.o somehow.

> 
> > In the next patch you add $(asm-offsets) as a prerequisite, if the generated rule would
> > be effective, you wouldn't need that, would you?
> 
> I thought, $(asm-offsets) is used to make sure that the file
> <asm/asm-offsets.h> is generated.

I was asking if this is necessary, since s390x/.flat.d contains the asm-offset headers
as prerequisites. So if the dependency file is included, the headers will be build,
but I guess that this is circular, in order to generate the dependencies,
the asm-offset headers must already have been built.
> 
> […snip]
>
Marc Hartmayer Feb. 1, 2023, 1:54 p.m. UTC | #5
Nina Schoetterl-Glausch <nsg@linux.ibm.com> writes:

> On Wed, 2023-02-01 at 11:00 +0100, Marc Hartmayer wrote:
>> Nina Schoetterl-Glausch <nsg@linux.ibm.com> writes:
>> 
>> > On Thu, 2023-01-19 at 12:40 +0100, Marc Hartmayer 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`.
>> > > 
>> > > 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
>> > > diff --git a/s390x/Makefile b/s390x/Makefile
>> > > index 8719f0c837cf..44ccca8102d6 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) $(SNIPP
>> > >  %.hdr.obj: %.hdr
>> > >  	$(OBJCOPY) -I binary -O elf64-s390 -B "s390:64-bit" $< $@
>> > >  
>> > > +%.lds: %.lds.S
>> > > +	$(CPP) $(autodepend-flags) $(CPPFLAGS) -P -C -o $@ $<
>> > 
>> > Where is CPP defined?
>> > Do you need the $(autodepend-flags)? It generates a rule with target flat.lds.o.
>>                                                                        ^^^^^^^^^^
>> 
>> Where does it generate a new Makefile rule? It generates the dependency
>> file used for the dependency tracking with the name: .flat.lds.S.d (or
>> similar)
>
> Yes and that file contains the rule.
> cat s390x/.flat.d
> flat.lds.o: /foo/bar/s390x/flat.lds.S \
>  /foo/bar/lib/asm/asm-offsets.h \
>  /foo/bar/lib/generated/asm-offsets.h

Yep, right… thanks for pointing it out! So I could either don’t use
$(autodepend-flags) or adapt it:

I could change autodepend-flags to:

--- i/Makefile
+++ w/Makefile
@@ -94,7 +94,7 @@ CFLAGS += $(wmissing_parameter_type)
 CFLAGS += $(wold_style_declaration)
 CFLAGS += -Woverride-init -Wmissing-prototypes -Wstrict-prototypes
 
-autodepend-flags = -MMD -MF $(dir $*).$(notdir $*).d
+autodepend-flags = -MMD -MF $(dir $*).$(notdir $*).d -MT $@

Shouldn’t break anything (we have to double check of course) and it
results in a Makefile rule like this for the linker scripts:

s390x/snippets/c/flat.lds: s390x/snippets/c/flat.lds.S \
 /foo/kvm-unit-tests/lib/asm/asm-offsets.h \
 /foo/kvm-unit-tests/lib/generated/asm-offsets.h


>
>> 
>> > I don't think that would be used anywhere.
>> 
>> It’s used for the dependency tracking. See line
>> 
>> $KUT/Makefile:122
>> 
>> -include */.*.d */*/.*.d
>
> Indeed, but the target flat.lds.o isn't used anywhere, is it?

No, it’s not and it doesn’t make any sense.

> So if flat.lds.S included some other header and that changed,
> flat.lds wouldn't be rebuild.
> So you would either need to generate a rule with flat.lds as target
> or make it depend on flat.lds.o somehow.
>
>> 
>> > In the next patch you add $(asm-offsets) as a prerequisite, if the generated rule would
>> > be effective, you wouldn't need that, would you?
>> 
>> I thought, $(asm-offsets) is used to make sure that the file
>> <asm/asm-offsets.h> is generated.
>
> I was asking if this is necessary, since s390x/.flat.d contains the asm-offset headers
> as prerequisites. So if the dependency file is included, the headers will be build,
> but I guess that this is circular, in order to generate the dependencies,
> the asm-offset headers must already have been built.

Hmm - I’ll check.

Thanks for the feedback!

>> 
>> […snip]
>> 
>
Marc Hartmayer Feb. 1, 2023, 2:18 p.m. UTC | #6
Nina Schoetterl-Glausch <nsg@linux.ibm.com> writes:

> On Wed, 2023-02-01 at 11:00 +0100, Marc Hartmayer wrote:
>> Nina Schoetterl-Glausch <nsg@linux.ibm.com> writes:
>> 
>> > On Thu, 2023-01-19 at 12:40 +0100, Marc Hartmayer 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`.
>> > > 
>> > > 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
>> > > diff --git a/s390x/Makefile b/s390x/Makefile
>> > > index 8719f0c837cf..44ccca8102d6 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) $(SNIPP
>> > >  %.hdr.obj: %.hdr
>> > >  	$(OBJCOPY) -I binary -O elf64-s390 -B "s390:64-bit" $< $@
>> > >  
>> > > +%.lds: %.lds.S
>> > > +	$(CPP) $(autodepend-flags) $(CPPFLAGS) -P -C -o $@ $<
>> > 
>> > Where is CPP defined?
>> > Do you need the $(autodepend-flags)? It generates a rule with target flat.lds.o.
>>                                                                        ^^^^^^^^^^
>> 
>> Where does it generate a new Makefile rule? It generates the dependency
>> file used for the dependency tracking with the name: .flat.lds.S.d (or
>> similar)
>
> Yes and that file contains the rule.
> cat s390x/.flat.d
> flat.lds.o: /foo/bar/s390x/flat.lds.S \
>  /foo/bar/lib/asm/asm-offsets.h \
>  /foo/bar/lib/generated/asm-offsets.h
>
>> 
>> > I don't think that would be used anywhere.
>> 
>> It’s used for the dependency tracking. See line
>> 
>> $KUT/Makefile:122
>> 
>> -include */.*.d */*/.*.d
>
> Indeed, but the target flat.lds.o isn't used anywhere, is it?
> So if flat.lds.S included some other header and that changed,
> flat.lds wouldn't be rebuild.
> So you would either need to generate a rule with flat.lds as target
> or make it depend on flat.lds.o somehow.
>
>> 
>> > In the next patch you add $(asm-offsets) as a prerequisite, if the generated rule would
>> > be effective, you wouldn't need that, would you?
>> 
>> I thought, $(asm-offsets) is used to make sure that the file
>> <asm/asm-offsets.h> is generated.
>
> I was asking if this is necessary, since s390x/.flat.d contains the asm-offset headers
> as prerequisites. So if the dependency file is included, the headers will be build,
> but I guess that this is circular, in order to generate the dependencies,
> the asm-offset headers must already have been built.

Hmm, no, this won’t work unless the dependency file was already created
(chicken-egg problem). That’s probably the reason for this Makefile
rule:

generated-files = $(asm-offsets)
$(tests:.elf=.o) $(asmlib) $(cflatobjs): $(generated-files)

>> 
>> […snip]
>> 
>
Marc Hartmayer Feb. 1, 2023, 2:47 p.m. UTC | #7
Nina Schoetterl-Glausch <nsg@linux.ibm.com> writes:

> On Thu, 2023-01-19 at 12:40 +0100, Marc Hartmayer 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`.
>> 
>> 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
>> diff --git a/s390x/Makefile b/s390x/Makefile
>> index 8719f0c837cf..44ccca8102d6 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) $(SNIPP
>>  %.hdr.obj: %.hdr
>>  	$(OBJCOPY) -I binary -O elf64-s390 -B "s390:64-bit" $< $@
>>  
>> +%.lds: %.lds.S
>> +	$(CPP) $(autodepend-flags) $(CPPFLAGS) -P -C -o $@ $<
>
> Where is CPP defined?

Sry, I forgot to answer this question. For GNU Make, it’s defined
implicitly:

https://www.gnu.org/software/make/manual/html_node/Implicit-Variables.html

[…snip]
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 8719f0c837cf..44ccca8102d6 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) $(SNIPP
 %.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