Re: general question about compiling for weaker CPU

"Pocket" ([email protected] via lfs-support Mailing List) <[email protected]> Fri, 26 Sep 2025 16:48:00 -0400
Newsgroups gmane.linux.lfs.support
Message-ID <[email protected]>

On 9/26/25 10:09 AM, Thomas Seeling ([email protected] via 
lfs-support Mailing List) wrote:
> Hallo,
> 
> my recent problem and my not-so-elegant solution - using a KVM with CPU 
> set to "core2duo" - made me think about generating a distro for general 
> use, like Fedora, Redhat, Debian, Ubuntu and all the other "vendors" do.
> 
> Obviously they cannot let the compiler optimize for the CPU on the build 
> machine, they have to restrict *all* packages to the lowest common 
> denominator they intend to support, e.g. the weakest 64-bit CPU there 
> is, and communicate those supported CPU levels. Never thought about that 
> before :-)
> 
> I understand the "LFS_TGT" variable is intended for this purpose.
> Do I also need to define the gcc setting "-march=<target>" in CFLAGS, 
> e.g. target="x86-64" or target="core2" (from the gcc man page at 
> https://gcc.gnu.org/onlinedocs/gcc/x86-Options.html)?
> What would the correct setting be to e.g. build for the "core2duo", 
> which was more or less the first generation of 64-bit CPUs from intel?
> 
> Thanks +
> Stay healthy,
> Thomas
> 
> 

Processor information
gcc -mcpu=native -march=native -Q --help=target - for all the processors
that you are interested in, use the lowerest dem.

gcc -march=native -Q -v test.c -o test
test.c can be the one in the book

######################################################################### 
# ARCHITECTURE, COMPILE FLAGS 
######################################################################### 
# CARCH="x86_64"
CHOST="x86_64-pc-linux-gnu"
#-- Compiler and Linker Flags
#CPPFLAGS=""
CFLAGS="-march=x86-64 -mtune=generic -O2 -pipe -fno-plt -fexceptions \ 
       -Wp,-D_FORTIFY_SOURCE=3 -Wformat -Werror=format-security \
-fstack-clash-protection -fcf-protection \
-fno-omit-frame-pointer -mno-omit-leaf-frame-pointer"

CXXFLAGS="$CFLAGS -Wp,-D_GLIBCXX_ASSERTIONS"
LDFLAGS="-Wl,-O1 -Wl,--sort-common -Wl,--as-needed -Wl,-z,relro \
-Wl,-,now -Wl,-z,pack-relative-relocs"

LTOFLAGS="-flto=auto" #-- Make Flags: change this for DistCC/SMP systems

#MAKEFLAGS="-j2"

#-- Debugging flags DEBUG_CFLAGS="-g" DEBUG_CXXFLAGS="$DEBUG_CFLAGS"

Use CFLAGS, CXXFLAGS and LDFLAGS on all packages including chapter 5 
tools, ie the whole book

If you build using the flags for an older processor, but you are 
building on a newer one then it should "just work"

I build for raspberry pi 1 to 5, but mainly use rpi 4 but build on an rpi 5

-- 
Hindi madali ang maging ako

-- 
http://lists.linuxfromscratch.org/sympa/info/lfs-support
Unsubscribe: See the above information page