Patchwork [v3,1/2] package: Makefile.in: Add target compilation flags for NOMMU architecture.

login
register
mail settings
Submitter Sonic Zhang
Date March 22, 2013, 9:01 a.m.
Message ID <1363942902-6045-1-git-send-email-sonic.adi@gmail.com>
Download mbox | patch
Permalink /patch/229928/
State Changes Requested
Headers show

Comments

Sonic Zhang - March 22, 2013, 9:01 a.m.
From: Sonic Zhang <sonic.zhang@analog.com>

v2-changes:
- Use double-dollar to cite ($(2)_FLAT_STACKSIZE)

v1-changes:
- Add BR2_TARGET_ABI_FLAT option
- Add NOMMU compiling macro
- Add FLAT ABI specific link flags
- Add stack size to FLAT link flags if macro <PKG>_FLAT_STACKSIZE is defined.

Signed-off-by: Sonic Zhang <sonic.zhang@analog.com>
---
 arch/Config.in           |    3 +++
 package/Makefile.in      |    8 ++++++++
 package/pkg-autotools.mk |    5 +++++
 package/pkg-generic.mk   |    5 +++++
 4 files changed, 21 insertions(+), 0 deletions(-)
Thomas Petazzoni - March 22, 2013, 2:29 p.m.
Dear Sonic Zhang,

On Fri, 22 Mar 2013 17:01:41 +0800, Sonic Zhang wrote:
> From: Sonic Zhang <sonic.zhang@analog.com>

Thanks for getting back to us with Blackfin-related changes!

> +config BR2_TARGET_ABI_FLAT
> +	bool

I don't think FLAT is an ABI, it's a binary format.

For example, on ARM, you can have ELF or FLAT binaries, that follow
either the OABI or EABI. True, OABI is deprecated, but it still clearly
points the fact that FLAT is *not* an ABI, but a binary format.

Therefore, I think we should introduce config options like:

config BR2_BINFMT_ELF
	bool

config BR2_BINFMT_FDPIC
	bool

config BR2_BINFMT_FLAT
	bool

probably with a choice list or something.

