Enable build for other architecture without patching

Open
#777 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
cmake, cpp

Research direction

Start by reading cmake/init-compilation-flags.cmake and compiler/compiler-settings.cpp to trace where the sandybridge flags are introduced and how compiler settings are assembled. Verify the build configuration and resulting compiler command for an x86_64 target; done means the generated binary uses configured or user-supplied architecture flags without requiring source patches.

Written by the indexing model from the issue text.

Description

Problem: kphp2cpp configured only with -march sandybridge, but application binary can be executed in KVM.

Solution: kphp2cpp must compile resulting binary with same flags as compiled or configured by cmake flags, or must don't set flags for using user-defined compiler flags.

I found two places:
cmake/init-compilation-flags.cmake

if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
-    add_compile_options(-march=sandybridge -fno-common)
+    add_compile_options(-march=core2 -mpclmul -msse2 -fno-common)
     add_link_options(-fno-common)

At here option must be configured by command line arguments.

compiler/compiler-settings.cpp

--- a/compiler/compiler-settings.cpp
+++ b/compiler/compiler-settings.cpp
@@ -280,7 +280,7 @@ void CompilerSettings::init() {
   ss << " -Wall -fwrapv -Wno-parentheses -Wno-trigraphs";
   ss << " -fno-strict-aliasing -fno-omit-frame-pointer";
 #ifdef __x86_64__
-  ss << " -march=sandybridge";
 #endif
   if (!no_pch.get()) {

at here option must be removed or reused from cmake options.

Dominant language
C++
Stars
1.5k
Forks
116
Avg merge
5d 17h
Merged PRs (30d)
11

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from VKCOM/kphp

All issues in VKCOM/kphp

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.