>  if BR2_arm || BR2_armeb
>  source "arch/Config.in.arm"
>  endif
> diff --git a/package/Makefile.in b/package/Makefile.in
> index a8bf36b..acfd9c8 100644
> --- a/package/Makefile.in
> +++ b/package/Makefile.in
> @@ -103,6 +103,14 @@ TARGET_CFLAGS = $(TARGET_CPPFLAGS) $(TARGET_ABI) $(TARGET_OPTIMIZATION) $(TARGET
>  TARGET_CXXFLAGS = $(TARGET_CFLAGS)
>  TARGET_LDFLAGS = $(call qstrip,$(BR2_TARGET_LDFLAGS))
>  
> +ifeq ($(BR2_TARGET_ABI_FLAT),y)
> +TARGET_LDFLAGS += -Wl,-elf2flt
> +endif

This will have to use some BR2_BINFMT_FLAT config option, as per the
discussion above.

> +ifneq ($(BR2_USE_MMU), y)
> +TARGET_CFLAGS += -D__NOMMU__
> +endif

I'm still not entirely happy with that. This define is completely
non-standard, I am not sure we want to have this at the global level.
autotools-based packages should be fixed to check if fork() is
available or not. For other packages, this special flag can be
introduced on a per-package basis. But it's true that maybe a good
number of packages will need that. Not sure here. What do others think?

> +
>  ifeq ($(BR2_TOOLCHAIN_BUILDROOT)$(BR2_TOOLCHAIN_CTNG),y)
>  TARGET_CROSS=$(HOST_DIR)/usr/bin/$(GNU_TARGET_NAME)-
>  else
> diff --git a/package/pkg-autotools.mk b/package/pkg-autotools.mk
> index 890506b..09bdc7b 100644
> --- a/package/pkg-autotools.mk
> +++ b/package/pkg-autotools.mk
> @@ -82,6 +82,11 @@ $(2)_CLEAN_OPT			?= clean
>  $(2)_UNINSTALL_STAGING_OPT	?= DESTDIR=$$(STAGING_DIR) uninstall
>  $(2)_UNINSTALL_TARGET_OPT	?= DESTDIR=$$(TARGET_DIR)  uninstall
>  
> +ifeq ($(BR2_TARGET_ABI_FLAT),y)
> + ifneq ($$($(2)_FLAT_STACKSIZE),)
> +  $(2)_CONF_ENV			+= LDFLAGS="$(TARGET_LDFLAGS) -Wl,-elf2flt=-s$$($(2)_FLAT_STACKSIZE)"
> + endif
> +endif

Ok. This needs an update in the documentation, detailing the new
<pkg>_FLAT_STACKSIZE option.

>  #
>  # Configure step. Only define it if not already defined by the package
> diff --git a/package/pkg-generic.mk b/package/pkg-generic.mk
> index 57b0fd0..5ce32f9 100644
> --- a/package/pkg-generic.mk
> +++ b/package/pkg-generic.mk
> @@ -303,6 +303,11 @@ endif
>  
>  $(2)_REDISTRIBUTE		?= YES
>  
> +ifeq ($(BR2_TARGET_ABI_FLAT),y)
> + ifneq ($$($(2)_FLAT_STACKSIZE),)
> +  $(2)_FLAT_LDFLAGS = -Wl,-elf2flt=-s$$($(2)_FLAT_STACKSIZE)
> + endif
> +endif

How is this one supposed to work? Who will use <pkg>_FLAT_LDFLAGS?

Best regards,

Thomas
Thomas De Schampheleire - March 22, 2013, 5:28 p.m.
Hi,

On Fri, Mar 22, 2013 at 3:29 PM, Thomas Petazzoni <
thomas.petazzoni@free-electrons.com> wrote:

> Dear Sonic Zhang,
>
> On Fri, 22 Mar 2013 17:01:41 +0800, Sonic Zhang wrote:
> > From: Sonic Zhang <sonic.zhang@analog.com>
>
> Thanks for getting back to us with Blackfin-related changes!
>
> > +config BR2_TARGET_ABI_FLAT
> > +     bool
>
> I don't think FLAT is an ABI, it's a binary format.
>
> For example, on ARM, you can have ELF or FLAT binaries, that follow
> either the OABI or EABI. True, OABI is deprecated, but it still clearly
> points the fact that FLAT is *not* an ABI, but a binary format.
>
> Therefore, I think we should introduce config options like:
>
> config BR2_BINFMT_ELF
>         bool
>
> config BR2_BINFMT_FDPIC
>         bool
>
> config BR2_BINFMT_FLAT
>         bool
>
> probably with a choice list or something.
>
> >  if BR2_arm || BR2_armeb
> >  source "arch/Config.in.arm"
> >  endif
> > diff --git a/package/Makefile.in b/package/Makefile.in
> > index a8bf36b..acfd9c8 100644
> > --- a/package/Makefile.in
> > +++ b/package/Makefile.in
> > @@ -103,6 +103,14 @@ TARGET_CFLAGS = $(TARGET_CPPFLAGS) $(TARGET_ABI)
> $(TARGET_OPTIMIZATION) $(TARGET
> >  TARGET_CXXFLAGS = $(TARGET_CFLAGS)
> >  TARGET_LDFLAGS = $(call qstrip,$(BR2_TARGET_LDFLAGS))
> >
> > +ifeq ($(BR2_TARGET_ABI_FLAT),y)
> > +TARGET_LDFLAGS += -Wl,-elf2flt
> > +endif
>
> This will have to use some BR2_BINFMT_FLAT config option, as per the
> discussion above.
>
> > +ifneq ($(BR2_USE_MMU), y)
> > +TARGET_CFLAGS += -D__NOMMU__
> > +endif
>
> I'm still not entirely happy with that. This define is completely
> non-standard, I am not sure we want to have this at the global level.
> autotools-based packages should be fixed to check if fork() is
> available or not. For other packages, this special flag can be
> introduced on a per-package basis. But it's true that maybe a good
> number of packages will need that. Not sure here. What do others think?
>

Isn't this conceptually at the same level as settings like LARGEFILE,
WCHAR, etc.
In the case of LARGEFILE, a variable DISABLE_LARGEFILE is provided
(expanding to --disable-largefile), that packages can use to set the
necessary config options in a common way. Package infrastructures like
autotools-package can also use this.

This reasoning would then indeed suggest against such a global option, and
instead only provide a way to set this flag on a per-package basis or in an
infrastructure.

Best regards,
Thomas
Arnout Vandecappelle - March 25, 2013, 7:11 a.m.
On 22/03/13 15:29, Thomas Petazzoni wrote:
> Dear Sonic Zhang,
>
> On Fri, 22 Mar 2013 17:01:41 +0800, Sonic Zhang wrote:
[snip]
>> +ifneq ($(BR2_USE_MMU), y)
>> +TARGET_CFLAGS += -D__NOMMU__
>> +endif
>
> I'm still not entirely happy with that. This define is completely
> non-standard, I am not sure we want to have this at the global level.
> autotools-based packages should be fixed to check if fork() is
> available or not. For other packages, this special flag can be
> introduced on a per-package basis. But it's true that maybe a good
> number of packages will need that. Not sure here. What do others think?

  Since this is a non-standard flag, it would go together with some patch 
that adds the possibility of NOMMU builds. I would say that it's a good 
idea to have an explicit extra -DNOMMU in those .mk files.

  As to the large number of packages using it: it should anyway only be 
used for make-based packages (autotools and cmake should have different 
ways to detect NOMMU). So the number of packages using it wouldn't be 
that large.

  And finally, that do this that we have already (irda-utils and portmap) 
call it NO_FORK.

  Regards,
  Arnout

[snip]
Sonic Zhang - March 25, 2013, 7:50 a.m.
Hi Thomas,

On Fri, Mar 22, 2013 at 10:29 PM, Thomas Petazzoni
<thomas.petazzoni@free-electrons.com> wrote:
> Dear Sonic Zhang,
>
> On Fri, 22 Mar 2013 17:01:41 +0800, Sonic Zhang wrote:
>> From: Sonic Zhang <sonic.zhang@analog.com>
>
> Thanks for getting back to us with Blackfin-related changes!
>
>> +config BR2_TARGET_ABI_FLAT
>> +     bool
>
> I don't think FLAT is an ABI, it's a binary format.
>
> For example, on ARM, you can have ELF or FLAT binaries, that follow
> either the OABI or EABI. True, OABI is deprecated, but it still clearly
> points the fact that FLAT is *not* an ABI, but a binary format.
>
> Therefore, I think we should introduce config options like:
>
> config BR2_BINFMT_ELF
>         bool
>
> config BR2_BINFMT_FDPIC
>         bool
>
> config BR2_BINFMT_FLAT
>         bool
>
> probably with a choice list or something.
>

OK.

>>  if BR2_arm || BR2_armeb
>>  source "arch/Config.in.arm"
>>  endif
>> diff --git a/package/Makefile.in b/package/Makefile.in
>> index a8bf36b..acfd9c8 100644
>> --- a/package/Makefile.in
>> +++ b/package/Makefile.in
>> @@ -103,6 +103,14 @@ TARGET_CFLAGS = $(TARGET_CPPFLAGS) $(TARGET_ABI) $(TARGET_OPTIMIZATION) $(TARGET
>>  TARGET_CXXFLAGS = $(TARGET_CFLAGS)
>>  TARGET_LDFLAGS = $(call qstrip,$(BR2_TARGET_LDFLAGS))
>>
>> +ifeq ($(BR2_TARGET_ABI_FLAT),y)
>> +TARGET_LDFLAGS += -Wl,-elf2flt
>> +endif
>
> This will have to use some BR2_BINFMT_FLAT config option, as per the
> discussion above.
>

OK.

>> +ifneq ($(BR2_USE_MMU), y)
>> +TARGET_CFLAGS += -D__NOMMU__
>> +endif
>
> I'm still not entirely happy with that. This define is completely
> non-standard, I am not sure we want to have this at the global level.
> autotools-based packages should be fixed to check if fork() is
> available or not. For other packages, this special flag can be
> introduced on a per-package basis. But it's true that maybe a good
> number of packages will need that. Not sure here. What do others think?
>

Macro __NOMMU__ is not used only for fork/vfork. There are some
difference between MMU and NOMMU application. For example:
- exit(n) should be replaced by _exit(n) in child process.
- Large buffer or array shouldn't be defined on stack.
- calloc() should be replaced by malloc().

All these changes to MMU application should be protected by macro __NOMMU__


>> +
>>  ifeq ($(BR2_TOOLCHAIN_BUILDROOT)$(BR2_TOOLCHAIN_CTNG),y)
>>  TARGET_CROSS=$(HOST_DIR)/usr/bin/$(GNU_TARGET_NAME)-
>>  else
>> diff --git a/package/pkg-autotools.mk b/package/pkg-autotools.mk
>> index 890506b..09bdc7b 100644
>> --- a/package/pkg-autotools.mk
>> +++ b/package/pkg-autotools.mk
>> @@ -82,6 +82,11 @@ $(2)_CLEAN_OPT                     ?= clean
>>  $(2)_UNINSTALL_STAGING_OPT   ?= DESTDIR=$$(STAGING_DIR) uninstall
>>  $(2)_UNINSTALL_TARGET_OPT    ?= DESTDIR=$$(TARGET_DIR)  uninstall
>>
>> +ifeq ($(BR2_TARGET_ABI_FLAT),y)
>> + ifneq ($$($(2)_FLAT_STACKSIZE),)
>> +  $(2)_CONF_ENV                      += LDFLAGS="$(TARGET_LDFLAGS) -Wl,-elf2flt=-s$$($(2)_FLAT_STACKSIZE)"
>> + endif
>> +endif
>
> Ok. This needs an update in the documentation, detailing the new
> <pkg>_FLAT_STACKSIZE option.
>
>>  #
>>  # Configure step. Only define it if not already defined by the package
>> diff --git a/package/pkg-generic.mk b/package/pkg-generic.mk
>> index 57b0fd0..5ce32f9 100644
>> --- a/package/pkg-generic.mk
>> +++ b/package/pkg-generic.mk
>> @@ -303,6 +303,11 @@ endif
>>
>>  $(2)_REDISTRIBUTE            ?= YES
>>
>> +ifeq ($(BR2_TARGET_ABI_FLAT),y)
>> + ifneq ($$($(2)_FLAT_STACKSIZE),)
>> +  $(2)_FLAT_LDFLAGS = -Wl,-elf2flt=-s$$($(2)_FLAT_STACKSIZE)
>> + endif
>> +endif
>
> How is this one supposed to work? Who will use <pkg>_FLAT_LDFLAGS?

If the generic package wants to be built into FLAT binary, it should
append this package specific link flag <pkg>_FLAT_LDFLAGS to the build
command line in its makefile. This flag can't be added to
TARGET_LDFLAGS, because it is package specific.

Regards,

Sonic
Sonic Zhang - March 25, 2013, 7:57 a.m.
On Mon, Mar 25, 2013 at 3:50 PM, Sonic Zhang <sonic.adi@gmail.com> wrote:
> Hi Thomas,
>
> On Fri, Mar 22, 2013 at 10:29 PM, Thomas Petazzoni
> <thomas.petazzoni@free-electrons.com> wrote:
>> Dear Sonic Zhang,
>>
>> On Fri, 22 Mar 2013 17:01:41 +0800, Sonic Zhang wrote:
>>> From: Sonic Zhang <sonic.zhang@analog.com>
>>
>> Thanks for getting back to us with Blackfin-related changes!
>>
>>> +config BR2_TARGET_ABI_FLAT
>>> +     bool
>>
>> I don't think FLAT is an ABI, it's a binary format.
>>
>> For example, on ARM, you can have ELF or FLAT binaries, that follow
>> either the OABI or EABI. True, OABI is deprecated, but it still clearly
>> points the fact that FLAT is *not* an ABI, but a binary format.
>>
>> Therefore, I think we should introduce config options like:
>>
>> config BR2_BINFMT_ELF
>>         bool
>>
>> config BR2_BINFMT_FDPIC
>>         bool
>>
>> config BR2_BINFMT_FLAT
>>         bool
>>
>> probably with a choice list or something.
>>
>
> OK.
>
>>>  if BR2_arm || BR2_armeb
>>>  source "arch/Config.in.arm"
>>>  endif
>>> diff --git a/package/Makefile.in b/package/Makefile.in
>>> index a8bf36b..acfd9c8 100644
>>> --- a/package/Makefile.in
>>> +++ b/package/Makefile.in
>>> @@ -103,6 +103,14 @@ TARGET_CFLAGS = $(TARGET_CPPFLAGS) $(TARGET_ABI) $(TARGET_OPTIMIZATION) $(TARGET
>>>  TARGET_CXXFLAGS = $(TARGET_CFLAGS)
>>>  TARGET_LDFLAGS = $(call qstrip,$(BR2_TARGET_LDFLAGS))
>>>
>>> +ifeq ($(BR2_TARGET_ABI_FLAT),y)
>>> +TARGET_LDFLAGS += -Wl,-elf2flt
>>> +endif
>>
>> This will have to use some BR2_BINFMT_FLAT config option, as per the
>> discussion above.
>>
>
> OK.
>
>>> +ifneq ($(BR2_USE_MMU), y)
>>> +TARGET_CFLAGS += -D__NOMMU__
>>> +endif
>>
>> I'm still not entirely happy with that. This define is completely
>> non-standard, I am not sure we want to have this at the global level.
>> autotools-based packages should be fixed to check if fork() is
>> available or not. For other packages, this special flag can be
>> introduced on a per-package basis. But it's true that maybe a good
>> number of packages will need that. Not sure here. What do others think?
>>
>
> Macro __NOMMU__ is not used only for fork/vfork. There are some
> difference between MMU and NOMMU application. For example:
> - exit(n) should be replaced by _exit(n) in child process.
> - Large buffer or array shouldn't be defined on stack.
> - calloc() should be replaced by malloc().

More difference:
- Multi-process application should be converted into multi-thread
application other than vfork if these processes are running
concurrently.
- Frequent memory allocation and free code should be converted to
allocate a big memory poll at the beginning of the application or
replaced by nedmalloc API.


Regards,

Sonic
Thomas Petazzoni - March 25, 2013, 7:58 a.m.
Dear Sonic Zhang,

Thanks for following up on this discussion!

On Mon, 25 Mar 2013 15:50:49 +0800, Sonic Zhang wrote:

> > For example, on ARM, you can have ELF or FLAT binaries, that follow
> > either the OABI or EABI. True, OABI is deprecated, but it still clearly
> > points the fact that FLAT is *not* an ABI, but a binary format.
> >
> > Therefore, I think we should introduce config options like:
> >
> > config BR2_BINFMT_ELF
> >         bool
> >
> > config BR2_BINFMT_FDPIC
> >         bool
> >
> > config BR2_BINFMT_FLAT
> >         bool
> >
> > probably with a choice list or something.
> >
> 
> OK.

It would be good if this BR2_BINFMT_<foo> thing was introduced as a
separate patch. It can be part of the same patch series, but it would
be could to see it introduced separately from the Blackfin additions.

> >> +ifneq ($(BR2_USE_MMU), y)
> >> +TARGET_CFLAGS += -D__NOMMU__
> >> +endif
> >
> > I'm still not entirely happy with that. This define is completely
> > non-standard, I am not sure we want to have this at the global level.
> > autotools-based packages should be fixed to check if fork() is
> > available or not. For other packages, this special flag can be
> > introduced on a per-package basis. But it's true that maybe a good
> > number of packages will need that. Not sure here. What do others think?
> >
> 
> Macro __NOMMU__ is not used only for fork/vfork. There are some
> difference between MMU and NOMMU application. For example:
> - exit(n) should be replaced by _exit(n) in child process.
> - Large buffer or array shouldn't be defined on stack.
> - calloc() should be replaced by malloc().
> 
> All these changes to MMU application should be protected by macro __NOMMU__

The issue I have is that this __NOMMU__ define is, as far as I know,
entirely non-standard. So whenever you will send a patch for a package
that introduces some #ifdef __NOMMU__ ... #endif clause, we'll have no
way of pushing it upstream.

Have you managed to pushed upstream noMMU related changes that are
guarded using __NOMMU__ ?

> >>  # Configure step. Only define it if not already defined by the package
> >> diff --git a/package/pkg-generic.mk b/package/pkg-generic.mk
> >> index 57b0fd0..5ce32f9 100644
> >> --- a/package/pkg-generic.mk
> >> +++ b/package/pkg-generic.mk
> >> @@ -303,6 +303,11 @@ endif
> >>
> >>  $(2)_REDISTRIBUTE            ?= YES
> >>
> >> +ifeq ($(BR2_TARGET_ABI_FLAT),y)
> >> + ifneq ($$($(2)_FLAT_STACKSIZE),)
> >> +  $(2)_FLAT_LDFLAGS = -Wl,-elf2flt=-s$$($(2)_FLAT_STACKSIZE)
> >> + endif
> >> +endif
> >
> > How is this one supposed to work? Who will use <pkg>_FLAT_LDFLAGS?
> 
> If the generic package wants to be built into FLAT binary, it should
> append this package specific link flag <pkg>_FLAT_LDFLAGS to the build
> command line in its makefile. This flag can't be added to
> TARGET_LDFLAGS, because it is package specific.

Hum, right, but then it means that we should modify *all* our packages
so that they add $(<pkg>_FLAT_LDFLAGS) to their LDFLAGS ? Having to
change the recipe of all packages doesn't seem easy to do. Maybe with
enough $ signs we can delay the expansion of TARGET_LDFLAGS so that we
can use a package specific variable in it. Makefile experts? Arnout? :-)

Best regards,

Thomas
Sonic Zhang - March 25, 2013, 8:51 a.m.
Hi Thomas,

On Mon, Mar 25, 2013 at 3:58 PM, Thomas Petazzoni
<thomas.petazzoni@free-electrons.com> wrote:
> Dear Sonic Zhang,
>
> Thanks for following up on this discussion!
>
> On Mon, 25 Mar 2013 15:50:49 +0800, Sonic Zhang wrote:
>
>> > For example, on ARM, you can have ELF or FLAT binaries, that follow
>> > either the OABI or EABI. True, OABI is deprecated, but it still clearly
>> > points the fact that FLAT is *not* an ABI, but a binary format.
>> >
>> > Therefore, I think we should introduce config options like:
>> >
>> > config BR2_BINFMT_ELF
>> >         bool
>> >
>> > config BR2_BINFMT_FDPIC
>> >         bool
>> >
>> > config BR2_BINFMT_FLAT
>> >         bool
>> >
>> > probably with a choice list or something.
>> >
>>
>> OK.
>
> It would be good if this BR2_BINFMT_<foo> thing was introduced as a
> separate patch. It can be part of the same patch series, but it would
> be could to see it introduced separately from the Blackfin additions.
>

No problem.

>> >> +ifneq ($(BR2_USE_MMU), y)
>> >> +TARGET_CFLAGS += -D__NOMMU__
>> >> +endif
>> >
>> > I'm still not entirely happy with that. This define is completely
>> > non-standard, I am not sure we want to have this at the global level.
>> > autotools-based packages should be fixed to check if fork() is
>> > available or not. For other packages, this special flag can be
>> > introduced on a per-package basis. But it's true that maybe a good
>> > number of packages will need that. Not sure here. What do others think?
>> >
>>
>> Macro __NOMMU__ is not used only for fork/vfork. There are some
>> difference between MMU and NOMMU application. For example:
>> - exit(n) should be replaced by _exit(n) in child process.
>> - Large buffer or array shouldn't be defined on stack.
>> - calloc() should be replaced by malloc().
>>
>> All these changes to MMU application should be protected by macro __NOMMU__
>
> The issue I have is that this __NOMMU__ define is, as far as I know,
> entirely non-standard. So whenever you will send a patch for a package
> that introduces some #ifdef __NOMMU__ ... #endif clause, we'll have no
> way of pushing it upstream.
>

Busybox uses macro ENABLE_NOMMU.
Linux kernel uses macro CONFIG_MMU.
Blackfin buildroot distribution uses __NOMMU__.

Which one do you prefer? We are fine to unify the NOMMU macro name.


> Have you managed to pushed upstream noMMU related changes that are
> guarded using __NOMMU__ ?
>

Because no major Linux distributions support NOMMU architecture except
for the blackfin one and the resource shortage in ADI Linux team, we
have never tried to push the NOMMU patch to upstream packages.


>> >>  # Configure step. Only define it if not already defined by the package
>> >> diff --git a/package/pkg-generic.mk b/package/pkg-generic.mk
>> >> index 57b0fd0..5ce32f9 100644
>> >> --- a/package/pkg-generic.mk
>> >> +++ b/package/pkg-generic.mk
>> >> @@ -303,6 +303,11 @@ endif
>> >>
>> >>  $(2)_REDISTRIBUTE            ?= YES
>> >>
>> >> +ifeq ($(BR2_TARGET_ABI_FLAT),y)
>> >> + ifneq ($$($(2)_FLAT_STACKSIZE),)
>> >> +  $(2)_FLAT_LDFLAGS = -Wl,-elf2flt=-s$$($(2)_FLAT_STACKSIZE)
>> >> + endif
>> >> +endif
>> >
>> > How is this one supposed to work? Who will use <pkg>_FLAT_LDFLAGS?
>>
>> If the generic package wants to be built into FLAT binary, it should
>> append this package specific link flag <pkg>_FLAT_LDFLAGS to the build
>> command line in its makefile. This flag can't be added to
>> TARGET_LDFLAGS, because it is package specific.
>
> Hum, right, but then it means that we should modify *all* our packages
> so that they add $(<pkg>_FLAT_LDFLAGS) to their LDFLAGS ? Having to
> change the recipe of all packages doesn't seem easy to do. Maybe with
> enough $ signs we can delay the expansion of TARGET_LDFLAGS so that we
> can use a package specific variable in it. Makefile experts? Arnout? :-)

The default FLAT stack size is 4K bytes without the package specific
link flag. If the package doesn't need more than 4K byte stack,
nothing needs to be changed to its makefile.

Regards,

Sonic

Patch

diff --git a/arch/Config.in b/arch/Config.in
index 472b10c..120c67e 100644
--- a/arch/Config.in
+++ b/arch/Config.in
@@ -174,6 +174,9 @@  config BR2_GCC_TARGET_ABI
 config BR2_GCC_TARGET_CPU
 	string
 
+config BR2_TARGET_ABI_FLAT
+	bool
+
 if BR2_arm || BR2_armeb
 source "arch/Config.in.arm"
 endif
diff --git a/package/Makefile.in b/package/Makefile.in
index a8bf36b..acfd9c8 100644
--- a/package/Makefile.in
+++ b/package/Makefile.in
@@ -103,6 +103,14 @@  TARGET_CFLAGS = $(TARGET_CPPFLAGS) $(TARGET_ABI) $(TARGET_OPTIMIZATION) $(TARGET
 TARGET_CXXFLAGS = $(TARGET_CFLAGS)
 TARGET_LDFLAGS = $(call qstrip,$(BR2_TARGET_LDFLAGS))
 
+ifeq ($(BR2_TARGET_ABI_FLAT),y)
+TARGET_LDFLAGS += -Wl,-elf2flt
+endif
+
+ifneq ($(BR2_USE_MMU), y)
+TARGET_CFLAGS += -D__NOMMU__
+endif
+
 ifeq ($(BR2_TOOLCHAIN_BUILDROOT)$(BR2_TOOLCHAIN_CTNG),y)
 TARGET_CROSS=$(HOST_DIR)/usr/bin/$(GNU_TARGET_NAME)-
 else
diff --git a/package/pkg-autotools.mk b/package/pkg-autotools.mk
index 890506b..09bdc7b 100644
--- a/package/pkg-autotools.mk
+++ b/package/pkg-autotools.mk
@@ -82,6 +82,11 @@  $(2)_CLEAN_OPT			?= clean
 $(2)_UNINSTALL_STAGING_OPT	?= DESTDIR=$$(STAGING_DIR) uninstall
 $(2)_UNINSTALL_TARGET_OPT	?= DESTDIR=$$(TARGET_DIR)  uninstall
 
+ifeq ($(BR2_TARGET_ABI_FLAT),y)
+ ifneq ($$($(2)_FLAT_STACKSIZE),)
+  $(2)_CONF_ENV			+= LDFLAGS="$(TARGET_LDFLAGS) -Wl,-elf2flt=-s$$($(2)_FLAT_STACKSIZE)"
+ endif
+endif
 
 #
 # Configure step. Only define it if not already defined by the package
diff --git a/package/pkg-generic.mk b/package/pkg-generic.mk
index 57b0fd0..5ce32f9 100644
--- a/package/pkg-generic.mk
+++ b/package/pkg-generic.mk
@@ -303,6 +303,11 @@  endif
 
 $(2)_REDISTRIBUTE		?= YES
 
+ifeq ($(BR2_TARGET_ABI_FLAT),y)
+ ifneq ($$($(2)_FLAT_STACKSIZE),)
+  $(2)_FLAT_LDFLAGS = -Wl,-elf2flt=-s$$($(2)_FLAT_STACKSIZE)
+ endif
+endif
 
 $(2)_DEPENDENCIES ?= $(filter-out $(1),$(patsubst host-host-%,host-%,$(addprefix host-,$($(3)_DEPENDENCIES))))